fft#
Perform a 1D FFT. Batching is supported for any tensor with a rank higher than 1.
-
template<typename OpA>
__MATX_INLINE__ auto matx::fft(const OpA &a, uint64_t fft_size = 0, FFTNorm norm = FFTNorm::BACKWARD)# Run a 1D FFT with a cached plan
Creates a new FFT plan in the cache if none exists, and uses that to execute the 1D FFT. Note that FFTs and IFFTs share the same plans if all dimensions match Note: fft_size must be unsigned so that the axis overload does not match both prototypes with index_t.
- Template Parameters:
OpA – Input tensor or operator type
- Parameters:
a – input tensor or operator
fft_size – Size of FFT. Setting to 0 uses the output size to figure out the FFT size.
norm – Normalization to apply to FFT
-
template<typename OpA>
__MATX_INLINE__ auto matx::fft(const OpA &a, const int32_t (&axis)[1], uint64_t fft_size = 0, FFTNorm norm = FFTNorm::BACKWARD)# Run a 1D FFT with a cached plan
Creates a new FFT plan in the cache if none exists, and uses that to execute the 1D FFT. Note that FFTs and IFFTs share the same plans if all dimensions match Note: fft_size must be unsigned so that the axis overload does not match both prototypes with index_t.
- Template Parameters:
OpA – Input tensor or operator type
- Parameters:
a – input tensor or operator
axis – axis to perform FFT along
fft_size – Size of FFT. Setting to 0 uses the output size to figure out the FFT size.
norm – Normalization to apply to FFT
Examples#
// Perform a 1D FFT from input av into output avo. Input and output sizes will be deduced by the
// type of the tensors and output size.
(avo = fft(av)).run(this->exec);
auto in = make_tensor<TestType>({d1, d2, d3});
auto out1 = make_tensor<TestType>({d1, d2, d3});
auto out2 = make_tensor<TestType>({d1, d2, d3});
for(int i = 0; i < d1; i++) {
for(int j = 0; j < d2; j++) {
for(int k = 0; k < d3; k++) {
in(i,j,k) = static_cast<TestType>((float)(i+j+k));
}
}
}
// Perform a batched 1D FFT on a 3D tensor across axis 2. Since axis 2 is the last dimension,
// this is equivalent to not specifying the axis
(out1 = fft(in)).run(this->exec);
(out2 = fft(in, {2})).run(this->exec);
// Perform a batched 1D FFT on a 3D tensor across axis 1. This is equivalent to permuting the last
// two axes before input and after the output
(out1.Permute({0,2,1}) = fft(in.Permute({0,2,1}))).run(this->exec);
(out2 = fft(in, {1})).run(this->exec);
auto av = make_tensor<TestType>({fft_dim});
auto avo = make_tensor<TestType>({fft_dim * 2});
this->pb->NumpyToTensorView(av, "a_in");
// Specify the FFT size as bigger than av. Thus, av will be zero-padded to the appropriate size
(avo = fft(av, fft_dim * 2)).run(this->exec);
// Perform an FFT but force the size to be fft_dim * 2 instead of the output size
(avo = fft(av, fft_dim * 2)).run(this->exec); // Force the FFT size