NumCpp  2.16.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
ifft2.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <complex>
31
33#include "NumCpp/Core/Types.hpp"
34#include "NumCpp/NdArray.hpp"
35
36namespace nc::fft
37{
38 namespace detail
39 {
40 //===========================================================================
41 // Method Description:
47 inline NdArray<std::complex<double>> ifft2_internal(const NdArray<std::complex<double>>& x, const Shape& shape)
48 {
49 if (shape.rows == 0 || shape.cols == 0)
50 {
51 return {};
52 }
53
55
57 result.end(),
58 [&](auto& resultElement)
59 {
60 const auto i = &resultElement - result.data();
61 const auto m = static_cast<double>(i / shape.cols);
62 const auto n = static_cast<double>(i % shape.cols);
63 resultElement = std::complex<double>{ 0., 0. };
64 for (auto k = 0u; k < std::min(shape.rows, x.numRows()); ++k)
65 {
66 for (auto l = 0u; l < std::min(shape.cols, x.numCols()); ++l)
67 {
68 const auto angle =
70 (((static_cast<double>(k) * m) / static_cast<double>(shape.rows)) +
71 ((static_cast<double>(l) * n) / static_cast<double>(shape.cols)));
72 resultElement += (x(k, l) * std::polar(1., angle));
73 }
74 }
76 });
77
78 return result;
79 }
80 } // namespace detail
81
82 //===========================================================================
83 // Method Description:
93 template<typename dtype>
94 NdArray<std::complex<double>> ifft2(const NdArray<dtype>& inArray, const Shape& inShape)
95 {
97
98 const auto data = nc::complex<dtype, double>(inArray);
99 return detail::ifft2_internal(data, inShape);
100 }
101
102 //===========================================================================
103 // Method Description:
112 template<typename dtype>
114 {
116
117 return ifft2(inArray, inArray.shape());
118 }
119
120 //============================================================================
121 // Method Description:
131 template<typename dtype>
132 NdArray<std::complex<double>> ifft2(const NdArray<std::complex<dtype>>& inArray, const Shape& inShape)
133 {
135
136 const auto data = nc::complex<dtype, double>(inArray);
137 return detail::ifft2_internal(data, inShape);
138 }
139
140 //============================================================================
141 // Method Description:
150 template<typename dtype>
151 NdArray<std::complex<double>> ifft2(const NdArray<std::complex<dtype>>& inArray)
152 {
154
155 return ifft2(inArray, inArray.shape());
156 }
157} // namespace nc::fft
#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:139
const Shape & shape() const noexcept
Definition NdArrayCore.hpp:4587
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
uint32 rows
Definition Core/shape.hpp:44
uint32 cols
Definition Core/shape.hpp:45
uint32 size() const noexcept
Definition Core/shape.hpp:104
constexpr double twoPi
2Pi
Definition Core/Constants.hpp:40
NdArray< std::complex< double > > ifft2_internal(const NdArray< std::complex< double > > &x, const Shape &shape)
Definition ifft2.hpp:47
Definition FFT/FFT.hpp:40
NdArray< std::complex< double > > ifft2(const NdArray< dtype > &inArray, const Shape &inShape)
Definition ifft2.hpp:94
void for_each(InputIt first, InputIt last, UnaryFunction f)
Definition StlAlgorithms.hpp:225
auto angle(const std::complex< dtype > &inValue)
Definition angle.hpp:48
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
Shape shape(const NdArray< dtype > &inArray) noexcept
Definition Functions/shape.hpp:42