NumCpp  2.1.0
A C++ implementation of the Python Numpy library
reciprocal.hpp
Go to the documentation of this file.
1 #pragma once
30 
34 #include "NumCpp/Core/Types.hpp"
35 #include "NumCpp/NdArray.hpp"
36 
37 #include <complex>
38 
39 namespace nc
40 {
41  //============================================================================
42  // Method Description:
55  template<typename dtype>
57  {
59 
60  NdArray<double> returnArray(inArray.shape());
61 
62  uint32 counter = 0;
63  std::for_each(inArray.cbegin(), inArray.cend(),
64  [&returnArray, &counter](dtype value) noexcept -> void
65  {
66  returnArray[counter++] = 1.0 / static_cast<double>(value);
67  });
68 
69  return returnArray;
70  }
71 
72  //============================================================================
73  // Method Description:
86  template<typename dtype>
87  NdArray<std::complex<double>> reciprocal(const NdArray<std::complex<dtype>>& inArray)
88  {
90 
91  NdArray<std::complex<double>> returnArray(inArray.shape());
92 
93  uint32 counter = 0;
94  std::for_each(inArray.cbegin(), inArray.cend(),
95  [&returnArray, &counter](std::complex<dtype> value) -> void
96  {
97  returnArray[counter++] = std::complex<double>(1.0) / complex_cast<double>(value);
98  });
99 
100  return returnArray;
101  }
102 } // namespace nc
StaticAsserts.hpp
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4312
STATIC_ASSERT_ARITHMETIC
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:38
StdComplexOperators.hpp
nc::NdArray< double >
nc::stl_algorithms::for_each
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:214
nc::uint32
std::uint32_t uint32
Definition: Types.hpp:41
NdArray.hpp
nc::NdArray::cend
const_iterator cend() const noexcept
Definition: NdArrayCore.hpp:1491
nc
Definition: Coordinate.hpp:45
nc::NdArray::cbegin
const_iterator cbegin() const noexcept
Definition: NdArrayCore.hpp:1147
StlAlgorithms.hpp
Types.hpp
nc::reciprocal
NdArray< double > reciprocal(const NdArray< dtype > &inArray)
Definition: reciprocal.hpp:56