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

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

Go to the documentation of this file.
00001 #ifndef VIENNACL_LINALG_NORM_1_HPP_
00002 #define VIENNACL_LINALG_NORM_1_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_1 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_1(VectorT const& vector, 
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_1(vector);
00052     }
00053     #endif
00054     
00055     
00056     // ----------------------------------------------------
00057     // STL
00058     //
00059     template< typename VectorT>
00060     typename VectorT::value_type
00061     norm_1(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         result += fabs(v1[i]);
00069       
00070       return result;
00071     }
00072     
00073     // ----------------------------------------------------
00074     // VIENNACL
00075     //
00076     template< typename ScalarType, unsigned int alignment >
00077     viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>, 
00078                                  const viennacl::vector<ScalarType, alignment>,
00079                                  viennacl::op_norm_1 >
00080     norm_1(viennacl::vector<ScalarType, alignment> const & vector, 
00081          typename viennacl::enable_if< viennacl::is_viennacl< typename viennacl::traits::tag_of< viennacl::vector<ScalarType, alignment> >::type >::value
00082                                      >::type* dummy = 0)
00083     {
00084       return viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>, 
00085                                           const viennacl::vector<ScalarType, alignment>,
00086                                           viennacl::op_norm_1 >(vector, vector);
00087     }
00088 
00089   } // end namespace linalg
00090 } // end namespace viennacl
00091 #endif
00092 
00093 
00094 
00095 
00096 

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