Skip to content

Clarify the use of plan_fft! #82

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/definitions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ plan_fft
"""
plan_fft!(A [, dims]; flags=FFTW.ESTIMATE, timelimit=Inf)

Same as [`plan_fft`](@ref), but operates in-place on `A`.
Same as [`plan_fft`](@ref),
but creates a plan that operates in-place.
`A` must be an array of complex floating-point numbers.
When `p = plan_fft!(A, ...)`,
one evaluates the FFT of an array `B`
of the same `size`
via `p * B` or via `mul!(B, p, B)`.
For the `mul!` use, `B` must have the same `eltype` as `A`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even for p * B, it won't work in-place if B doesn't have the same eltype, no?

(Note also that the strides have to be the same too, when applying a plan to a new array. This is typically only relevant for arrays that are views of other arrays, as otherwise the strides are determined by the size.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the p * B version works fine even if B has different eltype and strides from A:

using LinearAlgebra: mul!
using FFTW: plan_fft! 
dima = (8,16)
A = Array{ComplexF32}(undef, dima)
B = rand(ComplexF16, 4, dima...)
p = plan_fft!(A)
C = @view B[1,:,:] # strides and eltype differs from A
p * C # works fine!
D = collect(C)
@assert p * C == p * D # passes 

You make a good point that the mul! version requires matching strides too so I updated the PR to mention that.

"""
plan_fft!

Expand Down