VCTR
Loading...
Searching...
No Matches
Pow.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::expressions
24{
25
26template <size_t extent, class SrcAType, class SrcBType>
28{
29public:
30 using CommonType = std::common_type_t<ValueType<SrcAType>, ValueType<SrcBType>>;
31 using value_type = std::conditional_t<std::integral<CommonType>, double, CommonType>;
32
33 VCTR_COMMON_BINARY_VEC_VEC_EXPRESSION_MEMBERS (PowVectors, srcBase, srcExp)
34
35 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
36 {
37#if VCTR_USE_GCEM
39 {
40 if (std::is_constant_evaluated())
41 return value_type (gcem::pow (srcBase[i], srcExp[i]));
42 }
43#endif
44
45 return value_type (std::pow (srcBase[i], srcExp[i]));
46 }
47
48 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
50 {
51 Expression::Accelerate::pow (srcBase.evalNextVectorOpInExpressionChain (dst), srcExp.evalNextVectorOpInExpressionChain (dst), dst, sizeToInt (size()));
52 return dst;
53 }
54
55 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
57 {
58 Expression::IPP::pow (srcBase.evalNextVectorOpInExpressionChain (dst), srcExp.evalNextVectorOpInExpressionChain (dst), dst, sizeToInt (size()));
59 return dst;
60 }
61
62 //==============================================================================
63 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_BINARY_EXPRESSION_MEMBER_FUNCTIONS (srcBase, srcExp)
64
65 // Apple specific SIMD Implementation
66 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
68 {
69 return { vpowf (srcBase.getSSE (i).value, srcExp.getSSE (i).value) };
70 }
71
72 NeonRegister<value_type> getNeon (size_t i) const
74 {
75 return { vpowf (srcBase.getNeon (i).value, srcExp.getNeon (i).value) };
76 }
77};
78
79template <size_t extent, class SrcType>
81{
82public:
83 using value_type = std::conditional_t<std::is_integral_v<ValueType<SrcType>>, double, ValueType<SrcType>>;
84
85 VCTR_COMMON_BINARY_SINGLE_VEC_EXPRESSION_MEMBERS (PowSingleExponent, base, exp)
86
87 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
88 {
89#if VCTR_USE_GCEM
91 {
92 if (std::is_constant_evaluated())
93 return value_type (gcem::pow (base[i], exp));
94 }
95#endif
96
97 return value_type (std::pow (base[i], exp));
98 }
99
100 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
102 {
103 Expression::IPP::pow (base.evalNextVectorOpInExpressionChain (dst), exp, dst, sizeToInt (size()));
104 return dst;
105 }
106};
107
108template <size_t extent, class SrcType>
110{
111public:
112 using value_type = std::conditional_t<std::is_integral_v<ValueType<SrcType>>, double, ValueType<SrcType>>;
113
114 VCTR_COMMON_BINARY_SINGLE_VEC_EXPRESSION_MEMBERS (PowSingleBase, exp, base)
115
116 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
117 {
118#if VCTR_USE_GCEM
120 {
121 if (std::is_constant_evaluated())
122 return value_type (gcem::pow (base, exp[i]));
123 }
124#endif
125
126 return value_type (std::pow (base, exp[i]));
127 }
128};
129
130template <size_t extent, class SrcType, is::constant ConstantType>
132{
133public:
134 using value_type = std::conditional_t<std::is_integral_v<ValueType<SrcType>>, double, ValueType<SrcType>>;
135
136 static constexpr value_type exp = ConstantType::value;
137
138 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (PowConstantExponent, src)
139
140 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
141 {
142#if VCTR_USE_GCEM
144 {
145 if (std::is_constant_evaluated())
146 return value_type (gcem::pow (src[i], exp));
147 }
148#endif
149
150 return value_type (std::pow (src[i], exp));
151 }
152
153 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
155 {
156 Expression::IPP::pow (src.evalNextVectorOpInExpressionChain (dst), exp, dst, sizeToInt (size()));
157 return dst;
158 }
159};
160
161template <size_t extent, class SrcType, is::constant ConstantType>
163{
164public:
165 using value_type = std::conditional_t<std::is_integral_v<ValueType<SrcType>>, double, ValueType<SrcType>>;
166
167 static constexpr value_type base = ConstantType::value;
168
169 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (PowConstantBase, src)
170
171 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
172 {
173#if VCTR_USE_GCEM
175 {
176 if (std::is_constant_evaluated())
177 return value_type (gcem::pow (base, src[i]));
178 }
179#endif
180
181 return value_type (std::pow (base, src[i]));
182 }
183
184 //==============================================================================
185 // Platform Vector Operation Implementation
186 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
189 {
190 // Todo: Quick workaround to use this in the context of chained accelerated operations.
191 // This is useful to speed up decibel calculation. We should optimise it – maybe based
192 // on chaining e.g. exp2 (log2 (base) * src)
193 const auto s = size();
194 const auto* x = src.evalNextVectorOpInExpressionChain (dst);
195
196 for (size_t i = 0; i < s; ++i)
197 dst[i] = std::pow (base, x[i]);
198
199 return dst;
200 }
201};
202
203} // namespace vctr::expressions
204
205namespace vctr
206{
207
212 template <is::anyVctrOrExpression SrcBaseType, is::anyVctrOrExpression SrcExpType>
213 constexpr auto pow (SrcBaseType&& bases, SrcExpType&& exponents)
214{
215 assertCommonSize (bases, exponents);
216 constexpr auto extent = getCommonExtent<SrcBaseType, SrcExpType>();
217
218 return expressions::PowVectors<extent, SrcBaseType, SrcExpType> (std::forward<SrcBaseType> (bases), std::forward<SrcExpType> (exponents));
219}
220
225template <is::anyVctrOrExpression Src>
226constexpr auto pow (typename std::remove_cvref_t<Src>::value_type base, Src&& exponents)
227{
228 return expressions::PowSingleBase<extentOf<Src>, Src> (base, exponents);
229}
230
241template <is::anyVctrOrExpression Src>
242constexpr auto pow (Src&& bases, typename std::remove_cvref_t<Src>::value_type exponent)
243{
244 return expressions::PowSingleExponent<extentOf<Src>, Src> (exponent, bases);
245}
246
251template <auto base>
253
258template <auto exponent>
260
261} // namespace vctr
Definition: Pow.h:28
Constrains a type to represent a complex valued floating point number (e.g.
Definition: NumericTypeConcepts.h:87
A combined concept to check if Apple Accelerate vpf functions are suitable to work on Neon registers.
Definition: ContainerAndExpressionConcepts.h:256
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:321
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:260
A combined concept to check if Apple Accelerate vpf functions are suitable to work on SSE registers.
Definition: ContainerAndExpressionConcepts.h:252
A combined concept to check if Intel IPP is a suitable option for a real valued floating point vector...
Definition: ContainerAndExpressionConcepts.h:284
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:342
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:296
constexpr ExpressionChainBuilder< expressions::Exp > exp
Computes e (Euler's number, 2.7182818...) raised to the source vector elements power.
Definition: Exp.h:84
constexpr ExpressionChainBuilder< expressions::PowConstantBase, Constant< base > > powConstantBase
Evaluates base raised to the power of the source elements.
Definition: Pow.h:252
constexpr auto pow(SrcBaseType &&bases, SrcExpType &&exponents)
Returns an expression that raises the elements in bases element-wise to the power of the elements in ...
Definition: Pow.h:213
constexpr ExpressionChainBuilder< expressions::PowConstantExponent, Constant< exponent > > powConstantExponent
Evaluates the source elements raised to the power of exponent.
Definition: Pow.h:259
The main namespace of the VCTR project.
Definition: Array.h:24
constexpr void assertCommonSize(const A &a, const B &b)
Ensures that both sources have the same size.
Definition: Traits.h:256
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
int sizeToInt(size_t size)
Casts the size_t argument to an int.
Definition: PlatformVectorOpsHelpers.h:27
An expression chain builder is an object which supplies various operator<< overloads which build chai...
Definition: ExpressionChainBuilder.h:157
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: NeonRegister.h:28
Definition: SSERegister.h:28