summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKilian <kilian.fatras@gmail.com>2020-01-07 13:16:54 +0100
committerGitHub <noreply@github.com>2020-01-07 13:16:54 +0100
commit40154746a5a6cab0b6f17c284967eb8303fcc3f6 (patch)
tree2622569a36aab5fc2eb2d2adc45a16f861a65dc5 /test
parenta9bbc2cfdffd22ceee3256102e470df6c25338f3 (diff)
parentc5039bcafde999114283f7e59fb03e176027d740 (diff)
Merge branch 'master' into emd_dimension
Diffstat (limited to 'test')
-rw-r--r--test/test_ot.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/test_ot.py b/test/test_ot.py
index 42a3d0a..18b6294 100644
--- a/test/test_ot.py
+++ b/test/test_ot.py
@@ -134,6 +134,28 @@ def test_emd_empty():
np.testing.assert_allclose(w, 0)
+def test_emd_sparse():
+
+ n = 100
+ rng = np.random.RandomState(0)
+
+ x = rng.randn(n, 2)
+ x2 = rng.randn(n, 2)
+
+ M = ot.dist(x, x2)
+
+ G = ot.emd([], [], M, dense=True)
+
+ Gs = ot.emd([], [], M, dense=False)
+
+ ws = ot.emd2([], [], M, dense=False)
+
+ # check G is the same
+ np.testing.assert_allclose(G, Gs.todense())
+ # check value
+ np.testing.assert_allclose(Gs.multiply(M).sum(), ws, rtol=1e-6)
+
+
def test_emd2_multi():
n = 500 # nb bins
@@ -165,7 +187,12 @@ def test_emd2_multi():
emdn = ot.emd2(a, b, M)
ot.toc('multi proc : {} s')
+ ot.tic()
+ emdn2 = ot.emd2(a, b, M, dense=False)
+ ot.toc('multi proc : {} s')
+
np.testing.assert_allclose(emd1, emdn)
+ np.testing.assert_allclose(emd1, emdn2, rtol=1e-6)
# emd loss multipro proc with log
ot.tic()