Blaze  3.6
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 
44 #include <blaze/math/simd/Prod.h>
46 #include <blaze/math/simd/Sum.h>
47 #include <blaze/math/simd/Storea.h>
49 
50 
51 namespace blaze {
52 
53 //=================================================================================================
54 //
55 // SIMD REDUCTION
56 //
57 //=================================================================================================
58 
59 //*************************************************************************************************
67 template< typename T, typename OP >
68 inline 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 //*************************************************************************************************
93 template< typename T >
94 inline decltype(auto) reduce( const SIMDPack<T>& a, const Add& /*op*/ )
95 {
96  return sum( ~a );
97 }
99 //*************************************************************************************************
100 
101 
102 //*************************************************************************************************
110 template< typename T >
111 inline 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.
decltype(auto) prod(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of multiplication.
Definition: DMatReduceExpr.h:2220
Header file for the SIMDPack base class.
Header file for the SIMD aligned store functionality.
decltype(auto) reduce(const DenseMatrix< MT, SO > &dm, OP op)
Performs a custom reduction operation on the given dense matrix.
Definition: DMatReduceExpr.h:2017
Header file for the SIMD multiplication reduction functionality.
Namespace of the Blaze C++ math library.
Definition: Blaze.h:58
decltype(auto) sum(const DenseMatrix< MT, SO > &dm)
Reduces the given dense matrix by means of addition.
Definition: DMatReduceExpr.h:2147
Header file for the SIMD addition reduction functionality.
Header file for all functor forward declarations.
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
Base class for all SIMD data types.The SIMDPack class template is a base class for all SIMD data type...
Definition: SIMDPack.h:63
constexpr size_t size(const Matrix< MT, SO > &matrix) noexcept
Returns the total number of elements of the matrix.
Definition: Matrix.h:530