Inplace irfft calculations with `mul!` mutate the fourier-space array
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by running the provided Julia reproduction using plan_irfft and LinearAlgebra.mul! with FFTW. Trace the planned preallocated path and compare it with irfft and plan * uhat; done means mul! produces the correct output without mutating the Fourier-space input array.
Written by the indexing model from the issue text.
Description
I ran into some unexpected behavior with both FFTW.jl and FastTransforms.jl but not CUFFT.jl. I am thinking this repo is the appropriate location to raise this issue, but its possible it is an issue with both FFTW.jl and FastTransforms.jl
Summary
When applying a irfft plan to a Fourier space matrix uhat with mul! and a preallocated output array u, uhat is unexpectedly mutated.
Given a uhat matrix of elements ComplexF64 and shape (3,4), these work as expected:
u = irfft(uhat, 4, 1:2)
plan = plan_irfft(uhat, 4, 1:2)
u = plan * uhat
this generates the correct u, but mutates uhat:
plan = plan_irfft(uhat, 4, 1:2)
u = zeros(4,4)
mul!(u, plan, uhat)
Reproduction
using FFTW
using LinearAlgebra: mul!
# (3,4) array
uhat = ComplexF64.([
1 2 3 4;
1 2 3 4;
1 2 3 4;
])
#
# first, perform an irfft without a plan
#
u = irfft(uhat, 4, 1:2)
println("\n\n########\n########")
println("unplanned irfft:")
display(u)
println("û: unchanged:")
display(uhat)
# generate an irfft plan
plan = plan_irfft(uhat, 4, 1:2)
#
# calculate the irfft with the plan (allocates)
#
u_plan = plan * uhat
println("\n\n########\n########")
println("planned irfft with allocation:")
display(u_plan)
println("uhat: unchanged:")
display(uhat)
#
# calculate the irfft with the plan (reuse allocation)
#
u_plan_preallocation = zeros(4,4)
mul!(u_plan_preallocation, plan, uhat)
println("\n\n########\n########")
println("planned irfft with preallocation:")
display(u_plan)
println("uhat: HAS changed:")
display(uhat)
This outputs:
########
########
unplanned irfft:
4×4 Matrix{Float64}:
2.5 -0.5 -0.5 -0.5
0.0 0.25 0.0 -0.25
0.0 0.0 0.0 0.0
0.0 -0.25 0.0 0.25
û: unchanged:
3×4 Matrix{ComplexF64}:
1.0+0.0im 2.0+0.0im 3.0+0.0im 4.0+0.0im
1.0+0.0im 2.0+0.0im 3.0+0.0im 4.0+0.0im
1.0+0.0im 2.0+0.0im 3.0+0.0im 4.0+0.0im
########
########
planned irfft with allocation:
4×4 Matrix{Float64}:
2.5 -0.5 -0.5 -0.5
0.0 0.25 0.0 -0.25
0.0 0.0 0.0 0.0
0.0 -0.25 0.0 0.25
uhat: unchanged:
3×4 Matrix{ComplexF64}:
1.0+0.0im 2.0+0.0im 3.0+0.0im 4.0+0.0im
1.0+0.0im 2.0+0.0im 3.0+0.0im 4.0+0.0im
1.0+0.0im 2.0+0.0im 3.0+0.0im 4.0+0.0im
########
########
planned irfft with preallocation:
4×4 Matrix{Float64}:
2.5 -0.5 -0.5 -0.5
0.0 0.25 0.0 -0.25
0.0 0.0 0.0 0.0
0.0 -0.25 0.0 0.25
uhat: HAS changed:
3×4 Matrix{ComplexF64}:
10.0+0.0im -2.0-2.0im -2.0+0.0im -2.0+2.0im
10.0+0.0im -2.0-2.0im -2.0+0.0im -2.0+2.0im
10.0+0.0im -2.0-2.0im -2.0+0.0im -2.0+2.0im
- Dominant language
- Julia
- Stars
- 135
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from JuliaMath/AbstractFFTs.jl
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaMath/AbstractFFTs.jl#159 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
JuliaMath/AbstractFFTs.jl#147 ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
JuliaMath/AbstractFFTs.jl#135 ·
-
Difficulty 5/5 Over a week Newbie friendliness 28/100
JuliaMath/AbstractFFTs.jl#125 · 2 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
JuliaMath/AbstractFFTs.jl#122 · 3 comments ·
All issues in JuliaMath/AbstractFFTs.jl
Similar issues
-
io
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
JuliaGPU/GPUArrays.jl#837 ·
Maintainers usually reply within 2 days
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bmad-sim/BeamTracking.jl#382 ·
Maintainers usually reply within 1 day