Blaze 3.9
Loading...
Searching...
No Matches
Reduce.h
Go to the documentation of this file.
1//=================================================================================================
33//=================================================================================================
34
35#ifndef _BLAZE_MATH_SIMD_REDUCE_H_
36#define _BLAZE_MATH_SIMD_REDUCE_H_
37
38
39//*************************************************************************************************
40// Includes
41//*************************************************************************************************
42
46#include <blaze/math/simd/Sum.h>
49
50
51namespace blaze {
52
53//=================================================================================================
54//
55// SIMD REDUCTION
56//
57//=================================================================================================
58
59//*************************************************************************************************
67template< typename T, typename OP >
68inline decltype(auto) reduce( const SIMDPack<T>& a, OP op )
69{
70 using ValueType = typename T::ValueType;
71
72 alignas( AlignmentOf_v<ValueType> ) ValueType array[T::size];
73 storea( array, *a );
74
75 ValueType redux( array[0UL] );
76 for( size_t k=1UL; k<T::size; ++k ) {
77 redux = op( redux, array[k] );
78 }
79
80 return redux;
81}
82//*************************************************************************************************
83
84
85//*************************************************************************************************
93template< typename T >
94inline decltype(auto) reduce( const SIMDPack<T>& a, const Add& /*op*/ )
95{
96 return sum( *a );
97}
99//*************************************************************************************************
100
101
102//*************************************************************************************************
110template< typename T >
111inline decltype(auto) reduce( const SIMDPack<T>& a, const Mult& /*op*/ )
112{
113 return prod( *a );
114}
116//*************************************************************************************************
117
118} // namespace blaze
119
120#endif
Header file for the AlignmentOf type trait.
Header file for the SIMD multiplication reduction functionality.
Header file for the SIMD aligned store functionality.
Header file for the SIMD addition reduction functionality.
Base class for all SIMD data types.
Definition SIMDPack.h:64
decltype(auto) prod(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of multiplication.
Definition DMatReduceExpr.h:2229
decltype(auto) reduce(const DenseMatrix< MT, SO > &dm, OP op)
Performs a custom reduction operation on the given dense matrix.
Definition DMatReduceExpr.h:2025
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition DMatReduceExpr.h:2156
BLAZE_ALWAYS_INLINE EnableIf_t< IsIntegral_v< T1 > &&HasSize_v< T1, 1UL > > storea(T1 *address, const SIMDi8< T2 > &value) noexcept
Aligned store of a vector of 1-byte integral values.
Definition Storea.h:78
constexpr size_t AlignmentOf_v
Auxiliary variable template for the AlignmentOf type trait.
Definition AlignmentOf.h:239
Header file for all functor forward declarations.
Header file for the SIMDPack base class.
Generic wrapper for the multiplication operator.
Definition Mult.h:82