|
ViennaCL - The Vienna Computing Library
1.4.2
|
00001 #ifndef VIENNACL_LINALG_NORM_INF_HPP_ 00002 #define VIENNACL_LINALG_NORM_INF_HPP_ 00003 00004 /* ========================================================================= 00005 Copyright (c) 2010-2013, 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, unsigned int alignment > 00077 viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>, 00078 const viennacl::vector<ScalarType, alignment>, 00079 viennacl::op_norm_inf > 00080 norm_inf(viennacl::vector<ScalarType, alignment> const & v1) 00081 { 00082 //std::cout << "viennacl .. " << std::endl; 00083 return viennacl::scalar_expression< const viennacl::vector<ScalarType, alignment>, 00084 const viennacl::vector<ScalarType, alignment>, 00085 viennacl::op_norm_inf >(v1, v1); 00086 } 00087 00088 template< typename VectorType > 00089 viennacl::scalar_expression< const viennacl::vector_range<VectorType>, 00090 const viennacl::vector_range<VectorType>, 00091 viennacl::op_norm_inf > 00092 norm_inf(viennacl::vector_range<VectorType> const & vector) 00093 { 00094 return viennacl::scalar_expression< const viennacl::vector_range<VectorType>, 00095 const viennacl::vector_range<VectorType>, 00096 viennacl::op_norm_inf >(vector, vector); 00097 } 00098 00099 template< typename VectorType > 00100 viennacl::scalar_expression< const viennacl::vector_slice<VectorType>, 00101 const viennacl::vector_slice<VectorType>, 00102 viennacl::op_norm_inf > 00103 norm_inf(viennacl::vector_slice<VectorType> const & vector) 00104 { 00105 return viennacl::scalar_expression< const viennacl::vector_slice<VectorType>, 00106 const viennacl::vector_slice<VectorType>, 00107 viennacl::op_norm_inf >(vector, vector); 00108 } 00109 00110 // with vector expression: 00111 template <typename LHS, typename RHS, typename OP> 00112 viennacl::scalar_expression<const viennacl::vector_expression<const LHS, const RHS, OP>, 00113 const viennacl::vector_expression<const LHS, const RHS, OP>, 00114 viennacl::op_norm_inf> 00115 norm_inf(viennacl::vector_expression<const LHS, const RHS, OP> const & vector) 00116 { 00117 return viennacl::scalar_expression< const viennacl::vector_expression<const LHS, const RHS, OP>, 00118 const viennacl::vector_expression<const LHS, const RHS, OP>, 00119 viennacl::op_norm_inf >(vector, vector); 00120 } 00121 00122 00123 } // end namespace linalg 00124 } // end namespace viennacl 00125 #endif 00126 00127 00128 00129 00130
1.7.6.1