ViennaCL - The Vienna Computing Library
1.5.2
|
00001 #ifndef VIENNACL_LINALG_NORM_INF_HPP_ 00002 #define VIENNACL_LINALG_NORM_INF_HPP_ 00003 00004 /* ========================================================================= 00005 Copyright (c) 2010-2014, Institute for Microelectronics, 00006 Institute for Analysis and Scientific Computing, 00007 TU Wien. 00008 Portions of this software are copyright by UChicago Argonne, LLC. 00009 00010 ----------------- 00011 ViennaCL - The Vienna Computing Library 00012 ----------------- 00013 00014 Project Head: Karl Rupp rupp@iue.tuwien.ac.at 00015 00016 (A list of authors and contributors can be found in the PDF manual) 00017 00018 License: MIT (X11), see file LICENSE in the base directory 00019 ============================================================================= */ 00020 00025 #include <cmath> 00026 #include "viennacl/forwards.h" 00027 #include "viennacl/tools/tools.hpp" 00028 #include "viennacl/meta/enable_if.hpp" 00029 #include "viennacl/meta/tag_of.hpp" 00030 00031 namespace viennacl 00032 { 00033 // 00034 // generic norm_inf function 00035 // uses tag dispatch to identify which algorithm 00036 // should be called 00037 // 00038 namespace linalg 00039 { 00040 00041 #ifdef VIENNACL_WITH_UBLAS 00042 // ---------------------------------------------------- 00043 // UBLAS 00044 // 00045 template< typename VectorT > 00046 typename viennacl::enable_if< viennacl::is_ublas< typename viennacl::traits::tag_of< VectorT >::type >::value, 00047 typename VectorT::value_type 00048 >::type 00049 norm_inf(VectorT const& v1) 00050 { 00051 return boost::numeric::ublas::norm_inf(v1); 00052 } 00053 #endif 00054 00055 00056 // ---------------------------------------------------- 00057 // STL 00058 // 00059 template< typename T, typename A > 00060 T norm_inf(std::vector<T, A> const & v1) 00061 { 00062 //std::cout << "stl .. " << std::endl; 00063 T result = 0; 00064 for (typename std::vector<T, A>::size_type i=0; i<v1.size(); ++i) 00065 { 00066 if (std::fabs(v1[i]) > result) 00067 result = std::fabs(v1[i]); 00068 } 00069 00070 return result; 00071 } 00072 00073 // ---------------------------------------------------- 00074 // VIENNACL 00075 // 00076 template< typename ScalarType> 00077 viennacl::scalar_expression< const viennacl::vector_base<ScalarType>, 00078 const viennacl::vector_base<ScalarType>, 00079 viennacl::op_norm_inf > 00080 norm_inf(viennacl::vector_base<ScalarType> const & v1) 00081 { 00082 //std::cout << "viennacl .. " << std::endl; 00083 return viennacl::scalar_expression< const viennacl::vector_base<ScalarType>, 00084 const viennacl::vector_base<ScalarType>, 00085 viennacl::op_norm_inf >(v1, v1); 00086 } 00087 00088 // with vector expression: 00089 template <typename LHS, typename RHS, typename OP> 00090 viennacl::scalar_expression<const viennacl::vector_expression<const LHS, const RHS, OP>, 00091 const viennacl::vector_expression<const LHS, const RHS, OP>, 00092 viennacl::op_norm_inf> 00093 norm_inf(viennacl::vector_expression<const LHS, const RHS, OP> const & vector) 00094 { 00095 return viennacl::scalar_expression< const viennacl::vector_expression<const LHS, const RHS, OP>, 00096 const viennacl::vector_expression<const LHS, const RHS, OP>, 00097 viennacl::op_norm_inf >(vector, vector); 00098 } 00099 00100 // with matrix: 00101 /* 00102 template<typename NumericT, typename F> 00103 scalar_expression< const matrix_base<NumericT, F>, const matrix_base<NumericT, F>, op_norm_inf> 00104 norm_inf(const matrix<NumericT, F> & A) 00105 { 00106 return scalar_expression< const matrix_base<NumericT, F>, const matrix_base<NumericT, F>, op_norm_inf>(A, A); 00107 }*/ 00108 00109 00110 } // end namespace linalg 00111 } // end namespace viennacl 00112 #endif 00113 00114 00115 00116 00117