ViennaCL - The Vienna Computing Library  1.5.1
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-2014, Institute for Microelectronics,
6  Institute for Analysis and Scientific Computing,
7  TU Wien.
8  Portions of this software are copyright by UChicago Argonne, LLC.
9 
10  -----------------
11  ViennaCL - The Vienna Computing Library
12  -----------------
13 
14  Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15 
16  (A list of authors and contributors can be found in the PDF manual)
17 
18  License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20 
25 #include <cmath>
26 #include "viennacl/forwards.h"
27 #include "viennacl/tools/tools.hpp"
29 #include "viennacl/meta/tag_of.hpp"
30 
31 namespace viennacl
32 {
33  //
34  // generic norm_1 function
35  // uses tag dispatch to identify which algorithm
36  // should be called
37  //
38  namespace linalg
39  {
40 
41  #ifdef VIENNACL_WITH_UBLAS
42  // ----------------------------------------------------
43  // UBLAS
44  //
45  template< typename VectorT >
47  typename VectorT::value_type
48  >::type
49  norm_1(VectorT const& vector)
50  {
51  // std::cout << "ublas .. " << std::endl;
52  return boost::numeric::ublas::norm_1(vector);
53  }
54  #endif
55 
56 
57  // ----------------------------------------------------
58  // STL
59  //
60  template< typename T, typename A >
61  T norm_1(std::vector<T, A> const & v1)
62  {
63  //std::cout << "stl .. " << std::endl;
64  T result = 0;
65  for (typename std::vector<T, A>::size_type i=0; i<v1.size(); ++i)
66  result += std::fabs(v1[i]);
67 
68  return result;
69  }
70 
71  // ----------------------------------------------------
72  // VIENNACL
73  //
74  template< typename ScalarType>
79  {
82  viennacl::op_norm_1 >(vector, vector);
83  }
84 
85  // with vector expression:
86  template <typename LHS, typename RHS, typename OP>
91  {
94  viennacl::op_norm_1 >(vector, vector);
95  }
96 
97  // with matrix
98  /*template<typename NumericT, typename F>
99  scalar_expression< const matrix_base<NumericT, F>, const matrix_base<NumericT, F>, op_norm_1>
100  norm_1(const matrix<NumericT, F> & A)
101  {
102  return scalar_expression< const matrix_base<NumericT, F>, const matrix_base<NumericT, F>, op_norm_1>(A, A);
103  }*/
104 
105  } // end namespace linalg
106 } // end namespace viennacl
107 #endif
108 
109 
110 
111 
112 
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:29
Dispatch facility for distinguishing between ublas, STL and ViennaCL types.
Various little tools used here and there in ViennaCL.
This file provides the forward declarations for the main types used within ViennaCL.
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:175
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:181
viennacl::scalar_expression< const viennacl::vector_expression< const LHS, const RHS, OP >, const viennacl::vector_expression< const LHS, const RHS, OP >, viennacl::op_norm_1 > norm_1(viennacl::vector_expression< const LHS, const RHS, OP > const &vector)
Definition: norm_1.hpp:90
A vector class representing a linear memory sequence on the GPU. Inspired by boost::numeric::ublas::v...
Definition: forwards.h:208
A tag class representing the 1-norm of a vector.
Definition: forwards.h:153
T norm_1(std::vector< T, A > const &v1)
Definition: norm_1.hpp:61
Simple enable-if variant that uses the SFINAE pattern.