NumCpp  1.0
A C++ implementation of the Python Numpy library
complex.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/NdArray.hpp"
35 
36 #include <complex>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
48  template<typename dtype>
49  auto complex(dtype inReal)
50  {
52 
53  return std::complex<dtype>(inReal);
54  }
55 
56  //============================================================================
57  // Method Description:
65  template<typename dtype>
66  auto complex(dtype inReal, dtype inImag)
67  {
69 
70  return std::complex<dtype>(inReal, inImag);
71  }
72 
73  //============================================================================
74  // Method Description:
81  template<typename dtype>
82  auto complex(const NdArray<dtype>& inReal)
83  {
84  NdArray<decltype(nc::complex(dtype{0}))> returnArray(inReal.shape());
85  stl_algorithms::transform(inReal.cbegin(), inReal.cend(), returnArray.begin(),
86  [](dtype real) -> auto
87  {
88  return nc::complex(real);
89  });
90 
91  return returnArray;
92  }
93 
94  //============================================================================
95  // Method Description:
103  template<typename dtype>
104  auto complex(const NdArray<dtype>& inReal, const NdArray<dtype>& inImag)
105  {
106  if (inReal.shape() != inImag.shape())
107  {
108  THROW_INVALID_ARGUMENT_ERROR("Input real array must be the same shape as input imag array");
109  }
110 
111  NdArray<decltype(nc::complex(dtype{0}, dtype{0}))> returnArray(inReal.shape());
112  stl_algorithms::transform(inReal.cbegin(), inReal.cend(), inImag.cbegin(), returnArray.begin(),
113  [](dtype real, dtype imag) -> auto
114  {
115  return nc::complex(real, imag);
116  });
117 
118  return returnArray;
119  }
120 }
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
nc::complex
auto complex(dtype inReal)
Definition: complex.hpp:49
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::NdArray< dtype >
NdArray.hpp
nc::imag
auto imag(const std::complex< dtype > &inValue)
Definition: imag.hpp:50
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
nc::real
auto real(const std::complex< dtype > &inValue)
Definition: real.hpp:51
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction) noexcept
Definition: StlAlgorithms.hpp:703
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091