35#ifndef _BLAZE_MATH_EXPRESSIONS_DMATNORMEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DMATNORMEXPR_H_
106 using ET = ElementType_t<MT>;
109 using CT = RemoveReference_t< CompositeType_t<MT> >;
113 static constexpr bool value =
114 ( useOptimizedKernels &&
116 If_t< HasSIMDEnabled_v<Abs> && HasSIMDEnabled_v<Power>
117 , And_t< GetSIMDEnabled<Abs,ET>, GetSIMDEnabled<Power,ET> >
118 , And_t< HasLoad<Abs>, HasLoad<Power> > >::value &&
119 HasSIMDAdd_v< ElementType_t<CT>, ElementType_t<CT> > );
153inline decltype(
auto) norm_backend(
const DenseMatrix<MT,false>& dm, Abs
abs, Power power, Root root,
FalseType )
155 using CT = CompositeType_t<MT>;
156 using ET = ElementType_t<MT>;
157 using PT = RemoveCVRef_t< decltype( power( abs( std::declval<ET>() ) ) ) >;
158 using RT = RemoveCVRef_t< decltype( evaluate( root( std::declval<PT>() ) ) ) >;
160 if( (*dm).rows() == 0UL || (*dm).columns() == 0UL )
return RT{};
164 const size_t M( tmp.rows() );
165 const size_t N( tmp.columns() );
167 PT
norm( power(
abs( tmp(0UL,0UL) ) ) );
172 for( ; (j+4UL) <= N; j+=4UL ) {
173 norm += power(
abs( tmp(0UL,j ) ) ) + power(
abs( tmp(0UL,j+1UL) ) ) +
174 power(
abs( tmp(0UL,j+2UL) ) ) + power(
abs( tmp(0UL,j+3UL) ) );
176 for( ; (j+2UL) <= N; j+=2UL ) {
177 norm += power(
abs( tmp(0UL,j) ) ) + power(
abs( tmp(0UL,j+1UL) ) );
180 norm += power(
abs( tmp(0UL,j) ) );
184 for(
size_t i=1UL; i<M; ++i )
188 for( ; (j+4UL) <= N; j+=4UL ) {
189 norm += power(
abs( tmp(i,j ) ) ) + power(
abs( tmp(i,j+1UL) ) ) +
190 power(
abs( tmp(i,j+2UL) ) ) + power(
abs( tmp(i,j+3UL) ) );
192 for( ; (j+2UL) <= N; j+=2UL ) {
193 norm += power(
abs( tmp(i,j) ) ) + power(
abs( tmp(i,j+1UL) ) );
196 norm += power(
abs( tmp(i,j) ) );
225inline decltype(
auto) norm_backend(
const DenseMatrix<MT,true>& dm, Abs
abs, Power power, Root root,
FalseType )
227 using CT = CompositeType_t<MT>;
228 using ET = ElementType_t<MT>;
229 using PT = RemoveCVRef_t< decltype( power( abs( std::declval<ET>() ) ) ) >;
230 using RT = RemoveCVRef_t< decltype( evaluate( root( std::declval<PT>() ) ) ) >;
232 if( (*dm).rows() == 0UL || (*dm).columns() == 0UL )
return RT{};
236 const size_t M( tmp.rows() );
237 const size_t N( tmp.columns() );
239 PT
norm( power(
abs( tmp(0UL,0UL) ) ) );
244 for( ; (i+4UL) <= M; i+=4UL ) {
245 norm += power(
abs( tmp(i ,0UL) ) ) + power(
abs( tmp(i+1UL,0UL) ) ) +
246 power(
abs( tmp(i+2UL,0UL) ) ) + power(
abs( tmp(i+3UL,0UL) ) );
248 for( ; (i+2UL) <= M; i+=2UL ) {
249 norm += power(
abs( tmp(i,0UL) ) ) + power(
abs( tmp(i+1UL,0UL) ) );
252 norm += power(
abs( tmp(i,0UL) ) );
256 for(
size_t j=1UL; j<N; ++j )
260 for( ; (i+4UL) <= M; i+=4UL ) {
261 norm += power(
abs( tmp(i ,j) ) ) + power(
abs( tmp(i+1UL,j) ) ) +
262 power(
abs( tmp(i+2UL,j) ) ) + power(
abs( tmp(i+3UL,j) ) );
264 for( ; (i+2UL) <= M; i+=2UL ) {
265 norm += power(
abs( tmp(i,j) ) ) + power(
abs( tmp(i+1UL,j) ) );
268 norm += power(
abs( tmp(i,j) ) );
297inline decltype(
auto) norm_backend(
const DenseMatrix<MT,false>& dm, Abs
abs, Power power, Root root,
TrueType )
299 using CT = CompositeType_t<MT>;
300 using ET = ElementType_t<MT>;
301 using RT =
decltype(
evaluate( root( std::declval<ET>() ) ) );
305 if( (*dm).rows() == 0UL || (*dm).columns() == 0UL )
return RT{};
309 const size_t M( tmp.rows() );
310 const size_t N( tmp.columns() );
312 constexpr bool remainder( !
IsPadded_v< RemoveReference_t<CT> > );
316 if( !remainder || N >= SIMDSIZE )
318 const size_t jpos( remainder ?
prevMultiple( N, SIMDSIZE ) : N );
321 SIMDTrait_t<ET> xmm1{};
324 for( ; (i+4UL) <= M; i+=4UL )
326 xmm1 += power(
abs( tmp.load(i,0UL) ) );
327 SIMDTrait_t<ET> xmm2( power(
abs( tmp.load(i+1UL,0UL) ) ) );
328 SIMDTrait_t<ET> xmm3( power(
abs( tmp.load(i+2UL,0UL) ) ) );
329 SIMDTrait_t<ET> xmm4( power(
abs( tmp.load(i+3UL,0UL) ) ) );
330 size_t j( SIMDSIZE );
332 for( ; j<jpos; j+=SIMDSIZE ) {
333 xmm1 += power(
abs( tmp.load(i ,j) ) );
334 xmm2 += power(
abs( tmp.load(i+1UL,j) ) );
335 xmm3 += power(
abs( tmp.load(i+2UL,j) ) );
336 xmm4 += power(
abs( tmp.load(i+3UL,j) ) );
338 for( ; remainder && j<N; ++j ) {
339 norm += power(
abs( tmp(i ,j) ) );
340 norm += power(
abs( tmp(i+1UL,j) ) );
341 norm += power(
abs( tmp(i+2UL,j) ) );
342 norm += power(
abs( tmp(i+3UL,j) ) );
352 xmm1 += power(
abs( tmp.load(i,0UL) ) );
353 SIMDTrait_t<ET> xmm2( power(
abs( tmp.load(i+1UL,0UL) ) ) );
354 size_t j( SIMDSIZE );
356 for( ; j<jpos; j+=SIMDSIZE ) {
357 xmm1 += power(
abs( tmp.load(i ,j) ) );
358 xmm2 += power(
abs( tmp.load(i+1UL,j) ) );
360 for( ; remainder && j<N; ++j ) {
361 norm += power(
abs( tmp(i ,j) ) );
362 norm += power(
abs( tmp(i+1UL,j) ) );
372 xmm1 += power(
abs( tmp.load(i,0UL) ) );
373 size_t j( SIMDSIZE );
375 for( ; j<jpos; j+=SIMDSIZE ) {
376 xmm1 += power(
abs( tmp.load(i,j) ) );
378 for( ; remainder && j<N; ++j ) {
379 norm += power(
abs( tmp(i,j) ) );
387 for(
size_t i=0UL; i<M; ++i ) {
388 for(
size_t j=0UL; j<N; ++j ) {
389 norm += power(
abs( tmp(i,j) ) );
419inline decltype(
auto) norm_backend(
const DenseMatrix<MT,true>& dm, Abs
abs, Power power, Root root,
TrueType )
421 using CT = CompositeType_t<MT>;
422 using ET = ElementType_t<MT>;
423 using RT =
decltype(
evaluate( root( std::declval<ET>() ) ) );
427 if( (*dm).rows() == 0UL || (*dm).columns() == 0UL )
return RT{};
431 const size_t M( tmp.rows() );
432 const size_t N( tmp.columns() );
434 constexpr bool remainder( !
IsPadded_v< RemoveReference_t<CT> > );
438 if( !remainder || N >= SIMDSIZE )
440 const size_t ipos( remainder ?
prevMultiple( M, SIMDSIZE ) :M );
443 SIMDTrait_t<ET> xmm1{};
446 for( ; (j+4UL) <= N; j+=4UL )
448 xmm1 += power(
abs( tmp.load(0UL,j) ) );
449 SIMDTrait_t<ET> xmm2( power(
abs( tmp.load(0UL,j+1UL) ) ) );
450 SIMDTrait_t<ET> xmm3( power(
abs( tmp.load(0UL,j+2UL) ) ) );
451 SIMDTrait_t<ET> xmm4( power(
abs( tmp.load(0UL,j+3UL) ) ) );
452 size_t i( SIMDSIZE );
454 for( ; i<ipos; i+=SIMDSIZE ) {
455 xmm1 += power(
abs( tmp.load(i,j ) ) );
456 xmm2 += power(
abs( tmp.load(i,j+1UL) ) );
457 xmm3 += power(
abs( tmp.load(i,j+2UL) ) );
458 xmm4 += power(
abs( tmp.load(i,j+3UL) ) );
460 for( ; remainder && i<M; ++i ) {
461 norm += power(
abs( tmp(i,j ) ) );
462 norm += power(
abs( tmp(i,j+1UL) ) );
463 norm += power(
abs( tmp(i,j+2UL) ) );
464 norm += power(
abs( tmp(i,j+3UL) ) );
474 xmm1 += power(
abs( tmp.load(0UL,j) ) );
475 SIMDTrait_t<ET> xmm2( power(
abs( tmp.load(0UL,j+1UL) ) ) );
476 size_t i( SIMDSIZE );
478 for( ; i<ipos; i+=SIMDSIZE ) {
479 xmm1 += power(
abs( tmp.load(i,j ) ) );
480 xmm2 += power(
abs( tmp.load(i,j+1UL) ) );
482 for( ; remainder && i<M; ++i ) {
483 norm += power(
abs( tmp(i,j ) ) );
484 norm += power(
abs( tmp(i,j+1UL) ) );
494 xmm1 += power(
abs( tmp.load(0UL,j) ) );
495 size_t i( SIMDSIZE );
497 for( ; i<ipos; i+=SIMDSIZE ) {
498 xmm1 += power(
abs( tmp.load(i,j) ) );
500 for( ; remainder && i<M; ++i ) {
501 norm += power(
abs( tmp(i,j) ) );
509 for(
size_t j=0UL; j<N; ++j ) {
510 for(
size_t i=0UL; i<M; ++i ) {
511 norm += power(
abs( tmp(i,j) ) );
548decltype(
auto) norm_backend(
const DenseMatrix<MT,SO>& dm, Abs
abs, Power power, Root root )
550 return norm_backend( *dm,
abs, power, root,
Bool_t< DMatNormHelper<MT,Abs,Power>::value >() );
743 return norm_backend( *dm,
Abs(), UnaryPow(
Pow(), p ), UnaryPow(
Pow(),
inv( p ) ) );
775 using Norm =
typename TypeAt< Norms,
min( P-1UL, 4UL ) >::Type;
777 return Norm()( *dm );
Header file for auxiliary alias declarations.
Header file for run time assertion macros.
Header file for the Bind2nd functor.
Header file for the evaluate shim.
Header file for the function trace functionality.
Header file for the HasLoad type trait.
Header file for the HasMember type traits.
Header file for the HasSIMDAdd type trait.
Header file for the If class template.
Header file for the IntegralConstant class template.
Header file for the invert shim.
Header file for the IsPadded type trait.
Header file for the IsSIMDEnabled type trait.
Header file for the L1Norm functor.
Header file for the L2Norm functor.
Header file for the L3Norm functor.
Header file for the L4Norm functor.
Header file for the LpNorm functor.
Header file for the multiplication trait.
Header file for the Noop functor.
Header file for the prevMultiple shim.
Header file for the RemoveCVRef type trait.
Header file for the RemoveReference type trait.
Header file for all SIMD functionality.
Header file for the SqrAbs functor.
Header file for the type list functionality.
Header file for the UnderlyingBuiltin type trait.
Base class for dense matrices.
Definition: DenseMatrix.h:82
Header file for the DenseMatrix base class.
Header file for the Abs functor.
Header file for the Cbrt functor.
Header file for the Pow2 functor.
Header file for the Pow3 functor.
Header file for the Pow functor.
Header file for the Qdrt functor.
Header file for the Sqrt functor.
decltype(auto) l4Norm(const DenseMatrix< MT, SO > &dm)
Computes the L4 norm for the given dense matrix.
Definition: DMatNormExpr.h:703
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:1339
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:1375
decltype(auto) l2Norm(const DenseMatrix< MT, SO > &dm)
Computes the L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:651
decltype(auto) sqrNorm(const DenseMatrix< MT, SO > &dm)
Computes the squared L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:599
decltype(auto) linfNorm(const DenseMatrix< MT, SO > &dm)
Computes the infinity norm for the given dense matrix.
Definition: DMatNormExpr.h:799
decltype(auto) maxNorm(const DenseMatrix< MT, SO > &dm)
Computes the maximum norm for the given dense matrix.
Definition: DMatNormExpr.h:825
decltype(auto) abs(const DenseMatrix< MT, SO > &dm)
Applies the abs() function to each single element of the dense matrix dm.
Definition: DMatMapExpr.h:1296
decltype(auto) norm(const DenseMatrix< MT, SO > &dm)
Computes the L2 norm for the given dense matrix.
Definition: DMatNormExpr.h:573
decltype(auto) minNorm(const DenseMatrix< MT, SO > &dm)
Computes the minimum norm for the given dense matrix.
Definition: DMatNormExpr.h:851
decltype(auto) lpNorm(const DenseMatrix< MT, SO > &dm)
Computes the Lp norm for the given dense matrix.
Definition: DMatNormExpr.h:770
decltype(auto) inv(const DenseMatrix< MT, SO > &dm)
Calculation of the inverse of the given dense matrix.
Definition: DMatInvExpr.h:405
bool isZero(const DenseMatrix< MT, SO > &dm)
Checks if the given dense matrix is a zero matrix.
Definition: DenseMatrix.h:1819
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2156
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
typename MultTrait< T1, T2 >::Type MultTrait_t
Auxiliary alias declaration for the MultTrait class template.
Definition: MultTrait.h:165
constexpr bool IsPadded_v
Auxiliary variable template for the IsPadded type trait.
Definition: IsPadded.h:134
BLAZE_ALWAYS_INLINE constexpr auto prevMultiple(T1 value, T2 factor) noexcept
Rounds down an integral value to the previous multiple of a given factor.
Definition: PrevMultiple.h:68
MT::ResultType evaluate(const Matrix< MT, SO > &matrix)
Evaluates the given matrix expression.
Definition: Matrix.h:1282
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:676
#define BLAZE_INTERNAL_ASSERT(expr, msg)
Run time assertion macro for internal checks.
Definition: Assert.h:101
#define BLAZE_USER_ASSERT(expr, msg)
Run time assertion macro for user checks.
Definition: Assert.h:117
#define BLAZE_STATIC_ASSERT_MSG(expr, msg)
Compile time assertion macro.
Definition: StaticAssert.h:123
BoolConstant< true > TrueType
Type traits base class.
Definition: IntegralConstant.h:132
BoolConstant< false > FalseType
Type/value traits base class.
Definition: IntegralConstant.h:121
#define BLAZE_FUNCTION_TRACE
Function trace macro.
Definition: FunctionTrace.h:94
IntegralConstant< bool, B > Bool_t
Compile time integral constant wrapper for bool.
Definition: IntegralConstant.h:153
Header file for the isZero shim.
Generic wrapper for the abs() function.
Definition: Abs.h:85
Generic wrapper for an operation with fixed 2nd argument.
Definition: Bind2nd.h:66
Generic wrapper for the cbrt() function.
Definition: Cbrt.h:83
Generic wrapper for the null function.
Definition: Noop.h:62
Generic wrapper for the pow2() function.
Definition: Pow2.h:80
Generic wrapper for the pow3() function.
Definition: Pow3.h:80
Generic wrapper for the pow() function.
Definition: Pow.h:65
Generic wrapper for the qdrt() function.
Definition: Qdrt.h:84
Generic wrapper for the squared abs() function.
Definition: SqrAbs.h:86
Generic wrapper for the sqrt() function.
Definition: Sqrt.h:85
Indexing a type list.
Definition: TypeAt.h:75
Implementation of a type list.
Definition: TypeList.h:120
System settings for performance optimizations.
Header file for basic type definitions.
Header file for the And_t alias template.