NumCpp  2.16.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
irfft2.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/FFT/ifft2.hpp"
39#include "NumCpp/NdArray.hpp"
40
41namespace nc::fft
42{
43 namespace detail
44 {
45 //===========================================================================
46 // Method Description:
52 inline NdArray<double> irfft2_internal(const NdArray<std::complex<double>>& x, const Shape& shape)
53 {
54 if (x.size() == 0 || shape.rows == 0 || shape.cols == 0)
55 {
56 return {};
57 }
58
59 const auto necessaryInputPoints = shape.cols / 2 + 1;
61 if (x.numCols() > necessaryInputPoints)
62 {
63 input = x(x.rSlice(), Slice(necessaryInputPoints + 1));
64 }
65 else if (x.numCols() < necessaryInputPoints)
66 {
68 input.put(x.rSlice(), x.cSlice(), x);
69 }
70 else
71 {
72 input = x;
73 }
74
75 auto realN = 2 * (input.numCols() - 1);
76 realN += shape.cols % 2 == 1 ? 1 : 0;
78 for (auto row = 0u; row < input.numRows(); ++row)
79 {
80 stl_algorithms::copy(input.begin(row), input.end(row), fullOutput.begin(row));
81 }
83 fullOutput.begin(0) + input.numCols(),
84 fullOutput.rbegin(0),
85 [](const auto& value) { return std::conj(value); });
86 for (auto col = 1u; col < input.numCols(); ++col)
87 {
88 stl_algorithms::transform(input.colbegin(col) + 1,
89 input.colend(col),
90 fullOutput.rcolbegin(fullOutput.numCols() - col),
91 [](const auto& value) { return std::conj(value); });
92 }
93
95 }
96 } // namespace detail
97
98 //============================================================================
99 // Method Description:
109 template<typename dtype>
110 NdArray<double> irfft2(const NdArray<std::complex<dtype>>& inArray, const Shape& inShape)
111 {
113
114 const auto data = nc::complex<dtype, double>(inArray);
115 return detail::irfft2_internal(data, inShape);
116 }
117
118 //============================================================================
119 // Method Description:
128 template<typename dtype>
129 NdArray<double> irfft2(const NdArray<std::complex<dtype>>& inArray)
130 {
132
133 const auto& shape = inArray.shape();
134 const auto newCols = 2 * (shape.cols - 1);
135 return irfft2(inArray, { shape.rows, newCols });
136 }
137} // 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
A Shape Class for NdArrays.
Definition Core/shape.hpp:41
uint32 rows
Definition Core/shape.hpp:44
uint32 cols
Definition Core/shape.hpp:45
A Class for slicing into NdArrays.
Definition Slice.hpp:45
NdArray< std::complex< double > > ifft2_internal(const NdArray< std::complex< double > > &x, const Shape &shape)
Definition ifft2.hpp:47
NdArray< double > irfft2_internal(const NdArray< std::complex< double > > &x, const Shape &shape)
Definition irfft2.hpp:52
Definition FFT/FFT.hpp:40
NdArray< double > irfft2(const NdArray< std::complex< dtype > > &inArray, const Shape &inShape)
Definition irfft2.hpp:110
OutputIt transform(InputIt first, InputIt last, OutputIt destination, UnaryOperation unaryFunction)
Definition StlAlgorithms.hpp:775
OutputIt copy(InputIt first, InputIt last, OutputIt destination) noexcept
Definition StlAlgorithms.hpp:97
auto real(const std::complex< dtype > &inValue)
Definition real.hpp:48
NdArray< dtype > arange(dtype inStart, dtype inStop, dtype inStep=1)
Definition arange.hpp:59
NdArray< dtype > zeros(uint32 inSquareSize)
Definition zeros.hpp:48
Shape shape(const NdArray< dtype > &inArray) noexcept
Definition Functions/shape.hpp:42