Skip to content

Commit a0115fb

Browse files
committed
Add some allocation tests
1 parent 8d65144 commit a0115fb

File tree

8 files changed

+132
-95
lines changed

8 files changed

+132
-95
lines changed

test/onedim/complex_backward.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
using FFTA, Test
2-
test_nums = [8, 11, 15, 16, 27, 100]
3-
@testset "backward" begin
4-
for N in test_nums
5-
x = ones(ComplexF64, N)
6-
y = bfft(x)
7-
y_ref = 0*y
8-
y_ref[1] = N
9-
@test y y_ref atol=1e-12
10-
end
2+
3+
@testset "backward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4+
x = ones(ComplexF64, N)
5+
y = bfft(x)
6+
y_ref = 0*y
7+
y_ref[1] = N
8+
@test y y_ref atol=1e-12
119
end
1210

13-
@testset verbose = true "against naive implementation. Size: $n" for n in 1:64
11+
@testset "More backward tests. Size: $n" for n in 1:64
1412
x = complex.(randn(n), randn(n))
15-
@test naive_1d_fourier_transform(x, FFTA.FFT_BACKWARD) bfft(x)
13+
14+
@testset "against naive implementation" begin
15+
@test naive_1d_fourier_transform(x, FFTA.FFT_BACKWARD) bfft(x)
16+
end
17+
18+
@testset "allocation" begin
19+
@test (@allocations bfft(x)) <= 44
20+
end
1621
end
1722

1823
@testset "error messages" begin

test/onedim/complex_forward.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
using FFTA, Test
2-
test_nums = [8, 11, 15, 16, 27, 100]
3-
@testset verbose = true " forward" begin
4-
for N in test_nums
5-
x = ones(ComplexF64, N)
6-
y = fft(x)
7-
y_ref = 0*y
8-
y_ref[1] = N
9-
@test y y_ref atol=1e-12
10-
end
2+
3+
@testset verbose = true " forward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4+
x = ones(ComplexF64, N)
5+
y = fft(x)
6+
y_ref = 0*y
7+
y_ref[1] = N
8+
@test y y_ref atol=1e-12
119
end
1210

13-
@testset verbose = true "against naive implementation. Size: $n" for n in 1:64
11+
@testset "More forward tests. Size: $n" for n in 1:64
1412
x = complex.(randn(n), randn(n))
15-
@test naive_1d_fourier_transform(x, FFTA.FFT_FORWARD) fft(x)
13+
14+
@testset "against naive implementation" begin
15+
@test naive_1d_fourier_transform(x, FFTA.FFT_FORWARD) fft(x)
16+
end
17+
18+
@testset "allocation" begin
19+
@test (@allocations fft(x)) <= 44
20+
end
1621
end
1722

1823
@testset "error messages" begin

test/onedim/real_backward.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
using FFTA, Test, LinearAlgebra
2-
test_nums = [8, 11, 15, 16, 27, 100]
3-
@testset "backward" begin
4-
for N in test_nums
5-
x = ones(Float64, N)
6-
y = brfft(x, 2*(N-1))
7-
y_ref = 0*y
8-
y_ref[1] = 2*(N-1)
9-
if !isapprox(y_ref, y, atol=1e-12)
10-
println(norm(y_ref - y))
11-
end
12-
@test y_ref y atol=1e-12
2+
3+
@testset "backward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4+
x = ones(Float64, N)
5+
y = brfft(x, 2*(N-1))
6+
y_ref = 0*y
7+
y_ref[1] = 2*(N-1)
8+
if !isapprox(y_ref, y, atol=1e-12)
9+
println(norm(y_ref - y))
1310
end
11+
@test y_ref y atol=1e-12
1412
end
1513

16-
@testset verbose = true "against naive implementation. Size: $n" for n in 1:64
14+
@testset "More backward tests. Size: $n" for n in 1:64
1715
x = complex.(randn(n ÷ 2 + 1), randn(n ÷ 2 + 1))
1816
x[begin] = real(x[begin])
1917
if iseven(n)
@@ -22,7 +20,14 @@ end
2220
else
2321
xe = [x; conj.(reverse(x[begin + 1:end]))]
2422
end
25-
@test naive_1d_fourier_transform(xe, FFTA.FFT_BACKWARD) brfft(x, n)
23+
24+
@testset "against naive implementation" begin
25+
@test naive_1d_fourier_transform(xe, FFTA.FFT_BACKWARD) brfft(x, n)
26+
end
27+
28+
@testset "allocation" begin
29+
@test (@allocations brfft(x, n)) <= 50
30+
end
2631
end
2732

2833
@testset "error messages" begin

test/onedim/real_forward.jl

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
using FFTA, Test
2-
test_nums = [8, 11, 15, 16, 27, 100]
3-
@testset verbose = true " forward" begin
4-
for N in test_nums
5-
x = ones(Float64, N)
6-
y = rfft(x)
7-
y_ref = 0*y
8-
y_ref[1] = N
9-
@test y y_ref atol=1e-12
10-
end
2+
3+
@testset verbose = true " forward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4+
x = ones(Float64, N)
5+
y = rfft(x)
6+
y_ref = 0*y
7+
y_ref[1] = N
8+
@test y y_ref atol=1e-12
119
end
1210

13-
@testset verbose = true "against naive implementation. Size: $n" for n in 1:64
11+
@testset "More forward tests. Size: $n" for n in 1:64
1412
x = randn(n)
15-
y = rfft(x)
16-
@test naive_1d_fourier_transform(x, FFTA.FFT_FORWARD)[1:(n ÷ 2 + 1)] y
1713

18-
@testset "temporarily test real dft separately until used by rfft" begin
19-
y_dft = similar(y)
20-
FFTA.fft_dft!(y_dft, x, n, 1, 1, 1, 1, cispi(-2/n))
21-
@test y y_dft
14+
@testset "against naive implementation" begin
15+
y = rfft(x)
16+
@test naive_1d_fourier_transform(x, FFTA.FFT_FORWARD)[1:(n ÷ 2 + 1)] y
17+
18+
@testset "temporarily test real dft separately until used by rfft" begin
19+
y_dft = similar(y)
20+
FFTA.fft_dft!(y_dft, x, n, 1, 1, 1, 1, cispi(-2/n))
21+
@test y y_dft
22+
end
23+
end
24+
25+
@testset "allocation" begin
26+
@test (@allocations rfft(x)) <= 48
2227
end
2328
end
2429

test/twodim/complex_backward.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
using FFTA, Test
2-
test_nums = [8, 11, 15, 16, 27, 100]
3-
@testset "backward" begin
4-
for N in test_nums
5-
x = ones(ComplexF64, N, N)
6-
y = bfft(x)
7-
y_ref = 0*y
8-
y_ref[1] = length(x)
9-
@test y y_ref
10-
end
2+
3+
@testset "backward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4+
x = ones(ComplexF64, N, N)
5+
y = bfft(x)
6+
y_ref = 0*y
7+
y_ref[1] = length(x)
8+
@test y y_ref
119
end
1210

13-
@testset verbose = true "against naive implementation" for n in 1:64
11+
@testset "More backward tests" for n in 1:64
1412
@testset "size: ($m, $n)" for m in n:(n + 1)
1513
X = complex.(randn(m, n), randn(m, n))
16-
Y = similar(X)
17-
@test naive_2d_fourier_transform(X, FFTA.FFT_BACKWARD) bfft(X)
14+
15+
@testset "against naive implementation" begin
16+
@test naive_2d_fourier_transform(X, FFTA.FFT_BACKWARD) bfft(X)
17+
end
18+
19+
@testset "allocations" begin
20+
@test (@allocations bfft(X)) <= 111
21+
end
1822
end
1923
end
2024

test/twodim/complex_forward.jl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
using FFTA, Test
2-
test_nums = [8, 11, 15, 16, 27, 100]
3-
@testset " forward" begin
4-
for N in test_nums
5-
x = ones(ComplexF64, N, N)
6-
y = fft(x)
7-
y_ref = 0*y
8-
y_ref[1] = length(x)
9-
@test y y_ref
10-
end
2+
3+
@testset " forward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4+
x = ones(ComplexF64, N, N)
5+
y = fft(x)
6+
y_ref = 0*y
7+
y_ref[1] = length(x)
8+
@test y y_ref
119
end
1210

13-
@testset verbose = true "against naive implementation" for n in 1:64
11+
@testset "More forward tests" for n in 1:64
1412
@testset "size: ($m, $n)" for m in n:(n + 1)
1513
X = complex.(randn(m, n), randn(m, n))
16-
Y = similar(X)
17-
@test naive_2d_fourier_transform(X, FFTA.FFT_FORWARD) fft(X)
14+
15+
@testset "against naive implementation" begin
16+
@test naive_2d_fourier_transform(X, FFTA.FFT_FORWARD) fft(X)
17+
end
18+
19+
@testset "allocations" begin
20+
@test (@allocations fft(X)) <= 111
21+
end
1822
end
1923
end
2024

test/twodim/real_backward.jl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
using FFTA, Test
2-
test_nums = [8]
3-
@testset "backward" begin
4-
for N in test_nums
5-
x = ones(Float64, N, N)
6-
y = brfft(x, 2(N-1))
7-
y_ref = 0*y
8-
y_ref[1] = N*(2(N-1))
9-
@test y_ref y atol=1e-12
10-
end
11-
end
2+
3+
@testset "backward. N=$N" for N in [8]
4+
x = ones(Float64, N, N)
5+
y = brfft(x, 2(N-1))
6+
y_ref = 0*y
7+
y_ref[1] = N*(2(N-1))
8+
@test y_ref y atol=1e-12
9+
end
10+
11+
@testset "allocations" begin
12+
X = randn(256, 256)
13+
rfft(X) # compile
14+
@test (@allocations rfft(X)) <= 51
15+
end

test/twodim/real_forward.jl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
using FFTA, Test
2-
test_nums = [8, 11, 15, 16, 27, 100]
3-
@testset " forward" begin
4-
for N in test_nums
5-
x = ones(Float64, N, N)
6-
y = rfft(x)
7-
y_ref = 0*y
8-
y_ref[1] = length(x)
9-
@test y y_ref
10-
end
11-
end
2+
3+
@testset " forward. N=$N" for N in [8, 11, 15, 16, 27, 100]
4+
x = ones(Float64, N, N)
5+
y = rfft(x)
6+
y_ref = 0*y
7+
y_ref[1] = length(x)
8+
@test y y_ref
9+
end
10+
11+
@testset "allocations" begin
12+
X = randn(256, 256)
13+
Y = rfft(X)
14+
brfft(Y, 256) # compile
15+
@test (@allocations brfft(Y, 256)) <= 54
16+
end

0 commit comments

Comments
 (0)