Skip to content

Commit 38a0a8b

Browse files
christiangnrdmaleadt
authored andcommitted
Add accumulation tests
1 parent 4b5f6cb commit 38a0a8b

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

test/testsuite.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ include("testsuite/indexing.jl")
8888
include("testsuite/base.jl")
8989
include("testsuite/vector.jl")
9090
include("testsuite/reductions.jl")
91+
include("testsuite/accumulations.jl")
9192
include("testsuite/broadcasting.jl")
9293
include("testsuite/linalg.jl")
9394
include("testsuite/math.jl")

test/testsuite/accumulations.jl

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# @testsuite "accumulations" (AT, eltypes)->begin
2+
@testsuite "accumulations" (AT, eltypes)->begin
3+
@testset "$ET" for ET in eltypes
4+
range = ET <: Real ? (ET(1):ET(10)) : ET
5+
6+
# 1d arrays
7+
for num_elems in 1:256
8+
@test compare(A->accumulate(+, A; init=zero(ET)), AT, rand(range, num_elems))
9+
end
10+
11+
for num_elems = rand(1:100, 10)
12+
@test compare(A->accumulate(+, A; init=zero(ET)), AT, rand(range, num_elems))
13+
end
14+
15+
for _ in 1:10 # nd arrays reduced as 1d
16+
n1 = rand(1:10)
17+
n2 = rand(1:10)
18+
n3 = rand(1:10)
19+
@test compare(A->accumulate(+, A; init=zero(ET)), AT, rand(range, n1, n2, n3))
20+
end
21+
22+
for num_elems = rand(1:100, 10) # init value
23+
init = rand(range)
24+
@test compare(A->accumulate(+, A; init), AT, rand(range, num_elems))
25+
end
26+
27+
28+
# nd arrays
29+
for dims in 1:4 # corner cases
30+
for isize in 1:3
31+
for jsize in 1:3
32+
for ksize in 1:3
33+
@test compare(A->accumulate(+, A; dims, init=zero(ET)), AT, rand(range, isize, jsize, ksize))
34+
end
35+
end
36+
end
37+
end
38+
39+
for _ in 1:10
40+
for dims in 1:3
41+
n1 = rand(1:10)
42+
n2 = rand(1:10)
43+
n3 = rand(1:10)
44+
@test compare(A->accumulate(+, A; dims, init=zero(ET)), AT, rand(range, n1, n2, n3))
45+
end
46+
end
47+
48+
for _ in 1:10 # init value
49+
for dims in 1:3
50+
n1 = rand(1:10)
51+
n2 = rand(1:10)
52+
n3 = rand(1:10)
53+
init = rand(range)
54+
@test compare(A->accumulate(+, A; init, dims), AT, rand(range, n1, n2, n3))
55+
end
56+
end
57+
end
58+
end
59+
60+
@testsuite "accumulations/cumsum & cumprod" (AT, eltypes)->begin
61+
@test compare(cumsum, AT, rand(Bool, 16))
62+
63+
@testset "$ET" for ET in eltypes
64+
range = ET <: Real ? (ET(1):ET(10)) : ET
65+
66+
# cumsum
67+
for num_elems in rand(1:100, 10)
68+
@test compare(A->cumsum(A; dims=1), AT, rand(range, num_elems))
69+
end
70+
71+
for _ in 1:10
72+
for dims in 1:3
73+
n1 = rand(1:10)
74+
n2 = rand(1:10)
75+
n3 = rand(1:10)
76+
@test compare(A->cumsum(A; dims), AT, rand(range, n1, n2, n3))
77+
end
78+
end
79+
80+
81+
# cumprod
82+
range = ET <: Real ? (ET(1):ET(10)) : ET
83+
@test compare(A->cumprod(A; dims=1), AT, ones(ET, 100_000))
84+
85+
for _ in 1:10
86+
for dims in 1:3
87+
n1 = rand(1:10)
88+
n2 = rand(1:10)
89+
n3 = rand(1:10)
90+
@test compare(A->cumprod(A; dims), AT, rand(range, n1, n2, n3))
91+
end
92+
end
93+
end
94+
end

0 commit comments

Comments
 (0)