23namespace vctr::expressions
26template <
size_t extent,
class SrcType>
27requires is::number<ValueType<SrcType>>
33 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (
Mean, src)
35 static constexpr value_type reductionResultInitValue = 0;
37 VCTR_FORCEDINLINE
constexpr void reduceElementWise (value_type& result,
size_t i)
const
43 VCTR_FORCEDINLINE value_type reduceVectorOp()
const
46 return Expression::Accelerate::mean (src.data(), size());
49 VCTR_FORCEDINLINE value_type reduceVectorOp()
const
52 return Expression::IPP::mean (src.data(),
sizeToInt (size()));
59 result = Expression::Neon::add (result, src.getNeon (i));
62 VCTR_FORCEDINLINE VCTR_TARGET (
"avx")
void reduceAVXRegisterWise (
AVXRegister<value_type>& result,
size_t i)
const
65 result = Expression::AVX::add (result, src.getAVX (i));
68 VCTR_FORCEDINLINE VCTR_TARGET (
"avx2")
void reduceAVXRegisterWise (
AVXRegister<value_type>& result,
size_t i)
const
71 result = Expression::AVX::add (result, src.getAVX (i));
74 VCTR_FORCEDINLINE VCTR_TARGET (
"sse4.1")
void reduceSSERegisterWise (
SSERegister<value_type>& result,
size_t i)
const
77 result = Expression::SSE::add (result, src.getSSE (i));
82 VCTR_FORCEDINLINE
constexpr value_type finalizeReduction (
const std::array<value_type, n>& sums)
const
84 auto sum = n == 1 ? sums[0] : std::reduce (sums.begin(), sums.end());
90template <
size_t extent,
class SrcType>
97 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (
MeanSquare, src)
99 static constexpr value_type reductionResultInitValue = 0;
101 VCTR_FORCEDINLINE
constexpr void reduceElementWise (value_type& result,
size_t i)
const
108 VCTR_FORCEDINLINE value_type reduceVectorOp()
const
111 return Expression::Accelerate::meanSquare (src.data(), size());
114 VCTR_FORCEDINLINE value_type reduceVectorOp()
const
117 auto l2Norm = Expression::IPP::l2Norm (src.data(),
sizeToInt (size()));
118 return (l2Norm * l2Norm) / value_type (size());
125 auto s = src.getNeon (i);
126 s = Expression::Neon::mul (s, s);
127 result = Expression::Neon::add (result, s);
130 VCTR_FORCEDINLINE VCTR_TARGET (
"avx")
void reduceAVXRegisterWise (
AVXRegister<value_type>& result,
size_t i)
const
133 auto s = src.getAVX (i);
134 s = Expression::AVX::mul (s, s);
135 result = Expression::AVX::add (result, s);
138 VCTR_FORCEDINLINE VCTR_TARGET (
"sse4.1")
void reduceSSERegisterWise (
SSERegister<value_type>& result,
size_t i)
const
141 auto s = src.getSSE (i);
142 s = Expression::SSE::mul (s, s);
143 result = Expression::SSE::add (result, s);
148 VCTR_FORCEDINLINE
constexpr value_type finalizeReduction (
const std::array<value_type, n>& sums)
const
150 auto sum = n == 1 ? sums[0] : std::reduce (sums.begin(), sums.end());
156template <
size_t extent,
class SrcType>
165 static constexpr value_type reductionResultInitValue = 0;
167 VCTR_FORCEDINLINE
constexpr void reduceElementWise (value_type& result,
size_t i)
const
174 VCTR_FORCEDINLINE value_type reduceVectorOp()
const
177 return Expression::Accelerate::rms (src.data(), size());
180 VCTR_FORCEDINLINE value_type reduceVectorOp()
const
183 auto l2Norm = Expression::IPP::l2Norm (src.data(),
sizeToInt (size()));
184 return std::sqrt ((l2Norm * l2Norm) / value_type (size()));
191 auto s = src.getNeon (i);
192 s = Expression::Neon::mul (s, s);
193 result = Expression::Neon::add (result, s);
196 VCTR_FORCEDINLINE VCTR_TARGET (
"avx")
void reduceAVXRegisterWise (
AVXRegister<value_type>& result,
size_t i)
const
199 auto s = src.getAVX (i);
200 s = Expression::AVX::mul (s, s);
201 result = Expression::AVX::add (result, s);
204 VCTR_FORCEDINLINE VCTR_TARGET (
"sse4.1")
void reduceSSERegisterWise (
SSERegister<value_type>& result,
size_t i)
const
207 auto s = src.getSSE (i);
208 s = Expression::SSE::mul (s, s);
209 result = Expression::SSE::add (result, s);
214 VCTR_FORCEDINLINE
constexpr value_type finalizeReduction (
const std::array<value_type, n>& squaredSums)
const
216 auto squaredSum = n == 1 ? squaredSums[0] : std::reduce (squaredSums.begin(), squaredSums.end());
222 if (std::is_constant_evaluated())
224 return value_type (gcem::sqrt (meanSquaredSum));
229 return value_type (std::sqrt (meanSquaredSum));
Constrains a type to have a member function getAVX (size_t) const.
Definition: ContainerAndExpressionConcepts.h:78
Constrains a type to have a member function getNeon (size_t) const.
Definition: ContainerAndExpressionConcepts.h:74
Constrains a type to have a member function getSSE (size_t) const.
Definition: ContainerAndExpressionConcepts.h:82
Constrains a type to represent a real valued 32 bit integer number.
Definition: NumericTypeConcepts.h:53
Constrains a type to represent a real valued or std::complex number type.
Definition: NumericTypeConcepts.h:45
Constrains a type to represent a real valued floating point number.
Definition: NumericTypeConcepts.h:79
Constrains a type to represent a real or complex valued floating point number.
Definition: NumericTypeConcepts.h:87
A combined concept to check if Apple Accelerate is a suitable option for a floating point vector redu...
Definition: ContainerAndExpressionConcepts.h:262
A combined concept to check if Intel IPP is a suitable option for a floating point vector reduction o...
Definition: ContainerAndExpressionConcepts.h:286
A combined concept to check if Intel IPP is a suitable option for a real or complex floating point ve...
Definition: ContainerAndExpressionConcepts.h:290
constexpr ExpressionChainBuilder< expressions::RootMeanSquare > rms
Computes the square root of the mean value of the squared source values.
Definition: Mean.h:254
constexpr ExpressionChainBuilder< expressions::Mean > mean
Computes the mean value of the source values.
Definition: Mean.h:242
constexpr ExpressionChainBuilder< expressions::Sum > sum
Computes the sum of the source values.
Definition: Sum.h:116
constexpr ExpressionChainBuilder< expressions::MeanSquare > meanSquare
Computes the mean value of the squared source values.
Definition: Mean.h:248
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::ValueType< std::remove_cvref_t< T > >::Type ValueType
If T is an expression template, it equals its return type, if it's a type that defines value_type as ...
Definition: Traits.h:201
typename detail::FloatType< std::remove_cvref_t< T > >::Type FloatType
The best matching float type for the real number type T.
Definition: Traits.h:219
typename detail::RealType< std::remove_cvref_t< T > >::Type RealType
If T is any instance of std::complex, this will be the real value_type, otherwise this will be T.
Definition: Traits.h:211
int sizeToInt(size_t size)
Casts the size_t argument to an int.
Definition: PlatformVectorOpsHelpers.h:27
Definition: AVXRegister.h:28
An expression chain builder is an object which supplies various operator<< overloads which build chai...
Definition: ExpressionChainBuilder.h:136
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: NeonRegister.h:28
Definition: SSERegister.h:28