Skip to content

Commit b338d52

Browse files
Expand tests
1 parent b1134f7 commit b338d52

File tree

1 file changed

+46
-9
lines changed

1 file changed

+46
-9
lines changed

test/vrspecials.jl

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,49 @@
22

33
@testset "vvmapreduce" begin
44
A = rand(5,5,5,5)
5-
@test vvmapreduce(abs2, +, A, dims=(1,3)) mapreduce(abs2, +, A, dims=(1,3))
6-
@test vvmapreduce(cos, *, A, dims=(2,4)) mapreduce(cos, *, A, dims=(2,4))
7-
@test vvprod(log, A, dims=1) prod(log, A, dims=1)
8-
@test vvminimum(sin, A, dims=(3,4)) minimum(sin, A, dims=(3,4))
9-
@test vvmaximum(sin, A, dims=(3,4)) maximum(sin, A, dims=(3,4))
5+
@testset "test reductions over region: $region" for region in Any[
6+
1, 2, 3, 4, 5, (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4),
7+
(1, 2, 3), (1, 3, 4), (2, 3, 4), (1, 2, 3, 4), :]
8+
@test vvmapreduce(abs2, +, A, dims=region) mapreduce(abs2, +, A, dims=region)
9+
@test vvmapreduce(cos, *, A, dims=region) mapreduce(cos, *, A, dims=region)
10+
@test vvprod(log, A, dims=region) prod(log, A, dims=region)
11+
@test vvminimum(sin, A, dims=region) minimum(sin, A, dims=region)
12+
@test vvmaximum(sin, A, dims=region) maximum(sin, A, dims=region)
13+
if region !== Colon()
14+
@test all((((x1, y1), (x2, y2)),) -> x1 x2 && y1 y2, zip(vvextrema(sin, A, dims=region), extrema(sin, A, dims=region)))
15+
else
16+
@test all(vvextrema(sin, A, dims=region) .≈ extrema(sin, A, dims=region))
17+
end
18+
end
1019
end
1120
@testset "vvmapreduce_vararg" begin
1221
A1 = rand(5,5,5,5)
1322
A2 = rand(5,5,5,5)
1423
A3 = rand(5,5,5,5)
1524
A4 = rand(1:10, 5,5,5,5)
1625
as = (A1, A2, A3)
17-
@test vvmapreduce(+, +, as, dims=(1,2,4)) mapreduce(+, +, A1, A2, A3, dims=(1,2,4))
18-
# Tests of variably typed arrays
19-
@test vvmapreduce(+, +, A1, A2, dims=(2,3,4)) mapreduce(+, +, A1, A2, dims=(2,3,4))
20-
@test vvmapreduce(+, +, A1, A4, dims=(2,3,4)) mapreduce(+, +, A1, A4, dims=(2,3,4))
26+
f3(x, y, z) = x * y + z
27+
f4(w, x, y, z) = inv(w) * exp(abs2(x - y) * z)
28+
@testset "test reductions over region: $region" for region in Any[
29+
1, 2, 3, 4, 5, (1, 2), (1, 3), (1, 4), (2, 3), (2, 4), (3, 4),
30+
(1, 2, 3), (1, 3, 4), (2, 3, 4), (1, 2, 3, 4), (1,2,3,4,5), :]
31+
@test vvmapreduce(+, +, as, dims=region) mapreduce(+, +, A1, A2, A3, dims=region)
32+
@test vvmapreduce(*, +, as, dims=region) mapreduce(*, +, A1, A2, A3, dims=region)
33+
@test vvmapreduce(+, *, as, dims=region) mapreduce(+, *, A1, A2, A3, dims=region)
34+
@test vvmapreduce(f3, *, as, dims=region) mapreduce(f3, *, A1, A2, A3, dims=region)
35+
36+
# slurping
37+
@test vvmapreduce(+, +, A1, A2, A3, dims=region) mapreduce(+, +, A1, A2, A3, dims=region)
38+
@test vvmapreduce(*, +, A1, A2, A3, dims=region) mapreduce(*, +, A1, A2, A3, dims=region)
39+
@test vvmapreduce(+, *, A1, A2, A3, dims=region) mapreduce(+, *, A1, A2, A3, dims=region)
40+
@test vvmapreduce(f3, *, A1, A2, A3, dims=region) mapreduce(f3, *, A1, A2, A3, dims=region)
41+
@test vvmapreduce(f4, *, A1, A2, A3, A3, dims=region) mapreduce(f4, *, A1, A2, A3, A3, dims=region)
42+
# Tests of variably typed arrays
43+
@test vvmapreduce(+, +, A1, A2, dims=region) mapreduce(+, +, A1, A2, dims=region)
44+
@test vvmapreduce(+, +, A1, A4, dims=region) mapreduce(+, +, A1, A4, dims=region)
45+
@test vvmapreduce(*, +, A1, A2, dims=region) mapreduce(*, +, A1, A2, dims=region)
46+
@test vvmapreduce(+, *, A1, A4, dims=region) mapreduce(+, *, A1, A4, dims=region)
47+
end
2148
# interface tests
2249
r = mapreduce(*, +, A1, A2, A3)
2350
@test r vvmapreduce(*, +, zero, A1, A2, A3)
@@ -113,4 +140,14 @@ end
113140
val1, ind1 = findmax(B′, dims=(2,4))
114141
val2, ind2 = vfindmax(h, B1, B2, B3, dims=(2,4))
115142
@test ind1 == ind2 && val1 val2
143+
144+
f3(x, y, z) = x * y + z
145+
@testset "test reductions over region: $region" for region in Any[
146+
2, 3, 4, 5, (1, 2), (2, 3), (2, 4), (3, 4),
147+
(2, 3), (3, 4), (2, 3, 4), (1, 2, 3, 4), (1,2,3,4,5), :]
148+
rval, rind = findmin(A′, dims=region)
149+
rval′, rind′ = vfindmin(f3, A1, A2, A3, dims=region)
150+
@test rval rval′
151+
@test rind == rind′
152+
end
116153
end

0 commit comments

Comments
 (0)