Skip to content

Commit 3c727ab

Browse files
committed
Support new AdjointStyle trait
1 parent 008bc5b commit 3c727ab

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1111
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1212

1313
[compat]
14-
AbstractFFTs = "1.0"
14+
AbstractFFTs = "1.4"
1515
FFTW_jll = "3.3.9"
1616
MKL_jll = "2019.0.117, 2020, 2021, 2022, 2023"
1717
Preferences = "1.2"

src/dct.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,5 @@ end
171171
mul!(Array{T}(undef, p.plan.osz), p, copy(x)) # need copy to preserve input
172172

173173
*(p::DCTPlan{T,K,true}, x::StridedArray{T}) where {T,K} = mul!(x, p, x)
174+
175+
AbstractFFTs.AdjointStyle(::DCTPlan) = AbstractFFTs.UnitaryAdjointStyle()

src/fft.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,3 +1049,18 @@ function *(p::r2rFFTWPlan{T,K,true}, x::StridedArray{T}) where {T,K}
10491049
unsafe_execute!(p, x, x)
10501050
return x
10511051
end
1052+
1053+
#######################################################################
1054+
1055+
"""
1056+
R2RAdjointStyle(kinds)
1057+
1058+
Projection style for real to real transforms
1059+
"""
1060+
struct R2RAdjointStyle{K} <: AbstractFFTs.AdjointStyle
1061+
kinds::K
1062+
end
1063+
1064+
AbstractFFTs.AdjointStyle(::cFFTWPlan) = AbstractFFTs.FFTAdjointStyle()
1065+
AbstractFFTs.AdjointStyle(::rFFTWPlan{T, FORWARD}) where {T} = AbstractFFTs.RFFTAdjointStyle()
1066+
AbstractFFTs.AdjointStyle(P::rFFTWPlan{T, BACKWARD}) where {T} = AbstractFFTs.IRFFTAdjointStyle(P.osz[first(P.region)])

test/Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# A bug in Julia 1.6.0's Pkg causes Preferences to be dropped during `Pkg.test()`, so we work around
2-
# it by explicitly creating a `test/Project.toml` which will correctly communicate any preferences
3-
# through to the child Julia process. X-ref: https://github.com/JuliaLang/Pkg.jl/issues/2500
4-
51
[deps]
62
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
3+
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a"
4+
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
75
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
6+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
87
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

test/runtests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,3 +577,21 @@ end
577577
end
578578
end
579579
end
580+
581+
@testset "DCT adjoints" begin
582+
for x in (randn(3), randn(4), randn(3, 4), randn(3, 4, 5))
583+
y = randn(size(x))
584+
N = ndims(x)
585+
for dims in unique((1, 1:N, N))
586+
for P in (plan_dct(x, dims), plan_idct(x, dims))
587+
AbstractFFTs.TestUtils.test_plan_adjoint(P, x)
588+
end
589+
end
590+
end
591+
end
592+
593+
@testset "AbstractFFTs FFT backend tests" begin
594+
# note this also tests adjoint functionality for FFT plans
595+
AbstractFFTs.TestUtils.test_complex_ffts(Array)
596+
AbstractFFTs.TestUtils.test_real_ffts(Array; copy_input=true)
597+
end

0 commit comments

Comments
 (0)