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

Support new AbstractFFTs.AdjointStyle trait for FFT and DCT plans #249

Merged
merged 8 commits into from
Sep 4, 2023
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
AbstractFFTs = "1.0"
AbstractFFTs = "1.5"
FFTW_jll = "3.3.9"
MKL_jll = "2019.0.117, 2020, 2021, 2022, 2023"
Preferences = "1.2"
Expand Down
2 changes: 2 additions & 0 deletions src/dct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,5 @@ end
mul!(Array{T}(undef, p.plan.osz), p, copy(x)) # need copy to preserve input

*(p::DCTPlan{T,K,true}, x::StridedArray{T}) where {T,K} = mul!(x, p, x)

AbstractFFTs.AdjointStyle(::DCTPlan) = AbstractFFTs.UnitaryAdjointStyle()
gaurav-arya marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions src/fft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1049,3 +1049,9 @@ function *(p::r2rFFTWPlan{T,K,true}, x::StridedArray{T}) where {T,K}
unsafe_execute!(p, x, x)
return x
end

#######################################################################

AbstractFFTs.AdjointStyle(::cFFTWPlan) = AbstractFFTs.FFTAdjointStyle()
AbstractFFTs.AdjointStyle(::rFFTWPlan{T, FORWARD}) where {T} = AbstractFFTs.RFFTAdjointStyle()
AbstractFFTs.AdjointStyle(p::rFFTWPlan{T, BACKWARD}) where {T} = AbstractFFTs.IRFFTAdjointStyle(p.osz[first(p.region)])
24 changes: 24 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -577,3 +577,27 @@ end
end
end
end

@testset "DCT adjoints" begin
# only test on FFTW because MKL is missing functionality
if FFTW.get_provider() == "fftw"
for x in (randn(3), randn(4), randn(3, 4), randn(3, 4, 5))
y = randn(size(x))
N = ndims(x)
for dims in unique((1, 1:N, N))
for P in (plan_dct(x, dims), plan_idct(x, dims))
AbstractFFTs.TestUtils.test_plan_adjoint(P, x)
end
end
end
end
end

@testset "AbstractFFTs FFT backend tests" begin
# note this also tests adjoint functionality for FFT plans
# only test on FFTW because MKL is missing functionality
if FFTW.get_provider() == "fftw"
AbstractFFTs.TestUtils.test_complex_ffts(Array)
AbstractFFTs.TestUtils.test_real_ffts(Array; copy_input=true)
end
end