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