NumCpp  2.1.0
A C++ implementation of the Python Numpy library
polar.hpp
Go to the documentation of this file.
1 #pragma once
30 
34 #include "NumCpp/NdArray.hpp"
35 
36 #include <complex>
37 
38 namespace nc
39 {
40  //============================================================================
41  // Method Description:
50  template<typename dtype>
51  auto polar(dtype magnitude, dtype phaseAngle)
52  {
54 
55  return std::polar(magnitude, phaseAngle);
56  }
57 
58  //============================================================================
59  // Method Description:
67  template<typename dtype>
68  auto polar(const NdArray<dtype>& magnitude, const NdArray<dtype>& phaseAngle)
69  {
70  if (magnitude.shape() != phaseAngle.shape())
71  {
72  THROW_INVALID_ARGUMENT_ERROR("Input magnitude and phaseAngle arrays must be the same shape");
73  }
74 
75  NdArray<decltype(nc::polar(dtype{0}, dtype{0}))> returnArray(magnitude.shape());
76  stl_algorithms::transform(magnitude.cbegin(), magnitude.cend(), phaseAngle.begin(), returnArray.begin(),
77  [](dtype mag, dtype angle) -> auto
78  {
79  return nc::polar(mag, angle);
80  });
81 
82  return returnArray;
83  }
84 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
Error.hpp
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
nc::NdArray< dtype >
nc::polar
auto polar(dtype magnitude, dtype phaseAngle)
Definition: polar.hpp:51
nc::stl_algorithms::transform
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition: StlAlgorithms.hpp:703
NdArray.hpp
nc::angle
auto angle(const std::complex< dtype > &inValue)
Definition: angle.hpp:51
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
THROW_INVALID_ARGUMENT_ERROR
#define THROW_INVALID_ARGUMENT_ERROR(msg)
Definition: Error.hpp:37
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
nc::NdArray::begin
iterator begin() noexcept
Definition: NdArrayCore.hpp:1091
nc::polar
auto polar(const NdArray< dtype > &magnitude, const NdArray< dtype > &phaseAngle)
Definition: polar.hpp:68