NumCpp  2.14.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>
48 {
50
51 return std::complex<dtype>(inReal);
52 }
53
54 //============================================================================
55 // Method Description:
62 template<typename dtype>
64 {
66
67 return std::complex<dtype>(inReal, inImag);
68 }
69
70 //============================================================================
71 // Method Description:
77 template<typename dtype>
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>
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
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
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59