Skip to content

Add accumulation tests #606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/testsuite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ include("testsuite/indexing.jl")
include("testsuite/base.jl")
include("testsuite/vector.jl")
include("testsuite/reductions.jl")
include("testsuite/accumulations.jl")
include("testsuite/broadcasting.jl")
include("testsuite/linalg.jl")
include("testsuite/math.jl")
Expand Down
94 changes: 94 additions & 0 deletions test/testsuite/accumulations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# @testsuite "accumulations" (AT, eltypes)->begin
@testsuite "accumulations" (AT, eltypes)->begin
@testset "$ET" for ET in eltypes
range = ET <: Real ? (ET(1):ET(10)) : ET

# 1d arrays
for num_elems in 1:256
@test compare(A->accumulate(+, A; init=zero(ET)), AT, rand(range, num_elems))
end

for num_elems = rand(1:100, 10)
@test compare(A->accumulate(+, A; init=zero(ET)), AT, rand(range, num_elems))
end

for _ in 1:10 # nd arrays reduced as 1d
n1 = rand(1:10)
n2 = rand(1:10)
n3 = rand(1:10)
@test compare(A->accumulate(+, A; init=zero(ET)), AT, rand(range, n1, n2, n3))
end

for num_elems = rand(1:100, 10) # init value
init = rand(range)
@test compare(A->accumulate(+, A; init), AT, rand(range, num_elems))
end


# nd arrays
for dims in 1:4 # corner cases
for isize in 1:3
for jsize in 1:3
for ksize in 1:3
@test compare(A->accumulate(+, A; dims, init=zero(ET)), AT, rand(range, isize, jsize, ksize))
end
end
end
end

for _ in 1:10
for dims in 1:3
n1 = rand(1:10)
n2 = rand(1:10)
n3 = rand(1:10)
@test compare(A->accumulate(+, A; dims, init=zero(ET)), AT, rand(range, n1, n2, n3))
end
end

for _ in 1:10 # init value
for dims in 1:3
n1 = rand(1:10)
n2 = rand(1:10)
n3 = rand(1:10)
init = rand(range)
@test compare(A->accumulate(+, A; init, dims), AT, rand(range, n1, n2, n3))
end
end
end
end

@testsuite "accumulations/cumsum & cumprod" (AT, eltypes)->begin
@test compare(cumsum, AT, rand(Bool, 16))

@testset "$ET" for ET in eltypes
range = ET <: Real ? (ET(1):ET(10)) : ET

# cumsum
for num_elems in rand(1:100, 10)
@test compare(A->cumsum(A; dims=1), AT, rand(range, num_elems))
end

for _ in 1:10
for dims in 1:3
n1 = rand(1:10)
n2 = rand(1:10)
n3 = rand(1:10)
@test compare(A->cumsum(A; dims), AT, rand(range, n1, n2, n3))
end
end


# cumprod
range = ET <: Real ? (ET(1):ET(10)) : ET
@test compare(A->cumprod(A; dims=1), AT, ones(ET, 100_000))

for _ in 1:10
for dims in 1:3
n1 = rand(1:10)
n2 = rand(1:10)
n3 = rand(1:10)
@test compare(A->cumprod(A; dims), AT, rand(range, n1, n2, n3))
end
end
end
end
Loading