VCTR
Loading...
Searching...
No Matches
RealImagToComplex.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>
27requires is::realFloatNumber<ValueType<SrcAType>> && std::same_as<ValueType<SrcAType>, ValueType<SrcBType>>
29{
30public:
31 using value_type = std::complex<ValueType<SrcAType>>;
32
33 VCTR_COMMON_BINARY_VEC_VEC_EXPRESSION_MEMBERS (RealImagToComplex, real, imag)
34
35 VCTR_FORCEDINLINE constexpr value_type operator[] (size_t i) const
36 {
37 return { real[i], imag[i] };
38 }
39
40 //==============================================================================
41 // Platform Vector Operation Implementation. The real sources can't be evaluated into the complex destination, so the
42 // concepts only allow containers as sources. Expression::Accelerate / Expression::IPP refer to the real source type,
43 // the functions live in the complex one.
44 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
46 {
47 platform_vec_ops::AppleAccelerate<value_type>::realImagToComplex (real.data(), imag.data(), dst, size());
48 return dst;
49 }
50
51 VCTR_FORCEDINLINE const value_type* evalNextVectorOpInExpressionChain (value_type* dst) const
53 {
54 platform_vec_ops::IntelIPP<value_type>::realImagToComplex (real.data(), imag.data(), dst, sizeToInt (size()));
55 return dst;
56 }
57};
58
59} // namespace vctr::expressions
60
61namespace vctr
62{
73template <is::anyVctrOrExpression RealType, is::anyVctrOrExpression ImagType>
74constexpr auto realImagToComplex (RealType&& real, ImagType&& imag)
75{
77 constexpr auto extent = getCommonExtent<RealType, ImagType>();
78 return expressions::RealImagToComplex<extent, RealType, ImagType> (std::forward<RealType> (real), std::forward<ImagType> (imag));
79}
80} // namespace vctr
Definition: RealImagToComplex.h:29
A combined concept to check if Apple Accelerate is a suitable option for a complex valued floating po...
Definition: ContainerAndExpressionConcepts.h:378
A combined concept to check if Intel IPP is a suitable option for a complex valued floating point bin...
Definition: ContainerAndExpressionConcepts.h:391
constexpr ExpressionChainBuilder< expressions::Imag > imag
Extracts the imaginary parts of the complex source values.
Definition: Imag.h:60
constexpr auto realImagToComplex(SrcType &&src)
Returns an expression that converts a split-complex source into interleaved std::complex values.
Definition: SplitComplexMath.h:206
constexpr ExpressionChainBuilder< expressions::Real > real
Extracts the real parts of the complex source values.
Definition: Real.h:60
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::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
The base class to every expression template.
Definition: ExpressionTemplate.h:37