VCTR
Loading...
Searching...
No Matches
Exp.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 SrcType>
27requires is::realNumber<ValueType<SrcType>> || is::complexFloatNumber<ValueType<SrcType>>
29{
30 using SrcValueType = ValueType<SrcType>;
31
32public:
33 using value_type = std::conditional_t<is::intNumber<SrcValueType>, float, SrcValueType>;
34
35 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (Exp, src)
36
37 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
38 {
39#if VCTR_USE_GCEM
40 if (std::is_constant_evaluated())
41 {
43 {
44 // gcem has no complex support, so we use e^(a + ib) = e^a * (cos (b) + i sin (b))
45 const auto z = src[i];
46 const auto magnitude = gcem::exp (z.real());
47
48 return value_type (magnitude * gcem::cos (z.imag()), magnitude * gcem::sin (z.imag()));
49 }
50 else
51 {
52 return value_type (gcem::exp (src[i]));
53 }
54 }
55#endif
56
57 return value_type (std::exp (src[i]));
58 }
59
60 //==============================================================================
61 // Platform Vector Operation Implementation
62 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
64 {
65 Expression::Accelerate::exp (src.evalNextVectorOpInExpressionChain (dst), dst, sizeToInt (size()));
66 return dst;
67 }
68
69 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
71 {
72 auto s = size();
73
74 Expression::Accelerate::intToFloat (src.evalNextVectorOpInExpressionChain (reinterpret_cast<SrcValueType*> (dst)), dst, s);
75 Expression::Accelerate::exp (dst, dst, sizeToInt (s));
76
77 return dst;
78 }
79
80 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
82 {
83 Expression::IPP::exp (src.evalNextVectorOpInExpressionChain (dst), dst, sizeToInt (size()));
84 return dst;
85 }
86
87 VCTR_FORWARD_PREPARE_SIMD_EVALUATION_UNARY_EXPRESSION_MEMBER_FUNCTIONS
88
89 VCTR_FORCEDINLINE NeonRegister<value_type> getNeon (size_t i) const
90 requires archARM && platformApple && has::getNeon<SrcType> && std::same_as<value_type, float>
91 {
92 return Expression::Neon::exp (src.getNeon (i));
93 }
94
95 VCTR_FORCEDINLINE VCTR_TARGET ("fma") AVXRegister<value_type> getAVX (size_t i) const
96 requires archX64 && hasSVML && has::getAVX<SrcType> && is::realFloatNumber<value_type>
97 {
98 return Expression::AVX::exp (src.getAVX (i));
99 }
100
101 VCTR_FORCEDINLINE VCTR_TARGET ("sse4.1") SSERegister<value_type> getSSE (size_t i) const
103 {
104 return Expression::SSE::exp (src.getSSE (i));
105 }
106};
107
108} // namespace vctr::expressions
109
110namespace vctr
111{
112
123
124} // namespace vctr
Definition: Exp.h:29
Constrains a type to have a member function getAVX (size_t) const.
Definition: ContainerAndExpressionConcepts.h:98
Constrains a type to have a member function getNeon (size_t) const.
Definition: ContainerAndExpressionConcepts.h:90
Constrains a type to have a member function getSSE (size_t) const.
Definition: ContainerAndExpressionConcepts.h:106
Constrains a type to represent a complex valued floating point number (e.g.
Definition: NumericTypeConcepts.h:91
Constrains a type to represent a real valued 32 bit integer number.
Definition: NumericTypeConcepts.h:61
Constrains a type to represent a real valued floating point number.
Definition: NumericTypeConcepts.h:87
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:309
A combined concept to check if Apple Accelerate is a suitable option for a vector operation that tran...
Definition: ContainerAndExpressionConcepts.h:329
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:349
A combined concept if one of the similar named Apple Accelerate VFP or Intel SVML backed member funct...
Definition: ContainerAndExpressionConcepts.h:399
constexpr auto magnitude(SrcType &&src)
Returns an expression containing the magnitude of each value in a split-complex source.
Definition: SplitComplexMath.h:185
constexpr ExpressionChainBuilder< expressions::Exp > exp
Computes e (Euler's number, 2.7182818...) raised to the source vector elements power.
Definition: Exp.h:122
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
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:170
The base class to every expression template.
Definition: ExpressionTemplate.h:37
Definition: NeonRegister.h:28
Definition: SSERegister.h:28