All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
maxmin.hpp
Go to the documentation of this file.
#ifndef VIENNACL_LINALG_MAXMIN_HPP_
#define VIENNACL_LINALG_MAXMIN_HPP_
/* =========================================================================
Copyright (c) 2010-2016, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
Portions of this software are copyright by UChicago Argonne, LLC.
-----------------
ViennaCL - The Vienna Computing Library
-----------------
Project Head: Karl Rupp rupp@iue.tuwien.ac.at
(A list of authors and contributors can be found in the manual)
License: MIT (X11), see file LICENSE in the base directory
============================================================================= */
#include <cmath>
#include "viennacl/forwards.h"
#include "viennacl/tools/tools.hpp"
#include "viennacl/meta/enable_if.hpp"
#include "viennacl/meta/tag_of.hpp"
#include "viennacl/meta/result_of.hpp"
namespace viennacl
{
//
// generic norm_inf function
// uses tag dispatch to identify which algorithm
// should be called
//
namespace linalg
{
// ----------------------------------------------------
// STL
//
template< typename NumericT >
NumericT max(std::vector<NumericT> const & v1)
{
//std::cout << "stl .. " << std::endl;
NumericT result = v1[0];
for (vcl_size_t i=1; i<v1.size(); ++i)
{
if (v1[i] > result)
result = v1[i];
}
return result;
}
// ----------------------------------------------------
// VIENNACL
//
template< typename ScalarType>
viennacl::scalar_expression< const viennacl::vector_base<ScalarType>,
const viennacl::vector_base<ScalarType>,
viennacl::op_max >
max(viennacl::vector_base<ScalarType> const & v1)
{
//std::cout << "viennacl .. " << std::endl;
return viennacl::scalar_expression< const viennacl::vector_base<ScalarType>,
const viennacl::vector_base<ScalarType>,
viennacl::op_max >(v1, v1);
}
// with vector expression:
template<typename LHS, typename RHS, typename OP>
viennacl::scalar_expression<const viennacl::vector_expression<const LHS, const RHS, OP>,
const viennacl::vector_expression<const LHS, const RHS, OP>,
viennacl::op_max>
max(viennacl::vector_expression<const LHS, const RHS, OP> const & vector)
{
return viennacl::scalar_expression< const viennacl::vector_expression<const LHS, const RHS, OP>,
const viennacl::vector_expression<const LHS, const RHS, OP>,
viennacl::op_max >(vector, vector);
}
// ----------------------------------------------------
// STL
//
template< typename NumericT >
NumericT min(std::vector<NumericT> const & v1)
{
//std::cout << "stl .. " << std::endl;
NumericT result = v1[0];
for (vcl_size_t i=1; i<v1.size(); ++i)
{
if (v1[i] < result)
result = v1[i];
}
return result;
}
// ----------------------------------------------------
// VIENNACL
//
template< typename ScalarType>
viennacl::scalar_expression< const viennacl::vector_base<ScalarType>,
const viennacl::vector_base<ScalarType>,
viennacl::op_min >
min(viennacl::vector_base<ScalarType> const & v1)
{
//std::cout << "viennacl .. " << std::endl;
return viennacl::scalar_expression< const viennacl::vector_base<ScalarType>,
const viennacl::vector_base<ScalarType>,
viennacl::op_min >(v1, v1);
}
template< typename ScalarType>
viennacl::scalar_expression< const viennacl::vector_base<ScalarType>,
const viennacl::vector_base<ScalarType>,
viennacl::op_min >
min(viennacl::vector<ScalarType> const & v1)
{
//std::cout << "viennacl .. " << std::endl;
return viennacl::scalar_expression< const viennacl::vector_base<ScalarType>,
const viennacl::vector_base<ScalarType>,
viennacl::op_min >(v1, v1);
}
// with vector expression:
template<typename LHS, typename RHS, typename OP>
viennacl::scalar_expression<const viennacl::vector_expression<const LHS, const RHS, OP>,
const viennacl::vector_expression<const LHS, const RHS, OP>,
viennacl::op_min>
min(viennacl::vector_expression<const LHS, const RHS, OP> const & vector)
{
return viennacl::scalar_expression< const viennacl::vector_expression<const LHS, const RHS, OP>,
const viennacl::vector_expression<const LHS, const RHS, OP>,
viennacl::op_min >(vector, vector);
}
} // end namespace linalg
} // end namespace viennacl
#endif
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
viennacl::op_max
A tag class representing the maximum of a vector.
Definition: forwards.h:210
NumericT
float NumericT
Definition: bisect.cpp:40
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::vcl_size_t
std::size_t vcl_size_t
Definition: forwards.h:75
viennacl::vector
Definition: forwards.h:266
viennacl::op_min
A tag class representing the minimum of a vector.
Definition: forwards.h:213
viennacl::linalg::max
NumericT max(std::vector< NumericT > const &v1)
Definition: maxmin.hpp:47
result_of.hpp
A collection of compile time type deductions.
enable_if.hpp
Simple enable-if variant that uses the SFINAE pattern.
viennacl::linalg::min
NumericT min(std::vector< NumericT > const &v1)
Definition: maxmin.hpp:91