• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

/data/development/ViennaCL/dev/viennacl/linalg/norm_inf.hpp

Go to the documentation of this file.
00001 #ifndef VIENNACL_LINALG_NORM_INF_HPP_
00002 #define VIENNACL_LINALG_NORM_INF_HPP_
00003 
00004 /* =========================================================================
00005    Copyright (c) 2010-2011, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008 
00009                             -----------------
00010                   ViennaCL - The Vienna Computing Library
00011                             -----------------
00012 
00013    Project Head:    Karl Rupp                   rupp@iue.tuwien.ac.at
00014                
00015    (A list of authors and contributors can be found in the PDF manual)
00016 
00017    License:         MIT (X11), see file LICENSE in the base directory
00018 ============================================================================= */
00019 
00024 #include <math.h>    //for sqrt()
00025 #include "viennacl/forwards.h"
00026 #include "viennacl/tools/tools.hpp"
00027 #include "viennacl/meta/enable_if.hpp"
00028 #include "viennacl/meta/tag_of.hpp"
00029 
00030 namespace viennacl
00031 {
00032   //
00033   // generic norm_inf function
00034   //   uses tag dispatch to identify which algorithm
00035   //   should be called 
00036   //
00037   namespace linalg 
00038   {
00039     
00040     #ifdef VIENNACL_HAVE_UBLAS
00041     // ----------------------------------------------------
00042     // UBLAS
00043     //
00044     template< typename VectorT >
00045     typename VectorT::value_type
00046     norm_inf(VectorT const& v1, 
00047          typename viennacl::enable_if< viennacl::is_ublas< typename viennacl::traits::tag_of< VectorT >::type >::value
00048                                             >::type* dummy = 0)
00049     {
00050       // std::cout << "ublas .. " << std::endl;
00051       return boost::numeric::ublas::norm_inf(v1);
00052     }
00053     #endif
00054     
00055     
00056     // ----------------------------------------------------
00057     // STL
00058     //
00059     template< typename VectorT>
00060     typename VectorT::value_type
00061     norm_inf(VectorT const& v1,
00062          typename viennacl::enable_if< viennacl::is_stl< typename viennacl::traits::tag_of< VectorT >::type >::value
00063                                             >::type* dummy = 0)
00064     {
00065       //std::cout << "stl .. " << std::endl;
00066       typename VectorT::value_type result = 0;
00067       for (typename VectorT::size_type i=0; i<v1.size(); ++i)
00068       {
00069         if (fabs(v1[i]) > result)
00070           result = fabs(v1[i]);
00071       }
00072       
00073       return result;
00074     }
00075     
00076     // ----------------------------------------------------
00077     // VIENNACL
00078     //
00079     template< typename ScalarType, unsigned int alignment >
00080     viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>, 
00081                                  const viennacl::vector<ScalarType, alignment>,
00082                                  viennacl::op_norm_inf >
00083     norm_inf(viennacl::vector<ScalarType, alignment> const & v1, 
00084          typename viennacl::enable_if< viennacl::is_viennacl< typename viennacl::traits::tag_of< viennacl::vector<ScalarType, alignment> >::type >::value
00085                                             >::type* dummy = 0)
00086     {
00087        //std::cout << "viennacl .. " << std::endl;
00088       return viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>, 
00089                                           const viennacl::vector<ScalarType, alignment>,
00090                                           viennacl::op_norm_inf >(v1, v1);
00091     }
00092 
00093   } // end namespace linalg
00094 } // end namespace viennacl
00095 #endif
00096 
00097 
00098 
00099 
00100 

Generated on Fri Dec 30 2011 23:20:43 for ViennaCL - The Vienna Computing Library by  doxygen 1.7.1