ViennaCL - The Vienna Computing Library
1.2.0
Main Page
Namespaces
Data Structures
Files
File List
Globals
viennacl
linalg
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
"
27
#include "
viennacl/meta/enable_if.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,
47
typename
viennacl::enable_if
<
viennacl::is_ublas
<
typename
viennacl::traits::tag_of< VectorT >::type
>::value
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,
62
typename
viennacl::enable_if
<
viennacl::is_stl
<
typename
viennacl::traits::tag_of< VectorT >::type
>::value
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 >
77
viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>
,
78
const
viennacl::vector<ScalarType, alignment>
,
79
viennacl::op_norm_1 >
80
norm_1
(
viennacl::vector<ScalarType, alignment>
const
&
vector
,
81
typename
viennacl::enable_if
<
viennacl::is_viennacl
<
typename
viennacl::traits::tag_of
<
viennacl::vector<ScalarType, alignment>
>::type >::value
82
>::type* dummy = 0)
83
{
84
return
viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>
,
85
const
viennacl::vector<ScalarType, alignment>
,
86
viennacl::op_norm_1 >(vector, vector);
87
}
88
89
}
// end namespace linalg
90
}
// end namespace viennacl
91
#endif
92
93
94
95
96
Generated on Wed Oct 10 2012 09:58:14 for ViennaCL - The Vienna Computing Library by
1.8.1.2