ViennaCL - The Vienna Computing Library  1.7.0
Free open-source GPU-accelerated linear algebra and solver library.
maxmin.hpp
Go to the documentation of this file.
1 #ifndef VIENNACL_LINALG_MAXMIN_HPP_
2 #define VIENNACL_LINALG_MAXMIN_HPP_
3 
4 /* =========================================================================
5  Copyright (c) 2010-2015, 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"
29 #include "viennacl/meta/tag_of.hpp"
31 
32 namespace viennacl
33 {
34  //
35  // generic norm_inf function
36  // uses tag dispatch to identify which algorithm
37  // should be called
38  //
39  namespace linalg
40  {
41 
42 
43  // ----------------------------------------------------
44  // STL
45  //
46  template< typename NumericT >
47  NumericT max(std::vector<NumericT> const & v1)
48  {
49  //std::cout << "stl .. " << std::endl;
50  NumericT result = v1[0];
51  for (vcl_size_t i=1; i<v1.size(); ++i)
52  {
53  if (v1[i] > result)
54  result = v1[i];
55  }
56 
57  return result;
58  }
59 
60  // ----------------------------------------------------
61  // VIENNACL
62  //
63  template< typename ScalarType>
67  max(viennacl::vector_base<ScalarType> const & v1)
68  {
69  //std::cout << "viennacl .. " << std::endl;
71  const viennacl::vector_base<ScalarType>,
73  }
74 
75  // with vector expression:
76  template<typename LHS, typename RHS, typename OP>
80  max(viennacl::vector_expression<const LHS, const RHS, OP> const & vector)
81  {
83  const viennacl::vector_expression<const LHS, const RHS, OP>,
84  viennacl::op_max >(vector, vector);
85  }
86 
87  // ----------------------------------------------------
88  // STL
89  //
90  template< typename NumericT >
91  NumericT min(std::vector<NumericT> const & v1)
92  {
93  //std::cout << "stl .. " << std::endl;
94  NumericT result = v1[0];
95  for (vcl_size_t i=1; i<v1.size(); ++i)
96  {
97  if (v1[i] < result)
98  result = v1[i];
99  }
100 
101  return result;
102  }
103 
104  // ----------------------------------------------------
105  // VIENNACL
106  //
107  template< typename ScalarType>
109  const viennacl::vector_base<ScalarType>,
111  min(viennacl::vector_base<ScalarType> const & v1)
112  {
113  //std::cout << "viennacl .. " << std::endl;
115  const viennacl::vector_base<ScalarType>,
116  viennacl::op_min >(v1, v1);
117  }
118 
119  template< typename ScalarType>
121  const viennacl::vector_base<ScalarType>,
124  {
125  //std::cout << "viennacl .. " << std::endl;
127  const viennacl::vector_base<ScalarType>,
128  viennacl::op_min >(v1, v1);
129  }
130 
131  // with vector expression:
132  template<typename LHS, typename RHS, typename OP>
134  const viennacl::vector_expression<const LHS, const RHS, OP>,
136  min(viennacl::vector_expression<const LHS, const RHS, OP> const & vector)
137  {
139  const viennacl::vector_expression<const LHS, const RHS, OP>,
140  viennacl::op_min >(vector, vector);
141  }
142 
143 
144 
145  } // end namespace linalg
146 } // end namespace viennacl
147 #endif
148 
149 
150 
151 
152 
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:230
An expression template class that represents a binary operation that yields a vector.
Definition: forwards.h:239
A tag class representing the maximum of a vector.
Definition: forwards.h:210
float NumericT
Definition: bisect.cpp:40
Main namespace in ViennaCL. Holds all the basic types such as vector, matrix, etc. and defines operations upon them.
Definition: cpu_ram.hpp:34
viennacl::vector< float > v1
std::size_t vcl_size_t
Definition: forwards.h:75
A tag class representing the minimum of a vector.
Definition: forwards.h:213
NumericT max(std::vector< NumericT > const &v1)
Definition: maxmin.hpp:47
A collection of compile time type deductions.
Simple enable-if variant that uses the SFINAE pattern.
NumericT min(std::vector< NumericT > const &v1)
Definition: maxmin.hpp:91