NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
complex.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <complex>
31
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
46 template<typename dtype>
47 auto complex(dtype inReal)
48 {
50
51 return std::complex<dtype>(inReal);
52 }
53
54 //============================================================================
55 // Method Description:
62 template<typename dtype>
63 auto complex(dtype inReal, dtype inImag)
64 {
66
67 return std::complex<dtype>(inReal, inImag);
68 }
69
70 //============================================================================
71 // Method Description:
77 template<typename dtype>
78 auto complex(const NdArray<dtype>& inReal)
79 {
80 NdArray<decltype(nc::complex(dtype{ 0 }))> returnArray(inReal.shape());
82 inReal.cend(),
83 returnArray.begin(),
84 [](dtype real) -> auto { return nc::complex(real); });
85
86 return returnArray;
87 }
88
89 //============================================================================
90 // Method Description:
97 template<typename dtype>
98 auto complex(const NdArray<dtype>& inReal, const NdArray<dtype>& inImag)
99 {
100 if (inReal.shape() != inImag.shape())
101 {
102 THROW_INVALID_ARGUMENT_ERROR("Input real array must be the same shape as input imag array");
103 }
104
105 NdArray<decltype(nc::complex(dtype{ 0 }, dtype{ 0 }))> returnArray(inReal.shape());
107 inReal.cend(),
108 inImag.cbegin(),
109 returnArray.begin(),
110 [](dtype real, dtype imag) -> auto { return nc::complex(real, imag); });
111
112 return returnArray;
113 }
114} // namespace nc
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
Holds 1D and 2D arrays, the main work horse of the NumCpp library.
Definition: NdArrayCore.hpp:139
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1365
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4511
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1673
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:775
Definition: Cartesian.hpp:40
auto imag(const std::complex< dtype > &inValue)
Definition: imag.hpp:47
auto complex(dtype inReal)
Definition: complex.hpp:47
auto real(const std::complex< dtype > &inValue)
Definition: real.hpp:48