NumCpp  2.18.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
reciprocal.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <complex>
31
34#include "NumCpp/Core/Types.hpp"
35#include "NumCpp/NdArray.hpp"
36
37namespace nc
38{
39 //============================================================================
40 // Method Description:
51 template<typename dtype>
53 {
55
56 NdArray<double> returnArray(inArray.shape());
57
58 uint32 counter = 0;
59 std::for_each(inArray.cbegin(),
60 inArray.cend(),
61 [&returnArray, &counter](dtype value) noexcept -> void
62 { returnArray[counter++] = 1. / static_cast<double>(value); });
63
64 return returnArray;
65 }
66
67 //============================================================================
68 // Method Description:
79 template<typename dtype>
80 NdArray<std::complex<double>> reciprocal(const NdArray<std::complex<dtype>>& inArray)
81 {
83
84 NdArray<std::complex<double>> returnArray(inArray.shape());
85
86 uint32 counter = 0;
87 std::for_each(inArray.cbegin(),
88 inArray.cend(),
89 [&returnArray, &counter](std::complex<dtype> value) -> void
90 { returnArray[counter++] = std::complex<double>(1.) / complex_cast<double>(value); });
91
92 return returnArray;
93 }
94} // namespace nc
#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:135
const_iterator cbegin() const noexcept
Definition NdArrayCore.hpp:1361
const Shape & shape() const noexcept
Definition NdArrayCore.hpp:4587
const_iterator cend() const noexcept
Definition NdArrayCore.hpp:1669
Definition Cartesian.hpp:39
NdArray< double > reciprocal(const NdArray< dtype > &inArray)
Definition reciprocal.hpp:52
std::uint32_t uint32
Definition Types.hpp:40