Go to the documentation of this file.00001 #ifndef VIENNACL_LINALG_NORM_1_HPP_
00002 #define VIENNACL_LINALG_NORM_1_HPP_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024 #include <math.h>
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
00034
00035
00036
00037 namespace linalg
00038 {
00039
00040 #ifdef VIENNACL_HAVE_UBLAS
00041
00042
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
00051 return boost::numeric::ublas::norm_1(vector);
00052 }
00053 #endif
00054
00055
00056
00057
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
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
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 }
00090 }
00091 #endif
00092
00093
00094
00095
00096