VCTR
Loading...
Searching...
No Matches
Log2.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>>
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 (Log2, 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 return value_type (gcem::log2 (src[i]));
42#endif
43
44 return value_type (std::log2 (src[i]));
45 }
46
47 //==============================================================================
48 // Platform Vector Operation Implementation
49 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
51 {
52 Expression::Accelerate::log2 (src.evalNextVectorOpInExpressionChain (dst), dst, sizeToInt (size()));
53 return dst;
54 }
55
56 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
58 {
59 auto s = size();
60
61 Expression::Accelerate::intToFloat (src.evalNextVectorOpInExpressionChain (reinterpret_cast<SrcValueType*> (dst)), dst, s);
62 Expression::Accelerate::log2 (dst, dst, sizeToInt (s));
63
64 return dst;
65 }
66
67 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
69 {
70 // No direct log2 in IPP. Therefore, we compute the ln and then multiply by 1 / ln (2)
71 constexpr auto factor = value_type (1.4426950408889634);
72
73 auto s = sizeToInt (size());
74
75 Expression::IPP::ln (src.evalNextVectorOpInExpressionChain (dst), dst, s);
76 Expression::IPP::mul (factor, dst, s);
77
78 return dst;
79 }
80};
81
82} // namespace vctr::expressions
83
84namespace vctr
85{
86
92
93} // namespace vctr
Definition: Log2.h:29
Constrains a type to represent a real valued 32 bit integer number.
Definition: NumericTypeConcepts.h:53
Constrains a type to represent a real valued floating point number.
Definition: NumericTypeConcepts.h:79
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:242
A combined concept to check if Apple Accelerate is a suitable option for a vector operation that tran...
Definition: ContainerAndExpressionConcepts.h:258
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:278
constexpr ExpressionChainBuilder< expressions::Log2 > log2
Computes the logarithm to the base of two of the source values.
Definition: Log2.h:91
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
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