nemo/Norms.h
Go to the documentation of this file.00001 #ifndef _NEMO_NORMS_H_ 00002 #define _NEMO_NORMS_H_ 00003 00004 #include "Mapping.h" 00005 #include "detail/nemo-cpp11.h" 00006 00007 #include <cmath> 00008 00009 00010 namespace nemo { 00011 00012 #ifndef NEMO_PARSED_BY_DOXYGEN 00013 template <class T> 00014 class AbsNormDefinition : public MappingDefinition<T,T> { 00015 public: 00016 T evaluate(T value) const { 00017 return (value<0)?(-value):value; 00018 } 00019 }; 00020 #endif 00021 00022 template <typename T> 00023 static inline Mapping<T,T> absNorm(){ 00024 return Mapping<T,T>(new AbsNormDefinition<T>()); 00025 } 00026 00027 #ifndef NEMO_PARSED_BY_DOXYGEN 00028 template <class T, class NormType> 00029 class EuclideanNormDefinition : public MappingDefinition<T,NormType> { 00030 public: 00031 NormType evaluate(T value) const { 00032 NormType squareSum = (NormType)0; 00033 for(unsigned int i=0; i<value.numElements(); i++){ 00034 squareSum += value.getElement(i)*value.getElement(i); 00035 } 00036 return sqrt(squareSum); 00037 } 00038 }; 00039 #endif 00040 00041 #ifdef _NEMO_HAS_FUNCTION_TEMPLATE_DEFAULTS_ 00042 template <typename T, typename NormType=double> 00043 #else 00044 template <typename T, typename NormType> 00045 #endif 00046 static inline Mapping<T,NormType> euclideanNorm(){ 00047 return Mapping<T,NormType>(new EuclideanNormDefinition<T,NormType>()); 00048 } 00049 00050 00051 #ifndef NEMO_PARSED_BY_DOXYGEN 00052 template <class T, class NormType=double> 00053 class EuclideanSquareDefinition : public MappingDefinition<T,NormType> { 00054 public: 00055 NormType evaluate(T value) const { 00056 NormType squareSum = (NormType)0; 00057 for(unsigned int i=0; i<value.numElements(); i++){ 00058 squareSum += value.getElement(i)*value.getElement(i); 00059 } 00060 return squareSum; 00061 } 00062 }; 00063 #endif 00064 00065 #ifdef _NEMO_HAS_FUNCTION_TEMPLATE_DEFAULTS_ 00066 template <typename T, typename NormType=double> 00067 #else 00068 template <typename T, typename NormType> 00069 #endif 00070 static inline Mapping<T,NormType> euclideanSquare(){ 00071 return Mapping<T,NormType>(new EuclideanSquareDefinition<T,NormType>()); 00072 } 00073 00074 00075 #ifndef NEMO_PARSED_BY_DOXYGEN 00076 template <class T, class NormType=double> 00077 class MaxNormDefinition : public MappingDefinition<T,NormType> { 00078 public: 00079 NormType evaluate(T value) const { 00080 NormType max = (NormType)0; 00081 for(unsigned int i=0; i<value.numElements(); i++){ 00082 if(value.getElement(i) < -max){ 00083 max = -value.getElement(i); 00084 } 00085 else if(max < value.getElement(i)){ 00086 max = value.getElement(i); 00087 } 00088 } 00089 return max; 00090 } 00091 }; 00092 #endif 00093 00094 #ifdef _NEMO_HAS_FUNCTION_TEMPLATE_DEFAULTS_ 00095 template <typename T, typename NormType=double> 00096 #else 00097 template <typename T, typename NormType> 00098 #endif 00099 static inline Mapping<T,NormType> maxNorm(){ 00100 return Mapping<T,NormType>(new MaxNormDefinition<T,NormType>()); 00101 } 00102 00103 00104 } // end namespace 00105 00106 #endif 00107
Generated on Mon Feb 25 12:49:59 2013 for NemoMath by 1.6.3