Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFTW planned 2D real ldiv! unexpectedly overwrites input #158

Open
marius311 opened this issue Aug 11, 2020 · 3 comments
Open

FFTW planned 2D real ldiv! unexpectedly overwrites input #158

marius311 opened this issue Aug 11, 2020 · 3 comments

Comments

@marius311
Copy link

The following seems unexpected:

using FFTW, LinearAlgebra
y = rand(4,4)
p = plan_rfft(y)
x = p * y
x_orig = copy(x)
ldiv!(y,p,x)
x == x_orig # unexpectedly returns false

This only happens with FFTW and not MKL, only with 2D and real FFTs, and only with ldiv! not mul!.

@stevengj
Copy link
Member

stevengj commented Aug 11, 2020

Unfortunately, FFTW's multidimensional c2r transforms (the inverse of rfft) overwrite the input, even for out-of-place transforms. The only way around this is to make an extra copy.

@marius311
Copy link
Author

That's fine, but shouldn't this package be making that copy for you? It kind of seems like its trying to do so here in fact, although I don't fully understand everything that's happening.

@jamesgabbard
Copy link

Bumping this issue, I spent quite some time debugging before figuring this out by experiment. I doubt that anyone expects ldiv! to modify its last argument.

Silently creating a copy seems like a poor solution. Users who are writing ldiv!(real, plan, complex) instead of real .= irfft(complex) are probably doing this for performance reasons, and won't enjoy a large and unexpected allocation. Seems better just to clearly state in the FFTW.jl documentation that any c2r transform will overwrite its input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants