@@ -6,6 +6,7 @@ using AbstractFFTs
6
6
using AbstractFFTs: TestUtils
7
7
using AbstractFFTs. LinearAlgebra
8
8
using Test
9
+ import Random
9
10
10
11
# Ground truth x_fft computed using FFTW library
11
12
const TEST_CASES = (
@@ -52,7 +53,8 @@ const TEST_CASES = (
52
53
)
53
54
54
55
55
- function TestUtils. test_plan (P:: AbstractFFTs.Plan , x:: AbstractArray , x_transformed:: AbstractArray ; inplace_plan= false , copy_input= false )
56
+ function TestUtils. test_plan (P:: AbstractFFTs.Plan , x:: AbstractArray , x_transformed:: AbstractArray ;
57
+ inplace_plan= false , copy_input= false , test_wrappers= true )
56
58
_copy = copy_input ? copy : identity
57
59
@test size (P) == size (x)
58
60
if ! inplace_plan
@@ -61,7 +63,9 @@ function TestUtils.test_plan(P::AbstractFFTs.Plan, x::AbstractArray, x_transform
61
63
_x_out = similar (P * _copy (x))
62
64
@test mul! (_x_out, P, _copy (x)) ≈ x_transformed
63
65
@test _x_out ≈ x_transformed
64
- @test P * view (_copy (x), axes (x)... ) ≈ x_transformed # test view input
66
+ if test_wrappers
67
+ @test P * view (_copy (x), axes (x)... ) ≈ x_transformed # test view input
68
+ end
65
69
else
66
70
_x = copy (x)
67
71
@test P * _copy (_x) ≈ x_transformed
@@ -71,9 +75,10 @@ function TestUtils.test_plan(P::AbstractFFTs.Plan, x::AbstractArray, x_transform
71
75
end
72
76
end
73
77
74
- function TestUtils. test_plan_adjoint (P:: AbstractFFTs.Plan , x:: AbstractArray ; real_plan= false , copy_input= false )
78
+ function TestUtils. test_plan_adjoint (P:: AbstractFFTs.Plan , x:: AbstractArray ;
79
+ real_plan= false , copy_input= false , test_wrappers= true )
75
80
_copy = copy_input ? copy : identity
76
- y = rand ( eltype ( P * _copy (x)), size (P * _copy (x) ))
81
+ y = Random . rand! ( P * _copy (x))
77
82
# test basic properties
78
83
@test eltype (P' ) === eltype (y)
79
84
@test (P' )' === P # test adjoint of adjoint
@@ -87,11 +92,13 @@ function TestUtils.test_plan_adjoint(P::AbstractFFTs.Plan, x::AbstractArray; rea
87
92
@test _component_dot (y, P * _copy (x)) ≈ _component_dot (P' * _copy (y), x)
88
93
@test _component_dot (x, P \ _copy (y)) ≈ _component_dot (P' \ _copy (x), y)
89
94
end
90
- @test P' * view (_copy (y), axes (y)... ) ≈ P' * _copy (y) # test view input (AbstractFFTs.jl#112)
95
+ if test_wrappers
96
+ @test P' * view (_copy (y), axes (y)... ) ≈ P' * _copy (y) # test view input (AbstractFFTs.jl#112)
97
+ end
91
98
@test_throws MethodError mul! (x, P' , y)
92
99
end
93
100
94
- function TestUtils. test_complex_ffts (ArrayType= Array; test_inplace= true , test_adjoint= true )
101
+ function TestUtils. test_complex_ffts (ArrayType= Array; test_inplace= true , test_adjoint= true , test_wrappers = true )
95
102
@testset " correctness of fft, bfft, ifft" begin
96
103
for test_case in TEST_CASES
97
104
_x, dims, _x_fft = copy (test_case. x), test_case. dims, copy (test_case. x_fft)
@@ -111,18 +118,18 @@ function TestUtils.test_complex_ffts(ArrayType=Array; test_inplace=true, test_ad
111
118
for P in (plan_fft (similar (x_complexf), dims),
112
119
(_inv (plan_ifft (similar (x_complexf), dims)) for _inv in (inv, AbstractFFTs. plan_inv)). .. )
113
120
@test eltype (P) <: Complex
114
- @test fftdims (P) == dims
115
- TestUtils. test_plan (P, x_complexf, x_fft)
121
+ @test collect ( fftdims (P))[:] == collect ( dims)[:] # compare as iterables
122
+ TestUtils. test_plan (P, x_complexf, x_fft; test_wrappers = test_wrappers )
116
123
if test_adjoint
117
124
@test fftdims (P' ) == fftdims (P)
118
- TestUtils. test_plan_adjoint (P, x_complexf)
125
+ TestUtils. test_plan_adjoint (P, x_complexf, test_wrappers = test_wrappers )
119
126
end
120
127
end
121
128
if test_inplace
122
129
# test IIP plans
123
130
for P in (plan_fft! (similar (x_complexf), dims),
124
131
(_inv (plan_ifft! (similar (x_complexf), dims)) for _inv in (inv, AbstractFFTs. plan_inv)). .. )
125
- TestUtils. test_plan (P, x_complexf, x_fft; inplace_plan= true )
132
+ TestUtils. test_plan (P, x_complexf, x_fft; inplace_plan= true , test_wrappers = test_wrappers )
126
133
end
127
134
end
128
135
@@ -137,17 +144,17 @@ function TestUtils.test_complex_ffts(ArrayType=Array; test_inplace=true, test_ad
137
144
# test OOP plans. Just 1 plan to test, but we use a for loop for consistent style
138
145
for P in (plan_bfft (similar (x_fft), dims),)
139
146
@test eltype (P) <: Complex
140
- @test fftdims (P) == dims
141
- TestUtils. test_plan (P, x_fft, x_scaled)
147
+ @test collect ( fftdims (P))[:] == collect ( dims)[:] # compare as iterables
148
+ TestUtils. test_plan (P, x_fft, x_scaled; test_wrappers = test_wrappers )
142
149
if test_adjoint
143
- TestUtils. test_plan_adjoint (P, x_fft)
150
+ TestUtils. test_plan_adjoint (P, x_fft, test_wrappers = test_wrappers )
144
151
end
145
152
end
146
153
# test IIP plans
147
154
for P in (plan_bfft! (similar (x_fft), dims),)
148
155
@test eltype (P) <: Complex
149
- @test fftdims (P) == dims
150
- TestUtils. test_plan (P, x_fft, x_scaled; inplace_plan= true )
156
+ @test collect ( fftdims (P))[:] == collect ( dims)[:] # compare as iterables
157
+ TestUtils. test_plan (P, x_fft, x_scaled; inplace_plan= true , test_wrappers = test_wrappers )
151
158
end
152
159
153
160
# IFFT
@@ -161,33 +168,33 @@ function TestUtils.test_complex_ffts(ArrayType=Array; test_inplace=true, test_ad
161
168
for P in (plan_ifft (similar (x_complexf), dims),
162
169
(_inv (plan_fft (similar (x_complexf), dims)) for _inv in (inv, AbstractFFTs. plan_inv)). .. )
163
170
@test eltype (P) <: Complex
164
- @test fftdims (P) == dims
165
- TestUtils. test_plan (P, x_fft, x)
171
+ @test collect ( fftdims (P))[:] == collect ( dims)[:] # compare as iterables
172
+ TestUtils. test_plan (P, x_fft, x; test_wrappers = test_wrappers )
166
173
if test_adjoint
167
- TestUtils. test_plan_adjoint (P, x_fft)
174
+ TestUtils. test_plan_adjoint (P, x_fft; test_wrappers = test_wrappers )
168
175
end
169
176
end
170
177
# test IIP plans
171
178
if test_inplace
172
179
for P in (plan_ifft! (similar (x_complexf), dims),
173
180
(_inv (plan_fft! (similar (x_complexf), dims)) for _inv in (inv, AbstractFFTs. plan_inv)). .. )
174
181
@test eltype (P) <: Complex
175
- @test fftdims (P) == dims
176
- TestUtils. test_plan (P, x_fft, x; inplace_plan= true )
182
+ @test collect ( fftdims (P))[:] == collect ( dims)[:] # compare as iterables
183
+ TestUtils. test_plan (P, x_fft, x; inplace_plan= true , test_wrappers = test_wrappers )
177
184
end
178
185
end
179
186
end
180
187
end
181
188
end
182
189
183
- function TestUtils. test_real_ffts (ArrayType= Array; test_adjoint= true , copy_input= false )
190
+ function TestUtils. test_real_ffts (ArrayType= Array; test_adjoint= true , copy_input= false , test_wrappers = true )
184
191
@testset " correctness of rfft, brfft, irfft" begin
185
192
for test_case in TEST_CASES
186
193
_x, dims, _x_fft = copy (test_case. x), test_case. dims, copy (test_case. x_fft)
187
194
x = convert (ArrayType, _x) # dummy array that will be passed to plans
188
195
x_real = float .(x) # for testing mutating real FFTs
189
196
x_fft = convert (ArrayType, _x_fft)
190
- x_rfft = collect (selectdim (x_fft, first (dims), 1 : (size (x_fft, first (dims)) ÷ 2 + 1 )))
197
+ x_rfft = convert (ArrayType, collect (selectdim (x_fft, first (dims), 1 : (size (x_fft, first (dims)) ÷ 2 + 1 ) )))
191
198
192
199
if ! (eltype (x) <: Real )
193
200
continue
@@ -198,10 +205,10 @@ function TestUtils.test_real_ffts(ArrayType=Array; test_adjoint=true, copy_input
198
205
for P in (plan_rfft (similar (x_real), dims),
199
206
(_inv (plan_irfft (similar (x_rfft), size (x, first (dims)), dims)) for _inv in (inv, AbstractFFTs. plan_inv)). .. )
200
207
@test eltype (P) <: Real
201
- @test fftdims (P) == dims
202
- TestUtils. test_plan (P, x_real, x_rfft; copy_input= copy_input)
208
+ @test collect ( fftdims (P))[:] == collect ( dims)[:] # compare as iterables
209
+ TestUtils. test_plan (P, x_real, x_rfft; copy_input= copy_input, test_wrappers = test_wrappers )
203
210
if test_adjoint
204
- TestUtils. test_plan_adjoint (P, x_real; real_plan= true , copy_input= copy_input)
211
+ TestUtils. test_plan_adjoint (P, x_real; real_plan= true , copy_input= copy_input, test_wrappers = test_wrappers )
205
212
end
206
213
end
207
214
@@ -210,10 +217,10 @@ function TestUtils.test_real_ffts(ArrayType=Array; test_adjoint=true, copy_input
210
217
@test brfft (x_rfft, size (x, first (dims)), dims) ≈ x_scaled
211
218
for P in (plan_brfft (similar (x_rfft), size (x, first (dims)), dims),)
212
219
@test eltype (P) <: Complex
213
- @test fftdims (P) == dims
214
- TestUtils. test_plan (P, x_rfft, x_scaled; copy_input= copy_input)
220
+ @test collect ( fftdims (P))[:] == collect ( dims)[:] # compare as iterables
221
+ TestUtils. test_plan (P, x_rfft, x_scaled; copy_input= copy_input, test_wrappers = test_wrappers )
215
222
if test_adjoint
216
- TestUtils. test_plan_adjoint (P, x_rfft; real_plan= true , copy_input= copy_input)
223
+ TestUtils. test_plan_adjoint (P, x_rfft; real_plan= true , copy_input= copy_input, test_wrappers = test_wrappers )
217
224
end
218
225
end
219
226
@@ -222,10 +229,10 @@ function TestUtils.test_real_ffts(ArrayType=Array; test_adjoint=true, copy_input
222
229
for P in (plan_irfft (similar (x_rfft), size (x, first (dims)), dims),
223
230
(_inv (plan_rfft (similar (x_real), dims)) for _inv in (inv, AbstractFFTs. plan_inv)). .. )
224
231
@test eltype (P) <: Complex
225
- @test fftdims (P) == dims
226
- TestUtils. test_plan (P, x_rfft, x; copy_input= copy_input)
232
+ @test collect ( fftdims (P))[:] == collect ( dims)[:] # compare as iterables
233
+ TestUtils. test_plan (P, x_rfft, x; copy_input= copy_input, test_wrappers = test_wrappers )
227
234
if test_adjoint
228
- TestUtils. test_plan_adjoint (P, x_rfft; real_plan= true , copy_input= copy_input)
235
+ TestUtils. test_plan_adjoint (P, x_rfft; real_plan= true , copy_input= copy_input, test_wrappers = test_wrappers )
229
236
end
230
237
end
231
238
end
0 commit comments