Skip to content

Commit b835f72

Browse files
Apply suggestions from code review
Co-authored-by: David Widmann <[email protected]>
1 parent 1dd7ea1 commit b835f72

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/TestUtils.jl

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,19 @@ function test_fft_backend(array_constructor; test_real=true, test_inplace=true)
7878
# FFT
7979
y = AbstractFFTs.fft(x_complex, dims)
8080
@test y fftw_fft
81-
test_inplace && (@test AbstractFFTs.fft!(copy(x_complex), dims) fftw_fft)
81+
if test_inplace
82+
@test AbstractFFTs.fft!(copy(x_complex), dims) fftw_fft
83+
end
8284
# test plan_fft and also inv and plan_inv of plan_ifft, which should all give
8385
# functionally identical plans
8486
plans_to_test = [plan_fft(x, dims), inv(plan_ifft(x, dims)),
8587
AbstractFFTs.plan_inv(plan_ifft(x, dims))]
8688
for P in plans_to_test
8789
@test mul!(similar(y), P, copy(x_complex)) fftw_fft
8890
end
89-
test_inplace && (plans_to_test = vcat(plans_to_test, plan_fft!(similar(x_complex), dims)))
91+
if test_inplace
92+
push!(plans_to_test, plan_fft!(similar(x_complex), dims))
93+
end
9094
for P in plans_to_test
9195
@test eltype(P) <: Complex
9296
@test P * copy(x_complex) fftw_fft
@@ -97,12 +101,16 @@ function test_fft_backend(array_constructor; test_real=true, test_inplace=true)
97101
# BFFT
98102
fftw_bfft = prod(size(x_complex, d) for d in dims) .* x_complex
99103
@test AbstractFFTs.bfft(y, dims) fftw_bfft
100-
test_inplace && (@test AbstractFFTs.bfft!(copy(y), dims) fftw_bfft)
101-
plans_to_test = [plan_bfft(similar(y), dims)]
102-
for P in plans_to_test
103-
@test mul!(similar(x_complex), P, copy(y)) fftw_bfft
104+
if test_inplace
105+
@test AbstractFFTs.bfft!(copy(y), dims) fftw_bfft
106+
end
107+
P = plan_bfft(similar(y), dims)
108+
@test mul!(similar(x_complex), P, copy(y)) fftw_bfft
109+
plans_to_test = if test_inplace
110+
[P, plan_bfft!(similar(y), dims)]
111+
else
112+
[P]
104113
end
105-
test_inplace && (plans_to_test = vcat(plans_to_test, plan_bfft!(similar(y), dims)))
106114
for P in plans_to_test
107115
@test eltype(P) <: Complex
108116
@test P * copy(y) fftw_bfft
@@ -113,13 +121,17 @@ function test_fft_backend(array_constructor; test_real=true, test_inplace=true)
113121
# IFFT
114122
fftw_ifft = x_complex
115123
@test AbstractFFTs.ifft(y, dims) fftw_ifft
116-
test_inplace && (@test AbstractFFTs.ifft!(copy(y), dims) fftw_ifft)
124+
if test_inplace
125+
@test AbstractFFTs.ifft!(copy(y), dims) fftw_ifft
126+
end
117127
plans_to_test = [plan_ifft(x, dims), inv(plan_fft(x, dims)),
118128
AbstractFFTs.plan_inv(plan_fft(x, dims))]
119129
for P in plans_to_test
120130
@test mul!(similar(x_complex), P, copy(y)) fftw_ifft
121131
end
122-
test_inplace && (plan_to_test = vcat(plans_to_test, plan_ifft!(similar(x_complex), dims)))
132+
if test_inplace
133+
push!(plans_to_test, plan_ifft!(similar(x_complex), dims))
134+
end
123135
for P in plans_to_test
124136
@test eltype(P) <: Complex
125137
@test P * copy(y) fftw_ifft
@@ -130,11 +142,7 @@ function test_fft_backend(array_constructor; test_real=true, test_inplace=true)
130142
if test_real && real_input
131143
x_real = float.(x) # for testing real FFTs
132144
# RFFT
133-
fftw_rfft = fftw_fft[
134-
(Colon() for _ in 1:(first(dims) - 1))...,
135-
1:(size(fftw_fft, first(dims)) ÷ 2 + 1),
136-
(Colon() for _ in (first(dims) + 1):ndims(fftw_fft))...
137-
]
145+
fftw_rfft = selectdim(fftw_fft, first(dims), 1:(size(fftw_fft, first(dims)) ÷ 2 + 1))
138146
ry = AbstractFFTs.rfft(x_real, dims)
139147
@test ry fftw_rfft
140148
for P in [plan_rfft(similar(x_real), dims), inv(plan_irfft(similar(ry), size(x, first(dims)), dims)),

0 commit comments

Comments
 (0)