Skip to content

Commit edb1365

Browse files
committed
Fix max/min bug (with optimization)
1 parent 7fbe739 commit edb1365

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Histograms.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ function W1(u_samples::AbstractVector, v_samples::AbstractVector;
197197
return if !normalize
198198
scsta.wasserstein_distance(u_samples, v_samples)
199199
else
200-
L = maximum( (u_samples; v_samples) ) - minimum( (u_samples; v_samples) )
200+
u_m, u_M = extrema(u_samples)
201+
v_m, v_M = extrema(v_samples)
202+
L = max(u_M, v_M) - min(u_m, v_m)
201203
scsta.wasserstein_distance(u_samples, v_samples) / L
202204
end
203205
end

test/Histograms/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ const w1_bal_onl_comb = 0.8529846357976019
2828
arr2 = [1, 1, 2, 2, 3, 3, 4, 4, 4]
2929
@test Hgm.W1(arr1, arr2; normalize = false) == 0.25
3030
@test Hgm.W1(arr2, arr1; normalize = false) == 0.25
31-
@test Hgm.W1(arr1, arr2; normalize = true) ==
32-
Hgm.W1(arr2, arr1; normalize = true)
31+
@test Hgm.W1([arr1; 5], arr2; normalize = true) ==
32+
Hgm.W1(arr2, [arr1; 5]; normalize = true)
3333

3434
@test isapprox(Hgm.W1(x1_dns, x1_bal), w1_dns_bal)
3535
@test isapprox(Hgm.W1(x1_dns, x1_onl), w1_dns_onl)

0 commit comments

Comments
 (0)