Blaze 3.9
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
43#include <utility>
45#include <blaze/system/Inline.h>
47
48
49namespace blaze {
50
51//=================================================================================================
52//
53// CLASS DEFINITION
54//
55//=================================================================================================
56
57//*************************************************************************************************
61template< size_t... P > // Compile time norm parameter
62struct LpNorm
63{
64 //**********************************************************************************************
70 template< typename T >
71 BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( T&& a ) const
72 {
73 BLAZE_STATIC_ASSERT_MSG( sizeof...( P ) == 1UL, "Missing norm parameter detected" );
74 return lpNorm( std::forward<T>( a ), P... );
75 }
76 //**********************************************************************************************
77
78 //**********************************************************************************************
85 template< typename T, typename ST >
86 BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( T&& a, ST p ) const
87 {
88 BLAZE_STATIC_ASSERT_MSG( sizeof...( P ) == 0UL, "Over-specified norm parameter detected" );
89 return lpNorm( std::forward<T>( a ), p );
90 }
91 //**********************************************************************************************
92};
93//*************************************************************************************************
94
95
96
97
98//=================================================================================================
99//
100// CLASS SPECIALIZATIONS
101//
102//=================================================================================================
103
104//*************************************************************************************************
109template<>
110struct LpNorm<1UL>
111{
112 //**********************************************************************************************
118 template< typename T >
119 BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
120 {
121 return l1Norm( a );
122 }
123 //**********************************************************************************************
124};
126//*************************************************************************************************
127
128
129//*************************************************************************************************
134template<>
135struct LpNorm<2UL>
136{
137 //**********************************************************************************************
143 template< typename T >
144 BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
145 {
146 return l2Norm( a );
147 }
148 //**********************************************************************************************
149};
151//*************************************************************************************************
152
153
154//*************************************************************************************************
159template<>
160struct LpNorm<3UL>
161{
162 //**********************************************************************************************
168 template< typename T >
169 BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
170 {
171 return l3Norm( a );
172 }
173 //**********************************************************************************************
174};
176//*************************************************************************************************
177
178
179//*************************************************************************************************
184template<>
185struct LpNorm<4UL>
186{
187 //**********************************************************************************************
193 template< typename T >
194 BLAZE_ALWAYS_INLINE BLAZE_DEVICE_CALLABLE decltype(auto) operator()( const T& a ) const
195 {
196 return l4Norm( a );
197 }
198 //**********************************************************************************************
199};
201//*************************************************************************************************
202
203} // namespace blaze
204
205#endif
Macro for CUDA compatibility.
Compile time assertion.
decltype(auto) lpNorm(const DenseMatrix< MT, SO > &dm, ST p)
Computes the Lp norm for the given dense matrix.
Definition: DMatNormExpr.h:735
decltype(auto) l4Norm(const DenseMatrix< MT, SO > &dm)
Computes the L4 norm for the given dense matrix.
Definition: DMatNormExpr.h:703
decltype(auto) l2Norm(const DenseMatrix< MT, SO > &dm)
Computes the L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:651
decltype(auto) l1Norm(const DenseMatrix< MT, SO > &dm)
Computes the L1 norm for the given dense matrix.
Definition: DMatNormExpr.h:625
decltype(auto) l3Norm(const DenseMatrix< MT, SO > &dm)
Computes the L3 norm for the given dense matrix.
Definition: DMatNormExpr.h:677
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.
Definition: StaticAssert.h:123
#define BLAZE_ALWAYS_INLINE
Platform dependent setup of an enforced inline keyword.
Definition: Inline.h:85
#define BLAZE_DEVICE_CALLABLE
Conditional macro that sets host and device attributes when compiled with CUDA.
Definition: HostDevice.h:94
Generic wrapper for the lpNorm() function.
Definition: LpNorm.h:63
System settings for the inline keywords.