Blaze  3.6
LpNorm.h
Go to the documentation of this file.
1 //=================================================================================================
33 //=================================================================================================
34 
35 #ifndef _BLAZE_MATH_FUNCTORS_LPNORM_H_
36 #define _BLAZE_MATH_FUNCTORS_LPNORM_H_
37 
38 
39 //*************************************************************************************************
40 // Includes
41 //*************************************************************************************************
42 
44 #include <blaze/system/Inline.h>
46 
47 
48 namespace blaze {
49 
50 //=================================================================================================
51 //
52 // CLASS DEFINITION
53 //
54 //=================================================================================================
55 
56 //*************************************************************************************************
60 template< size_t... P > // Compile time norm parameter
61 struct LpNorm
62 {
63  //**********************************************************************************************
69  template< typename T >
70  BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
71  {
72  BLAZE_STATIC_ASSERT_MSG( sizeof...( P ) == 1UL, "Missing norm parameter detected" );
73  return lpNorm( a, P... );
74  }
75  //**********************************************************************************************
76 
77  //**********************************************************************************************
84  template< typename T, typename ST >
85  BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a, ST p ) const
86  {
87  BLAZE_STATIC_ASSERT_MSG( sizeof...( P ) == 0UL, "Over-specified norm parameter detected" );
88  return lpNorm( a, p );
89  }
90  //**********************************************************************************************
91 };
92 //*************************************************************************************************
93 
94 
95 
96 
97 //=================================================================================================
98 //
99 // CLASS SPECIALIZATIONS
100 //
101 //=================================================================================================
102 
103 //*************************************************************************************************
108 template<>
109 struct LpNorm<1UL>
110 {
111  //**********************************************************************************************
114  explicit inline LpNorm()
115  {}
116  //**********************************************************************************************
117 
118  //**********************************************************************************************
124  template< typename T >
125  BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
126  {
127  return l1Norm( a );
128  }
129  //**********************************************************************************************
130 };
132 //*************************************************************************************************
133 
134 
135 //*************************************************************************************************
140 template<>
141 struct LpNorm<2UL>
142 {
143  //**********************************************************************************************
146  explicit inline LpNorm()
147  {}
148  //**********************************************************************************************
149 
150  //**********************************************************************************************
156  template< typename T >
157  BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
158  {
159  return l2Norm( a );
160  }
161  //**********************************************************************************************
162 };
164 //*************************************************************************************************
165 
166 
167 //*************************************************************************************************
172 template<>
173 struct LpNorm<3UL>
174 {
175  //**********************************************************************************************
178  explicit inline LpNorm()
179  {}
180  //**********************************************************************************************
181 
182  //**********************************************************************************************
188  template< typename T >
189  BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
190  {
191  return l3Norm( a );
192  }
193  //**********************************************************************************************
194 };
196 //*************************************************************************************************
197 
198 
199 //*************************************************************************************************
204 template<>
205 struct LpNorm<4UL>
206 {
207  //**********************************************************************************************
210  explicit inline LpNorm()
211  {}
212  //**********************************************************************************************
213 
214  //**********************************************************************************************
220  template< typename T >
221  BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
222  {
223  return l4Norm( a );
224  }
225  //**********************************************************************************************
226 };
228 //*************************************************************************************************
229 
230 } // namespace blaze
231 
232 #endif
decltype(auto) l3Norm(const DenseMatrix< MT, SO > &dm)
Computes the L3 norm for the given dense matrix.
Definition: DMatNormExpr.h:573
decltype(auto) l2Norm(const DenseMatrix< MT, SO > &dm)
Computes the L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:547
decltype(auto) l4Norm(const DenseMatrix< MT, SO > &dm)
Computes the L4 norm for the given dense matrix.
Definition: DMatNormExpr.h:599
decltype(auto) lpNorm(const DenseMatrix< MT, SO > &dm, ST p)
Computes the Lp norm for the given dense matrix.
Definition: DMatNormExpr.h:631
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.In case of an invalid compile time expression, a compilation error is cr...
Definition: StaticAssert.h:123
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
Compile time assertion.
decltype(auto) l1Norm(const DenseMatrix< MT, SO > &dm)
Computes the L1 norm for the given dense matrix.
Definition: DMatNormExpr.h:521
Macro for CUDA compatibility.
#define BLAZE_DEVICE_CALLABLE
Conditional macro that sets host and device attributes when compiled with CUDA.
Definition: HostDevice.h:94
System settings for the inline keywords.