NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
reciprocal.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <complex>
31
35#include "NumCpp/Core/Types.hpp"
36#include "NumCpp/NdArray.hpp"
37
38namespace nc
39{
40 //============================================================================
41 // Method Description:
52 template<typename dtype>
54 {
56
57 NdArray<double> returnArray(inArray.shape());
58
59 uint32 counter = 0;
60 std::for_each(inArray.cbegin(),
61 inArray.cend(),
62 [&returnArray, &counter](dtype value) noexcept -> void
63 { returnArray[counter++] = 1. / static_cast<double>(value); });
64
65 return returnArray;
66 }
67
68 //============================================================================
69 // Method Description:
80 template<typename dtype>
81 NdArray<std::complex<double>> reciprocal(const NdArray<std::complex<dtype>>& inArray)
82 {
84
85 NdArray<std::complex<double>> returnArray(inArray.shape());
86
87 uint32 counter = 0;
88 std::for_each(inArray.cbegin(),
89 inArray.cend(),
90 [&returnArray, &counter](std::complex<dtype> value) -> void
91 { returnArray[counter++] = std::complex<double>(1.) / complex_cast<double>(value); });
92
93 return returnArray;
94 }
95} // namespace nc
#define STATIC_ASSERT_ARITHMETIC(dtype)
Definition: StaticAsserts.hpp:39
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
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition: StlAlgorithms.hpp:225
Definition: Cartesian.hpp:40
NdArray< double > reciprocal(const NdArray< dtype > &inArray)
Definition: reciprocal.hpp:53
std::uint32_t uint32
Definition: Types.hpp:40