ViennaCL - The Vienna Computing Library  1.2.0
norm_1.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_NORM_1_HPP_
2 #define VIENNACL_LINALG_NORM_1_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2011, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8 
9  -----------------
10  ViennaCL - The Vienna Computing Library
11  -----------------
12 
13  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
14 
15  (A list of authors and contributors can be found in the PDF manual)
16 
17  License: MIT (X11), see file LICENSE in the base directory
18 ============================================================================= */
19 
24 #include <math.h> //for sqrt()
25 #include "viennacl/forwards.h"
26 #include "viennacl/tools/tools.hpp"
28 #include "viennacl/meta/tag_of.hpp"
29 
30 namespace viennacl
31 {
32  //
33  // generic norm_1 function
34  // uses tag dispatch to identify which algorithm
35  // should be called
36  //
37  namespace linalg
38  {
39 
40  #ifdef VIENNACL_HAVE_UBLAS
41  // ----------------------------------------------------
42  // UBLAS
43  //
44  template< typename VectorT >
45  typename VectorT::value_type
46  norm_1(VectorT const& vector,
48  >::type* dummy = 0)
49  {
50  // std::cout << "ublas .. " << std::endl;
51  return boost::numeric::ublas::norm_1(vector);
52  }
53  #endif
54 
55 
56  // ----------------------------------------------------
57  // STL
58  //
59  template< typename VectorT>
60  typename VectorT::value_type
61  norm_1(VectorT const& v1,
63  >::type* dummy = 0)
64  {
65  //std::cout << "stl .. " << std::endl;
66  typename VectorT::value_type result = 0;
67  for (typename VectorT::size_type i=0; i<v1.size(); ++i)
68  result += fabs(v1[i]);
69 
70  return result;
71  }
72 
73  // ----------------------------------------------------
74  // VIENNACL
75  //
76  template< typename ScalarType, unsigned int alignment >
79  viennacl::op_norm_1 >
82  >::type* dummy = 0)
83  {
86  viennacl::op_norm_1 >(vector, vector);
87  }
88 
89  } // end namespace linalg
90 } // end namespace viennacl
91 #endif
92 
93 
94 
95 
96