ViennaCL - The Vienna Computing Library: viennacl/linalg/norm_inf.hpp Source File

ViennaCL - The Vienna Computing Library 1.7.1 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
norm_inf.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_NORM_INF_HPP_
2 #define VIENNACL_LINALG_NORM_INF_HPP_
3
4 /* =========================================================================
5 Copyright (c) 2010-2016, 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 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"
28 #include "viennacl/meta/enable_if.hpp"
29 #include "viennacl/meta/tag_of.hpp"
30
31 namespace viennacl
32 {
33 //
34 // generic norm_inf 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 >
46 typename viennacl::enable_if< viennacl::is_ublas< typename viennacl::traits::tag_of< VectorT >::type >::value,
47 typename VectorT::value_type
48 >::type
49 norm_inf(VectorT const& v1)
50 {
51 return boost::numeric::ublas::norm_inf(v1);
52 }
53 #endif
54
55
56 // ----------------------------------------------------
57 // STL
58 //
59 template< typename T, typename A >
60 T norm_inf(std::vector<T, A> const & v1)
61 {
62 //std::cout << "stl .. " << std::endl;
63 T result = 0;
64 for (typename std::vector<T, A>::size_type i=0; i<v1.size(); ++i)
65 {
66 if (std::fabs(v1[i]) > result)
67 result = std::fabs(v1[i]);
68 }
69
70 return result;
71 }
72
73 // ----------------------------------------------------
74 // VIENNACL
75 //
76 template< typename ScalarType>
77 viennacl::scalar_expression< const viennacl::vector_base<ScalarType>,
78 const viennacl::vector_base<ScalarType>,
79 viennacl::op_norm_inf >
80 norm_inf(viennacl::vector_base<ScalarType> const & v1)
81 {
82 //std::cout << "viennacl .. " << std::endl;
83 return viennacl::scalar_expression< const viennacl::vector_base<ScalarType>,
84 const viennacl::vector_base<ScalarType>,
85 viennacl::op_norm_inf >(v1, v1);
86 }
87
88 // with vector expression:
89 template<typename LHS, typename RHS, typename OP>
90 viennacl::scalar_expression<const viennacl::vector_expression<const LHS, const RHS, OP>,
91 const viennacl::vector_expression<const LHS, const RHS, OP>,
92 viennacl::op_norm_inf>
93 norm_inf(viennacl::vector_expression<const LHS, const RHS, OP> const & vector)
94 {
95 return viennacl::scalar_expression< const viennacl::vector_expression<const LHS, const RHS, OP>,
96 const viennacl::vector_expression<const LHS, const RHS, OP>,
97 viennacl::op_norm_inf >(vector, vector);
98 }
99
100
101 } // end namespace linalg
102 } // end namespace viennacl
103 #endif
104
105
106
107
108
viennacl::enable_if
Simple enable-if variant that uses the SFINAE pattern.
Definition: enable_if.hpp:30
tag_of.hpp
Dispatch facility for distinguishing between ublas, STL and ViennaCL types.
tools.hpp
Various little tools used here and there in ViennaCL.
forwards.h
This file provides the forward declarations for the main types used within ViennaCL.
viennacl::scalar_expression
A proxy for scalar expressions (e.g. from inner vector products)
Definition: forwards.h:230
viennacl::vector_expression
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:239
v1
viennacl::vector< float > v1
Definition: global_variables.cpp:60
viennacl::vector_base
Common base class for dense vectors, vector ranges, and vector slices.
Definition: vector_def.hpp:104
viennacl::vector
Definition: forwards.h:266
viennacl::linalg::norm_inf
T norm_inf(std::vector< T, A > const &v1)
Definition: norm_inf.hpp:60
viennacl::linalg::norm_inf
viennacl::scalar_expression< const viennacl::vector_expression< const LHS, const RHS, OP >, const viennacl::vector_expression< const LHS, const RHS, OP >, viennacl::op_norm_inf > norm_inf(viennacl::vector_expression< const LHS, const RHS, OP > const &vector)
Definition: norm_inf.hpp:93
viennacl::op_norm_inf
A tag class representing the inf-norm of a vector.
Definition: forwards.h:207
enable_if.hpp
Simple enable-if variant that uses the SFINAE pattern.