35#ifndef _BLAZE_MATH_EXPRESSIONS_DVECNORMEXPR_H_
36#define _BLAZE_MATH_EXPRESSIONS_DVECNORMEXPR_H_
107 using ET = ElementType_t<VT>;
110 using CT = RemoveReference_t< CompositeType_t<VT> >;
114 static constexpr bool value =
115 ( useOptimizedKernels &&
117 If_t< HasSIMDEnabled_v<Abs> && HasSIMDEnabled_v<Power>
118 , And_t< GetSIMDEnabled<Abs,ET>, GetSIMDEnabled<Power,ET> >
119 , And_t< HasLoad<Abs>, HasLoad<Power> > >::value &&
120 HasSIMDAdd_v< ElementType_t<CT>, ElementType_t<CT> > );
155inline decltype(
auto) norm_backend(
const DenseVector<VT,TF>& dv, Abs
abs, Power power, Root root,
FalseType )
157 using CT = CompositeType_t<VT>;
158 using ET = ElementType_t<VT>;
159 using PT = RemoveCVRef_t< decltype( power( abs( std::declval<ET>() ) ) ) >;
160 using RT = RemoveCVRef_t< decltype( evaluate( root( std::declval<PT>() ) ) ) >;
162 if( (*dv).size() == 0UL )
return RT{};
166 const size_t N( tmp.size() );
168 PT
norm( power(
abs( tmp[0UL] ) ) );
171 for( ; (i+4UL) <= N; i+=4UL ) {
172 norm += power(
abs( tmp[i ] ) ) + power(
abs( tmp[i+1UL] ) ) +
173 power(
abs( tmp[i+2UL] ) ) + power(
abs( tmp[i+3UL] ) );
175 for( ; (i+2UL) <= N; i+=2UL ) {
176 norm += power(
abs( tmp[i] ) ) + power(
abs( tmp[i+1UL] ) );
179 norm += power(
abs( tmp[i] ) );
208inline decltype(
auto) norm_backend(
const DenseVector<VT,TF>& dv, Abs
abs, Power power, Root root,
TrueType )
210 using CT = CompositeType_t<VT>;
211 using ET = ElementType_t<VT>;
212 using RT =
decltype(
evaluate( root( std::declval<ET>() ) ) );
216 if( (*dv).size() == 0UL )
return RT{};
220 const size_t N( tmp.size() );
222 constexpr bool remainder( !
IsPadded_v< RemoveReference_t<VT> > );
224 const size_t ipos( remainder ?
prevMultiple( N, SIMDSIZE ) : N );
230 if( SIMDSIZE*3UL < ipos )
232 SIMDTrait_t<ET> xmm1{}, xmm2{}, xmm3{}, xmm4{};
234 for( ; (i+SIMDSIZE*3UL) < ipos; i+=SIMDSIZE*4UL ) {
235 xmm1 += power(
abs( tmp.load(i ) ) );
236 xmm2 += power(
abs( tmp.load(i+SIMDSIZE ) ) );
237 xmm3 += power(
abs( tmp.load(i+SIMDSIZE*2UL) ) );
238 xmm4 += power(
abs( tmp.load(i+SIMDSIZE*3UL) ) );
240 for( ; (i+SIMDSIZE) < ipos; i+=SIMDSIZE*2UL ) {
241 xmm1 += power(
abs( tmp.load(i ) ) );
242 xmm2 += power(
abs( tmp.load(i+SIMDSIZE) ) );
244 for( ; i<ipos; i+=SIMDSIZE ) {
245 xmm1 += power(
abs( tmp.load(i) ) );
248 norm =
sum( xmm1 + xmm2 + xmm3 + xmm4 );
250 else if( SIMDSIZE < ipos )
252 SIMDTrait_t<ET> xmm1{}, xmm2{};
254 for( ; (i+SIMDSIZE) < ipos; i+=SIMDSIZE*2UL ) {
255 xmm1 += power(
abs( tmp.load(i ) ) );
256 xmm2 += power(
abs( tmp.load(i+SIMDSIZE) ) );
258 for( ; i<ipos; i+=SIMDSIZE ) {
259 xmm1 += power(
abs( tmp.load(i) ) );
266 SIMDTrait_t<ET> xmm1{};
268 for( ; i<ipos; i+=SIMDSIZE ) {
269 xmm1 += power(
abs( tmp.load(i) ) );
275 for( ; remainder && i<N; ++i ) {
276 norm += power(
abs( tmp[i] ) );
311inline decltype(
auto) norm_backend(
const DenseVector<VT,TF>& dv, Abs
abs, Power power, Root root )
313 return norm_backend( *dv,
abs, power, root,
Bool_t< DVecNormHelper<VT,Abs,Power>::value >() );
506 return norm_backend( *dv,
Abs(), UnaryPow(
Pow(), p ), UnaryPow(
Pow(),
inv( p ) ) );
538 using Norm =
typename TypeAt< Norms,
min( P-1UL, 4UL ) >::Type;
540 return Norm()( *dv );
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 N-dimensional dense vectors.
Definition: DenseVector.h:77
Header file for the DenseVector 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) 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) 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) 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) lpNorm(const DenseVector< VT, TF > &dv)
Computes the Lp norm for the given dense vector.
Definition: DVecNormExpr.h:533
decltype(auto) l4Norm(const DenseVector< VT, TF > &dv)
Computes the L4 norm for the given dense vector.
Definition: DVecNormExpr.h:466
decltype(auto) norm(const DenseVector< VT, TF > &dv)
Computes the L2 norm for the given dense vector.
Definition: DVecNormExpr.h:336
decltype(auto) minNorm(const DenseVector< VT, TF > &dv)
Computes the minimum norm for the given dense vector.
Definition: DVecNormExpr.h:614
decltype(auto) l1Norm(const DenseVector< VT, TF > &dv)
Computes the L1 norm for the given dense vector.
Definition: DVecNormExpr.h:388
decltype(auto) length(const DenseVector< VT, TF > &dv)
Calculation of the length (magnitude) of the dense vector .
Definition: DVecNormExpr.h:654
decltype(auto) sqrNorm(const DenseVector< VT, TF > &dv)
Computes the squared L2 norm for the given dense vector.
Definition: DVecNormExpr.h:362
decltype(auto) l3Norm(const DenseVector< VT, TF > &dv)
Computes the L3 norm for the given dense vector.
Definition: DVecNormExpr.h:440
decltype(auto) maxNorm(const DenseVector< VT, TF > &dv)
Computes the maximum norm for the given dense vector.
Definition: DVecNormExpr.h:588
decltype(auto) sqrLength(const DenseVector< VT, TF > &dv)
Calculation of the square length (magnitude) of the dense vector .
Definition: DVecNormExpr.h:635
decltype(auto) l2Norm(const DenseVector< VT, TF > &dv)
Computes the L2 norm for the given dense vector.
Definition: DVecNormExpr.h:414
decltype(auto) linfNorm(const DenseVector< VT, TF > &dv)
Computes the infinity norm for the given dense vector.
Definition: DVecNormExpr.h:562
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 generic min algorithm.
Header file for the And_t alias template.