Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 16 additions & 2 deletions src/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,20 @@ function assert_applicable(p::FFTWPlan{T,K,inplace}, X::StridedArray{T}, Y::Stri
end
end


function assert_applicable(p::FFTWPlan{T,K, inplace}, X::AbstractArray) where {T,K, inplace}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of an if inplace stqtement, why not just make only to p::FFTWPlan{<:Any,<:Any,true}?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, we need to make sure that the parent assert_applicable is called when appropriate too…

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Well method dispatch on inline=true resulted in some method ambiguities which I couldn't resolve easily without hitting other code paths in the tests.

if inplace
throw(ArgumentError("In-place plan FFTWPlan{$(T)} cannot be applied to a $(typeof(X))"))
end
end

function assert_applicable(p::FFTWPlan{T, K, inplace}, X::AbstractArray, Y::AbstractArray) where {T,K, inplace}
if inplace
throw(ArgumentError("In-place plan FFTWPlan{$(T)} cannot be applied to a $(typeof(X))"))
end
end


# strides for a column-major (Julia-style) array of size == sz
colmajorstrides(::Tuple{}) = ()
colmajorstrides(sz) = _colmajorstrides(1, sz...)
Expand Down Expand Up @@ -832,7 +846,7 @@ function *(p::cFFTWPlan{T,K,false}, x::StridedArray{T,N}) where {T,K,N}
return y
end

function *(p::cFFTWPlan{T,K,true}, x::StridedArray{T}) where {T,K}
function *(p::cFFTWPlan{T,K,true}, x::AbstractArray) where {T,K}
assert_applicable(p, x)
unsafe_execute!(p, x, x)
return x
Expand Down Expand Up @@ -1046,7 +1060,7 @@ function *(p::r2rFFTWPlan{T,K,false}, x::StridedArray{T,N}) where {T,K,N}
return y
end

function *(p::r2rFFTWPlan{T,K,true}, x::StridedArray{T}) where {T,K}
function *(p::r2rFFTWPlan{T,K,true}, x::AbstractArray) where {T,K}
assert_applicable(p, x)
unsafe_execute!(p, x, x)
return x
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,18 @@ end
AbstractFFTs.TestUtils.test_real_ffts(Array; copy_input=true)
end
end


@testset "Ensure in-place version throws with wrong type" begin
complexplan = plan_fft!(zeros(ComplexF64, 4))
realvec = [1,1,1,1]

@test_throws MethodError FFTW.mul!(realvec, complexplan, realvec)
@test_throws ArgumentError complexplan * realvec

complexvec=ones(ComplexF64,4)
realplan = FFTW.plan_r2r!(zeros(4), FFTW.REDFT10)
@test_throws MethodError FFTW.mul!(complexvec, realplan, complexvec)
@test_throws ArgumentError realplan * complexvec

Comment thread
j-fu marked this conversation as resolved.
end
Loading