@@ -10,22 +10,12 @@ using AbstractFFTs: Plan
10
10
using LinearAlgebra
11
11
using Test
12
12
13
- import Unitful
14
-
15
- function test_fft_backend ()
16
- @testset " rfft sizes" begin
17
- A = rand (11 , 10 )
18
- @test @inferred (AbstractFFTs. rfft_output_size (A, 1 )) == (6 , 10 )
19
- @test @inferred (AbstractFFTs. rfft_output_size (A, 2 )) == (11 , 6 )
20
- A1 = rand (6 , 10 ); A2 = rand (11 , 6 )
21
- @test @inferred (AbstractFFTs. brfft_output_size (A1, 11 , 1 )) == (11 , 10 )
22
- @test @inferred (AbstractFFTs. brfft_output_size (A2, 10 , 2 )) == (11 , 10 )
23
- @test_throws AssertionError AbstractFFTs. brfft_output_size (A1, 10 , 2 )
24
- end
25
-
13
+ """
14
+ """
15
+ function test_fft_backend (array_constructor)
26
16
@testset " fft correctness" begin
27
17
# DFT along last dimension, results computed using FFTW
28
- for (x, fftw_fft ) in (
18
+ for (_x, _fftw_fft ) in (
29
19
(collect (1 : 7 ),
30
20
[28.0 + 0.0im ,
31
21
- 3.5 + 7.267824888003178im ,
@@ -51,6 +41,9 @@ function test_fft_backend()
51
41
15.0 + 0.0im - 4.5 + 2.598076211353316im - 4.5 - 2.598076211353316im ;
52
42
18.0 + 0.0im - 4.5 + 2.598076211353316im - 4.5 - 2.598076211353316im ]),
53
43
)
44
+ x = array_constructor (_x)
45
+ fftw_fft = array_constructor (_fftw_fft)
46
+
54
47
# FFT
55
48
dims = ndims (x)
56
49
y = AbstractFFTs. fft (x, dims)
@@ -59,39 +52,37 @@ function test_fft_backend()
59
52
# functionally identical plans
60
53
for P in [plan_fft (x, dims), inv (plan_ifft (x, dims)),
61
54
AbstractFFTs. plan_inv (plan_ifft (x, dims))]
62
- @test eltype (P) === ComplexF64
55
+ @test eltype (P) <: Complex
63
56
@test P * x ≈ fftw_fft
64
57
@test P \ (P * x) ≈ x
65
58
@test fftdims (P) == dims
66
59
end
67
60
61
+ # BFFT
68
62
fftw_bfft = complex .(size (x, dims) .* x)
69
63
@test AbstractFFTs. bfft (y, dims) ≈ fftw_bfft
70
64
P = plan_bfft (x, dims)
71
65
@test P * y ≈ fftw_bfft
72
66
@test P \ (P * y) ≈ y
73
67
@test fftdims (P) == dims
74
68
69
+ # IFFT
75
70
fftw_ifft = complex .(x)
76
71
@test AbstractFFTs. ifft (y, dims) ≈ fftw_ifft
77
- # test plan_ifft and also inv and plan_inv of plan_fft, which should all give
78
- # functionally identical plans
79
72
for P in [plan_ifft (x, dims), inv (plan_fft (x, dims)),
80
73
AbstractFFTs. plan_inv (plan_fft (x, dims))]
81
74
@test P * y ≈ fftw_ifft
82
75
@test P \ (P * y) ≈ y
83
76
@test fftdims (P) == dims
84
77
end
85
78
86
- # real FFT
79
+ # RFFT
87
80
fftw_rfft = fftw_fft[
88
81
(Colon () for _ in 1 : (ndims (fftw_fft) - 1 )). .. ,
89
82
1 : (size (fftw_fft, ndims (fftw_fft)) ÷ 2 + 1 )
90
83
]
91
84
ry = AbstractFFTs. rfft (x, dims)
92
85
@test ry ≈ fftw_rfft
93
- # test plan_rfft and also inv and plan_inv of plan_irfft, which should all give
94
- # functionally identical plans
95
86
for P in [plan_rfft (x, dims), inv (plan_irfft (ry, size (x, dims), dims)),
96
87
AbstractFFTs. plan_inv (plan_irfft (ry, size (x, dims), dims))]
97
88
@test eltype (P) <: Real
@@ -100,17 +91,17 @@ function test_fft_backend()
100
91
@test fftdims (P) == dims
101
92
end
102
93
94
+ # BRFFT
103
95
fftw_brfft = complex .(size (x, dims) .* x)
104
96
@test AbstractFFTs. brfft (ry, size (x, dims), dims) ≈ fftw_brfft
105
97
P = plan_brfft (ry, size (x, dims), dims)
106
98
@test P * ry ≈ fftw_brfft
107
99
@test P \ (P * ry) ≈ ry
108
100
@test fftdims (P) == dims
109
101
102
+ # IRFFT
110
103
fftw_irfft = complex .(x)
111
104
@test AbstractFFTs. irfft (ry, size (x, dims), dims) ≈ fftw_irfft
112
- # test plan_rfft and also inv and plan_inv of plan_irfft, which should all give
113
- # functionally identical plans
114
105
for P in [plan_irfft (ry, size (x, dims), dims), inv (plan_rfft (x, dims)),
115
106
AbstractFFTs. plan_inv (plan_rfft (x, dims))]
116
107
@test P * ry ≈ fftw_irfft
0 commit comments