forked from JuliaMath/FFTA.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargument_checking.jl
More file actions
147 lines (121 loc) · 5.26 KB
/
argument_checking.jl
File metadata and controls
147 lines (121 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using Test, FFTA
using LinearAlgebra: LinearAlgebra
@testset "Only 1D and 2D FFTs" begin
xr = zeros(2, 2, 2)
xc = complex(xr)
@test_throws ArgumentError("only supports 1D and 2D FFTs") plan_rfft(xr, 1:3)
@test_throws ArgumentError("only supports 1D and 2D FFTs") plan_brfft(xc, 2, 1:3)
end
@testset "mismatch between plan and array" begin
@testset "1D plan 1D array" begin
xr1 = randn(3)
yr1 = rfft(xr1)
xc1 = complex.(xr1)
xr1p = [xr1; 1]
xc1p = [xc1; 1]
yr1p = [yr1; 1]
@test_throws DimensionMismatch plan_fft(xc1) * xc1p
@test_throws DimensionMismatch plan_bfft(xc1) * xc1p
@test_throws DimensionMismatch plan_rfft(xr1) * xr1p
@test_throws DimensionMismatch plan_brfft(yr1, length(xr1)) * yr1p
@test_throws ArgumentError("only FFT_BACKWARD supported for complex vectors") plan_rfft(xr1) * xc1
@test_throws ArgumentError("only FFT_FORWARD supported for real vectors") plan_brfft(xc1, 5) * xr1
end
@testset "2D array" begin
xr2 = randn(3, 3)
xc2 = complex.(xr2)
xr2p = [[xr2; ones(1, size(xr2, 2))] ones(size(xr2, 1) + 1, 1)]
xc2p = [[xc2; ones(1, size(xr2, 2))] ones(size(xc2, 1) + 1, 1)]
@testset "1D plan, region=$(region)" for region in 1:2
yr2 = rfft(xr2, region)
yr2p = if region == 1
[yr2; ones(1, size(yr2, 2))]
else
[yr2 ones(size(yr2, 1), 1)]
end
@test_throws DimensionMismatch plan_fft(xc2, region) * xc2p
@test_throws DimensionMismatch plan_bfft(xc2, region) * xc2p
@test_throws DimensionMismatch plan_rfft(xr2, region) * xr2p
@test_throws DimensionMismatch plan_brfft(yr2, size(xr2, region), region) * yr2p
@test_throws ArgumentError("only FFT_BACKWARD supported for complex arrays") plan_rfft(xr2, region) * xc2
@test_throws ArgumentError("only FFT_FORWARD supported for real arrays") plan_brfft(xc2, 5, region) * xr2
end
@testset "2D plan" begin
yr2 = rfft(xr2)
yr2p = [yr2; ones(1, 3)]
@test_throws DimensionMismatch plan_fft(xc2) * xc2p
@test_throws DimensionMismatch plan_bfft(xc2) * xc2p
@test_throws DimensionMismatch plan_rfft(xr2) * xr2p
@test_throws DimensionMismatch plan_brfft(yr2, size(xr2, 1)) * yr2p
@test_throws ArgumentError("only FFT_BACKWARD supported for complex arrays") plan_rfft(xr2, 1:2) * xc2
@test_throws ArgumentError("only FFT_FORWARD supported for real arrays") plan_brfft(xc2, 5, 1:2) * xr2
end
end
@testset "3D array" begin
xc3 = randn(ComplexF64, 3, 3, 3)
yc3 = randn(ComplexF64, 5, 5, 5)
pxc3 = plan_fft(xc3)
@test_throws DimensionMismatch pxc3 * yc3
invalid_p = plan_fft(randn(ComplexF64, ntuple(i -> 3, 5)), 3:5)
xc4 = randn(ComplexF64, (1, ntuple(i -> 5, 3)...))
### plan region out of bounds
# all same dims
@test_throws DimensionMismatch("Plan region is outside array dimensions.") invalid_p * xc3
# dim(p) < dim(out) = dim(in)
@test_throws DimensionMismatch("Plan region is outside array dimensions.") LinearAlgebra.mul!(xc4, invalid_p, xc4)
end
end
@testset "mismatch between input and output arrays" begin
@testset "1D plan 1D array" begin
x1 = randn(ComplexF64, 3)
y1 = similar(x1, length(x1) + 1)
@test_throws DimensionMismatch LinearAlgebra.mul!(y1, plan_fft(x1), x1)
end
@testset "$(N)D array" for N in 2:4
xN = randn(ComplexF64, ntuple(i -> 3, N))
yN = similar(xN, size(xN) .+ 1)
@testset "1D plan, region=$(region)" for region in 1:N
@test_throws DimensionMismatch LinearAlgebra.mul!(yN, plan_fft(xN, region), xN)
end
@testset "$(N)D plan" begin
@test_throws DimensionMismatch LinearAlgebra.mul!(yN, plan_fft(xN), xN)
@test_throws DimensionMismatch LinearAlgebra.mul!(yN, plan_fft(xN, 1:N-1), xN)
end
end
end
@testset "Plan Base.size" begin
@testset "plan_fft" for sz in ((103,), (8, 11), (6, 24, 25))
x_c = rand(ComplexF64, sz)
p_c = plan_fft(x_c)
@test size(p_c) == sz
@test size(p_c, 1 + length(sz)) == 1
@test_throws DomainError size(p_c, 0)
@test_throws DomainError size(p_c, -1)
end
@testset "plan_rfft" for sz in ((103,), (8, 11))
x_r = rand(Float64, sz)
p_r = plan_rfft(x_r)
@test size(p_r) == sz
@test size(p_r, 1 + length(sz)) == 1
@test_throws DomainError size(p_r, 0)
@test_throws DomainError size(p_r, -1)
end
end
@testset "Invalid / mutated dims" verbose=true begin
@testset "Extra elements" begin
for n in 3:5
x = rand(ComplexF64, ntuple(i -> 2, n))
p1 = plan_fft(x, [1:n-1;])
push!(p1.region, n)
@test_throws DimensionMismatch("Region is invalid.") p1 * x
end
end
@testset "Unsorted dims" begin
for n in 3:5
x = rand(ComplexF64, ntuple(i -> 2, n))
p2 = plan_fft(x, [1:n-1;])
p2.region[1:2] = [2, 1]
@test_throws DimensionMismatch("Region is invalid.") p2 * x
end
end
end