question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inverse fft in 2D backend

See original GitHub issue

EDIT by EO:

  • Using the appropriate normalization for the ifft (ie both backend files)
  • Adding a unit test in 2d/test for testing the fft, which is not currently tested
  • Normalizing the wavelet in the Fourier domain (ie the file filter_bank.py) to avoid the new code to break and satisfy the previous unit tests NOTE: this might lead to a small(not to say tiny) speed-up, because the dot-wise multiplication usually use quite some resources!

In 2D backend code, in output = torch.ifft(input, 2, normalized=False)*input.size(-2)*input.size(-3) why is the inverse fft routine multiplied by the term *input.size(-2)*input.size(-3)? I was expecting that transforming a matrix back and forth to the Fourier domain give the same result. In other words, I was expecting outputs of the following test code match.

import torch
from kymatio.scattering2d import backend as bd2

pad = bd2.Pad(2 ** 0, pre_pad=False)

# -- parameters
M = 8
N = 8
L = 8
J = 4

# -- synthesise data
y = torch.rand(1, 1, M, N)
for i in range(M):
    for j in range(N):
        y[:,:,i,j] = i+j

y_pad = pad(y)                                    # pad to add complex dimension
y_fft = bd2.fft(y_pad, 'C2C')                     # fft
y_fft_inv = bd2.fft(y_fft, 'C2C', inverse=True)   # inverse fft
y_fft_inv_un = y_fft_inv[..., 1:-1, 1:-1, 0]      # unpad

# -- print
print(y)
print(y_fft_inv_un)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nshervtcommented, Jun 13, 2019

Hi @edouardoyallon, will do by tomorrow. My changes break test_Scattering2D in unittests, and that I had to look into.

1reaction
edouardoyalloncommented, May 29, 2019

Hi, This is a very good point. It’s due to a lack of testing of the FFT, however solving it is easy! I put a checklist to fix this! Would you mind doing a PR for solving this? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

VPI - Vision Programming Interface: Inverse FFT
Given a 2D spectrum (frequency domain), it returns the image representation on the spatial domain. It is the exact inverse of FFT algorithm....
Read more >
How to Perform a 2D FFT Inplace Given a Complex 2D Array ...
Here we use a 2D array which will help us find the Fast Fourier Transform. This Algorithm is useful in pattern recognition. Examples....
Read more >
2-D inverse fast Fourier transform - MATLAB ifft2 - MathWorks
This MATLAB function returns the two-dimensional discrete inverse Fourier transform of a matrix using a fast Fourier transform algorithm.
Read more >
Eigen FFT library - Stack Overflow
I am trying to use Eigen unsupported FFT library using FFTW backend. Specifically I am want to do a 2D FFT. Here's my...
Read more >
Discrete Fourier transforms (scipy.fft) — SciPy v1.9.3 Manual
Compute the 2-D inverse discrete Fourier Transform. fftn (x[, s, axes, norm, overwrite_x, ...]) ... Context manager to set the backend within a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found