Skip to content

Commit 3da1af6

Browse files
Add tests of deviations
1 parent 596159e commit 3da1af6

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

test/vstats.jl

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
counteq(x, y; dims=:) = mapreduce(==, +, x, y, dims=dims)
2+
countne(x, y; dims=:) = mapreduce(!=, +, x, y, dims=dims)
3+
@testset "counteq" begin
4+
for T (Float32, Float64, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64)
5+
x, y = rand(T, 1000), rand(T, 1000)
6+
c = counteq(x, y)
7+
@test vcounteq(x, y) == c
8+
@test vtcounteq(x, y) == c
9+
end
10+
x, y = rand(1:100, 10, 10, 10, 10), rand(1:100, 10, 10, 10, 10)
11+
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))
12+
c = counteq(x, y, dims=dims)
13+
@test vcounteq(x, y, dims=dims) == c
14+
@test vtcounteq(x, y, dims=dims) == c
15+
end
16+
end
17+
18+
@testset "countne" begin
19+
for T (Float32, Float64, Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64)
20+
x, y = rand(T, 1000), rand(T, 1000)
21+
c = countne(x, y)
22+
@test vcountne(x, y) == c
23+
@test vtcountne(x, y) == c
24+
end
25+
x, y = rand(1:100, 10, 10, 10, 10), rand(1:100, 10, 10, 10, 10)
26+
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))
27+
c = countne(x, y, dims=dims)
28+
@test vcountne(x, y, dims=dims) == c
29+
@test vtcountne(x, y, dims=dims) == c
30+
end
31+
end
32+
33+
meanad(x, y; dims=:) = mean(abs.(x .- y), dims=dims)
34+
maxad(x, y; dims=:) = maximum(abs.(x .- y), dims=dims)
35+
mse(x, y; dims=:) = mean(abs2.(x .- y), dims=dims)
36+
rmse(x, y; dims=:) = .√mean(abs2.(x .- y), dims=dims)
37+
38+
@testset "meanad" begin
39+
for T (Float32, Float64, Int32)
40+
x, y = rand(T, 1000), rand(T, 1000)
41+
c = meanad(x, y)
42+
@test vmeanad(x, y) c
43+
@test vtmeanad(x, y) c
44+
end
45+
x, y = rand(10, 10, 10, 10), rand(10, 10, 10, 10)
46+
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))
47+
c = meanad(x, y, dims=dims)
48+
@test vmeanad(x, y, dims=dims) c
49+
@test vtmeanad(x, y, dims=dims) c
50+
end
51+
end
52+
53+
@testset "maxad" begin
54+
for T (Float32, Float64, Int32)
55+
x, y = rand(T, 1000), rand(T, 1000)
56+
c = maxad(x, y)
57+
@test vmaxad(x, y) c
58+
@test vtmaxad(x, y) c
59+
end
60+
x, y = rand(10, 10, 10, 10), rand(10, 10, 10, 10)
61+
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))
62+
c = maxad(x, y, dims=dims)
63+
@test vmaxad(x, y, dims=dims) c
64+
@test vtmaxad(x, y, dims=dims) c
65+
end
66+
end
67+
68+
@testset "mse" begin
69+
for T (Float32, Float64, Int32)
70+
x, y = rand(T, 1000), rand(T, 1000)
71+
c = mse(x, y)
72+
@test vmse(x, y) c
73+
@test vtmse(x, y) c
74+
end
75+
x, y = rand(10, 10, 10, 10), rand(10, 10, 10, 10)
76+
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))
77+
c = mse(x, y, dims=dims)
78+
@test vmse(x, y, dims=dims) c
79+
@test vtmse(x, y, dims=dims) c
80+
end
81+
end
82+
83+
@testset "rmse" begin
84+
for T (Float32, Float64, Int32)
85+
x, y = rand(T, 1000), rand(T, 1000)
86+
c = rmse(x, y)
87+
@test vrmse(x, y) c
88+
@test vtrmse(x, y) c
89+
end
90+
x, y = rand(10, 10, 10, 10), rand(10, 10, 10, 10)
91+
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))
92+
c = rmse(x, y, dims=dims)
93+
@test vrmse(x, y, dims=dims) c
94+
@test vtrmse(x, y, dims=dims) c
95+
end
96+
end

0 commit comments

Comments
 (0)