|
1 | 1 | # Assorted tests; TODO: systematic
|
2 |
| -xx = rand(ntuple(_ -> 3, 4)...); |
3 |
| -@timev R = vmapreducethen(abs2, +, √, xx, dims=(2,4)) |
4 |
| -@timev R2 = .√mapreduce(abs2, +, xx, dims=(2,4)) |
5 |
| -R ≈ R2 |
6 |
| - |
7 |
| -XX = rand(ntuple(_ -> 5, 4)...); |
8 |
| -@benchmark vmapreducethen(abs2, +, √, $XX, dims=(2,4)) |
9 |
| -@benchmark .√mapreduce(abs2, +, XX, dims=(2,4)) |
10 |
| - |
11 |
| -@benchmark vnorm3($x1, 2.0) |
12 |
| -@benchmark vnorm($x1, 1.5) |
13 |
| -@benchmark vnorm3($x1, 1.5) |
14 |
| - |
15 |
| - |
16 |
| -@benchmark vnorm($x1, 2.0) |
17 |
| -@benchmark norm($x1, 1.5) |
18 |
| -@benchmark vnorm($x1, 1) |
19 |
| -@benchmark vnorm2($x1, 1.5) |
20 |
| - |
21 |
| -vmean(x1, dims=(2,4)) |
22 |
| -@benchmark vmean($lpds, dims=(1,2)) |
23 |
| -@benchmark mean($lpds, dims=(1,2)) |
24 |
| - |
25 |
| -@benchmark veuclidean($x1, $x2) |
26 |
| -@benchmark norm($x1 .- $x2) |
27 |
| -@benchmark euclidean($x1, $x2) |
28 |
| -@test euclidean(x1, x2, dims=(2,4)) ≈ veuclidean(x1, x2, dims=(2,4)) |
29 |
| -@benchmark veuclidean($x1, $x2, dims=(2,4)) |
30 |
| -@benchmark euclidean($x1, $x2, dims=(2,4)) |
31 |
| - |
32 |
| -YY = rand(1:100, 3,3,3,3); |
33 |
| -xxx = rand(3,3,3,3); |
34 |
| - |
35 |
| -@benchmark vmapreducethen(abs2, +, abs2, $YY, dims=(2,4)) |
36 |
| -@benchmark vmapreducethen(abs2, +, abs2, $xxx, dims=(2,4)) |
37 |
| - |
38 |
| -abs2.(mapreduce(abs2, +, YY, dims=(2,4))) == vmapreducethen(abs2, +, abs2, YY, dims=(2,4)) |
39 |
| - |
40 |
| -@code_warntype _vmapreducethen!(abs2, +, abs2, zero, R, xxx, (static(2), static(4))) |
41 |
| - |
42 |
| -x1 = rand(5,5,5,5); |
43 |
| -x2 = rand(5,5,5,5); |
44 |
| -x3 = rand(5,5,5,5); |
45 |
| -@benchmark vmapreducethen(+, +, abs2, $x1, $x2, $x3) |
46 |
| -@benchmark abs2(mapreduce(+, +, $x1, $x2, $x3)) |
47 |
| -@test abs2(mapreduce(+, +, x1, x2, x3)) ≈ vmapreducethen(+, +, abs2, x1, x2, x3) |
48 |
| - |
49 |
| -@benchmark vmapreducethen(+, +, abs2, $x1, $x2, $x3, dims=(2,4)) |
50 |
| -@benchmark abs2.(mapreduce(+, +, $x1, $x2, $x3, dims=(2,4))) |
| 2 | +Random.seed!(0x9f164f673dbb3f65) |
| 3 | +@testset "Simple mapreduce with post-operator" begin |
| 4 | + xx = rand(ntuple(_ -> 3, 4)...); |
| 5 | + R = vmapreducethen(abs2, +, √, xx, dims=(2,4)) |
| 6 | + R2 = .√mapreduce(abs2, +, xx, dims=(2,4)) |
| 7 | + @test R ≈ R2 |
| 8 | +end |
| 9 | + |
| 10 | +@testset "mapreducethen, varargs" begin |
| 11 | + x = rand(5,5,5,5); |
| 12 | + y = rand(5,5,5,5); |
| 13 | + z = rand(5,5,5,5); |
| 14 | + @test vmapreducethen(+, +, abs2, x, y, z) ≈ abs2(mapreduce(+, +, x, y, z)) |
| 15 | + for f ∈ (+, *, muladd) |
| 16 | + for op ∈ (+, *, max, min) |
| 17 | + for g ∈ (abs, abs2, sqrt) |
| 18 | + for dims ∈ (1, 2, 3, 4, (1,2), (1,3), (1,4), (2,3), (2,4), (3,4), (1,2,3), (1,2,4), (2,3,4), (1,2,3,4), (1,2,3,4,5)) |
| 19 | + @test vmapreducethen(f, op, g, x, y, z, dims=dims) ≈ g.(mapreduce(f, op, x, y, z, dims=dims)) |
| 20 | + end |
| 21 | + end |
| 22 | + end |
| 23 | + end |
| 24 | +end |
0 commit comments