35 #ifndef _BLAZE_MATH_EXPRESSIONS_DVECNORMEXPR_H_ 36 #define _BLAZE_MATH_EXPRESSIONS_DVECNORMEXPR_H_ 102 struct DVecNormHelper
106 using ET = ElementType_t<VT>;
109 using CT = RemoveReference_t< CompositeType_t<VT> >;
113 static constexpr
bool value =
114 ( useOptimizedKernels &&
116 If_t< HasSIMDEnabled_v<Abs> && HasSIMDEnabled_v<Power>
117 , And< GetSIMDEnabled<Abs,ET>, GetSIMDEnabled<Power,ET> >
118 , And< HasLoad<Abs>, HasLoad<Power> > >::value &&
119 HasSIMDAdd_v< ElementType_t<CT>, ElementType_t<CT> > );
149 template<
typename VT
154 inline decltype(
auto) norm_backend( const DenseVector<VT,TF>& dv, Abs
abs, Power power, Root root,
FalseType )
156 using CT = CompositeType_t<VT>;
157 using ET = ElementType_t<VT>;
158 using RT = decltype(
evaluate( root( std::declval<ET>() ) ) );
160 if( (~dv).
size() == 0UL )
return RT();
164 const size_t N( tmp.size() );
166 ET
norm( power(
abs( tmp[0UL] ) ) );
169 for( ; (i+4UL) <= N; i+=4UL ) {
170 norm += power(
abs( tmp[i ] ) ) + power(
abs( tmp[i+1UL] ) ) +
171 power(
abs( tmp[i+2UL] ) ) + power(
abs( tmp[i+3UL] ) );
173 for( ; (i+2UL) <= N; i+=2UL ) {
174 norm += power(
abs( tmp[i] ) ) + power(
abs( tmp[i+1UL] ) );
177 norm += power(
abs( tmp[i] ) );
201 template<
typename VT
206 inline decltype(
auto) norm_backend( const DenseVector<VT,TF>& dv, Abs
abs, Power power, Root root,
TrueType )
208 using CT = CompositeType_t<VT>;
209 using ET = ElementType_t<VT>;
210 using RT = decltype(
evaluate( root( std::declval<ET>() ) ) );
214 if( (~dv).
size() == 0UL )
return RT();
218 const size_t N( tmp.size() );
220 constexpr
bool remainder( !usePadding || !
IsPadded_v< RemoveReference_t<VT> > );
222 const size_t ipos( ( remainder )?( N &
size_t(-SIMDSIZE) ):( N ) );
225 SIMDTrait_t<ET> xmm1, xmm2, xmm3, xmm4;
228 for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
229 xmm1 += power(
abs( tmp.load(i ) ) );
230 xmm2 += power(
abs( tmp.load(i+SIMDSIZE ) ) );
231 xmm3 += power(
abs( tmp.load(i+SIMDSIZE*2UL) ) );
232 xmm4 += power(
abs( tmp.load(i+SIMDSIZE*3UL) ) );
234 for( ; (i+SIMDSIZE) < ipos; i+=SIMDSIZE*2UL ) {
235 xmm1 += power(
abs( tmp.load(i ) ) );
236 xmm2 += power(
abs( tmp.load(i+SIMDSIZE) ) );
238 for( ; i<ipos; i+=SIMDSIZE ) {
239 xmm1 += power(
abs( tmp.load(i) ) );
242 ET
norm(
sum( xmm1 + xmm2 + xmm3 + xmm4 ) );
244 for( ; remainder && i<N; ++i ) {
245 norm += power(
abs( tmp[i] ) );
275 template<
typename VT
280 decltype(
auto) norm_backend( const DenseVector<VT,TF>& dv, Abs
abs, Power power, Root root )
282 return norm_backend( ~dv,
abs, power, root,
Bool< DVecNormHelper<VT,Abs,Power>::value >() );
303 template<
typename VT
329 template<
typename VT
355 template<
typename VT
381 template<
typename VT
407 template<
typename VT
433 template<
typename VT
464 template<
typename VT
506 using Norm =
typename TypeAt< Norms,
min( P-1UL, 4UL ) >::Type;
508 return Norm()( ~dv );
528 template<
typename VT
decltype(auto) sqrNorm(const DenseMatrix< MT, SO > &dm)
Computes the squared L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:496
BoolConstant< false > FalseType
Type/value traits base class.The FalseType class is used as base class for type traits and value trai...
Definition: FalseType.h:61
Header file for the Sqrt functor.
Header file for auxiliary alias declarations.
Headerfile for the generic min algorithm.
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_USER_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERT flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:117
Generic wrapper for the cbrt() function.
Definition: Cbrt.h:80
Generic wrapper for the squared abs() function.
Definition: SqrAbs.h:84
Header file for the HasLoad type trait.
Header file for basic type definitions.
decltype(auto) l3Norm(const DenseMatrix< MT, SO > &dm)
Computes the L3 norm for the given dense matrix.
Definition: DMatNormExpr.h:574
Header file for the Pow2 functor.
decltype(auto) l2Norm(const DenseMatrix< MT, SO > &dm)
Computes the L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:548
Header file for the FalseType type/value trait base class.
decltype(auto) l4Norm(const DenseMatrix< MT, SO > &dm)
Computes the L4 norm for the given dense matrix.
Definition: DMatNormExpr.h:600
Header file for the isZero shim.
Header file for the And class template.
Header file for the DenseVector base class.
Generic wrapper for the pow() function with fixed exponent.
Definition: Forward.h:129
decltype(auto) lpNorm(const DenseMatrix< MT, SO > &dm, ST p)
Computes the Lp norm for the given dense matrix.
Definition: DMatNormExpr.h:632
Header file for the invert shim.
Generic wrapper for the qdrt() function.
Definition: Qdrt.h:81
BoolConstant< true > TrueType
Type traits base class.The TrueType class is used as base class for type traits and value traits that...
Definition: TrueType.h:61
System settings for performance optimizations.
#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
const MT::ResultType evaluate(const Matrix< MT, SO > &matrix)
Evaluates the given matrix expression.
Definition: Matrix.h:912
Header file for the Cbrt functor.
Header file for the LpNorm functor.
bool isZero(const DiagonalProxy< MT > &proxy)
Returns whether the represented element is 0.
Definition: DiagonalProxy.h:673
Generic wrapper for the abs() function.
Definition: Abs.h:82
IntegralConstant< bool, C > Bool
Compile time integral constant wrapper for bool.The Bool class template represents an integral wrappe...
Definition: Bool.h:70
Generic wrapper for the sqrt() function.
Definition: Sqrt.h:82
Header file for the multiplication trait.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
Header file for the L4Norm functor.
Header file for the If class template.
Header file for the SqrAbs functor.
Header file for the UnderlyingBuiltin type trait.
decltype(auto) l1Norm(const DenseMatrix< MT, SO > &dm)
Computes the L1 norm for the given dense matrix.
Definition: DMatNormExpr.h:522
decltype(auto) min(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise minimum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1147
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2146
Header file for the HasSIMDAdd type trait.
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:423
Header file for all SIMD functionality.
Base class for N-dimensional dense vectors.The DenseVector class is a base class for all arbitrarily ...
Definition: DenseVector.h:76
Header file for the L2Norm functor.
Implementation of a type list.The TypeList class template represents a list of data types of arbitrar...
Definition: TypeList.h:119
Generic wrapper for the null function.
Definition: Noop.h:59
decltype(auto) max(const DenseMatrix< MT1, SO1 > &lhs, const DenseMatrix< MT2, SO2 > &rhs)
Computes the componentwise maximum of the dense matrices lhs and rhs.
Definition: DMatDMatMapExpr.h:1179
Header file for the Abs functor.
Header file for the IsPadded type trait.
decltype(auto) abs(const DenseMatrix< MT, SO > &dm)
Applies the abs() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1152
decltype(auto) maxNorm(const DenseMatrix< MT, SO > &dm)
Computes the maximum norm for the given dense matrix.
Definition: DMatNormExpr.h:695
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.The MultTrait_t alias declaration provid...
Definition: MultTrait.h:240
Header file for the evaluate shim.
Header file for the IsSIMDEnabled type trait.
Generic wrapper for the pow2() function.
Definition: Pow2.h:77
Header file for run time assertion macros.
Indexing a type list.The TypeAt class can be used to access a type list at a specified position to qu...
Definition: TypeAt.h:76
Header file for the Unique class template.
Header file for the UnaryPow functor.
constexpr bool IsPadded_v
Auxiliary variable template for the IsPadded type trait.The IsPadded_v variable template provides a c...
Definition: IsPadded.h:135
#define BLAZE_FUNCTION_TRACE
Function trace macro.This macro can be used to reliably trace function calls. In case function tracin...
Definition: FunctionTrace.h:94
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530
Header file for the HasMember type traits.
Header file for the Noop functor.
Header file for the RemoveReference type trait.
decltype(auto) norm(const DenseMatrix< MT, SO > &dm)
Computes the L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:470
Generic wrapper for the pow3() function.
Definition: Pow3.h:77
Header file for the L3Norm functor.
Header file for the L1Norm functor.
Header file for the Qdrt functor.
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.In case of an invalid run time expression, the program execution is terminated. The BLAZE_INTERNAL_ASSERT macro can be disabled by setting the BLAZE_USER_ASSERTION flag to zero or by defining NDEBUG during the compilation.
Definition: Assert.h:101
Header file for the Bool class template.
Header file for the Pow3 functor.
Header file for the TrueType type/value trait base class.
Header file for the function trace functionality.