NumCpp  2.16.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
Loading...
Searching...
No Matches
rfft2.hpp
Go to the documentation of this file.
1
28#pragma once
29
30#include <complex>
31
33#include "NumCpp/Core/Types.hpp"
35#include "NumCpp/NdArray.hpp"
36
37namespace nc::fft
38{
39 namespace detail
40 {
41 //===========================================================================
42 // Method Description:
48 inline NdArray<std::complex<double>> rfft2_internal(const NdArray<std::complex<double>>& x, const Shape& shape)
49 {
50 if (shape.rows == 0 || shape.cols == 0)
51 {
52 return {};
53 }
54
55 const auto realN = shape.cols / 2 + 1;
57
59 result.end(),
60 [&](auto& resultElement)
61 {
62 const auto i = &resultElement - result.data();
63 const auto k = static_cast<double>(i / realN);
64 const auto l = static_cast<double>(i % realN);
65 resultElement = std::complex<double>{ 0., 0. };
66 for (auto m = 0u; m < std::min(shape.rows, x.numRows()); ++m)
67 {
68 for (auto n = 0u; n < std::min(shape.cols, x.numCols()); ++n)
69 {
70 const auto angle =
72 (((static_cast<double>(m) * k) / static_cast<double>(shape.rows)) +
73 ((static_cast<double>(n) * l) / static_cast<double>(shape.cols)));
74 resultElement += (x(m, n) * std::polar(1., angle));
75 }
76 }
77 });
78
79 return result;
80 }
81 } // namespace detail
82
83 //============================================================================
84 // Method Description:
94 template<typename dtype>
95 NdArray<std::complex<double>> rfft2(const NdArray<dtype>& inArray, const Shape& inShape)
96 {
98
99 const auto data = nc::complex<dtype, double>(inArray);
100 return detail::rfft2_internal(data, inShape);
101 }
102
103 //============================================================================
104 // Method Description:
113 template<typename dtype>
115 {
117
118 return rfft2(inArray, inArray.shape());
119 }
120} // 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
constexpr double twoPi
2Pi
Definition Core/Constants.hpp:40
NdArray< std::complex< double > > rfft2_internal(const NdArray< std::complex< double > > &x, const Shape &shape)
Definition rfft2.hpp:48
Definition FFT/FFT.hpp:40
NdArray< std::complex< double > > rfft2(const NdArray< dtype > &inArray, const Shape &inShape)
Definition rfft2.hpp:95
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