summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRémi Flamary <remi.flamary@gmail.com>2017-07-24 11:15:33 +0200
committerRémi Flamary <remi.flamary@gmail.com>2017-07-24 11:15:33 +0200
commit5a6b5de9b2f28c93bef1a9db2e3b94693c05ff4f (patch)
tree1f7457a028ef71253be36c44fb87c2e4131e909a /test
parent82da63f1020835a412f6174500099694a78ab6be (diff)
add proper testing
Diffstat (limited to 'test')
-rw-r--r--test/test_emd_multi.py47
-rw-r--r--test/test_gpu.py59
-rw-r--r--test/test_gpu_sinkhorn.py28
-rw-r--r--test/test_gpu_sinkhorn_lpl1.py29
-rw-r--r--test/test_load_module.py10
-rw-r--r--test/test_ot.py55
6 files changed, 114 insertions, 114 deletions
diff --git a/test/test_emd_multi.py b/test/test_emd_multi.py
deleted file mode 100644
index 2eef242..0000000
--- a/test/test_emd_multi.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
-"""
-Created on Fri Mar 10 09:56:06 2017
-
-@author: rflamary
-"""
-
-import numpy as np
-
-import ot
-from ot.datasets import get_1D_gauss as gauss
-# reload(ot.lp)
-
-#%% parameters
-
-n = 5000 # nb bins
-
-# bin positions
-x = np.arange(n, dtype=np.float64)
-
-# Gaussian distributions
-a = gauss(n, m=20, s=5) # m= mean, s= std
-
-ls = np.arange(20, 1000, 10)
-nb = len(ls)
-b = np.zeros((n, nb))
-for i in range(nb):
- b[:, i] = gauss(n, m=ls[i], s=10)
-
-# loss matrix
-M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
-# M/=M.max()
-
-#%%
-
-print('Computing {} EMD '.format(nb))
-
-# emd loss 1 proc
-ot.tic()
-emd_loss4 = ot.emd2(a, b, M, 1)
-ot.toc('1 proc : {} s')
-
-# emd loss multipro proc
-ot.tic()
-emd_loss4 = ot.emd2(a, b, M)
-ot.toc('multi proc : {} s')
diff --git a/test/test_gpu.py b/test/test_gpu.py
new file mode 100644
index 0000000..312a2d4
--- /dev/null
+++ b/test/test_gpu.py
@@ -0,0 +1,59 @@
+import ot
+import numpy as np
+import time
+import pytest
+
+
+@pytest.mark.skip(reason="No way to test GPU on travis yet")
+def test_gpu_sinkhorn():
+ import ot.gpu
+
+ def describeRes(r):
+ print("min:{:.3E}, max::{:.3E}, mean::{:.3E}, std::{:.3E}".format(
+ np.min(r), np.max(r), np.mean(r), np.std(r)))
+
+ for n in [5000]:
+ print(n)
+ a = np.random.rand(n // 4, 100)
+ b = np.random.rand(n, 100)
+ time1 = time.time()
+ transport = ot.da.OTDA_sinkhorn()
+ transport.fit(a, b)
+ G1 = transport.G
+ time2 = time.time()
+ transport = ot.gpu.da.OTDA_sinkhorn()
+ transport.fit(a, b)
+ G2 = transport.G
+ time3 = time.time()
+ print("Normal sinkhorn, time: {:6.2f} sec ".format(time2 - time1))
+ describeRes(G1)
+ print(" GPU sinkhorn, time: {:6.2f} sec ".format(time3 - time2))
+ describeRes(G2)
+
+
+@pytest.mark.skip(reason="No way to test GPU on travis yet")
+def test_gpu_sinkhorn_lpl1():
+ def describeRes(r):
+ print("min:{:.3E}, max:{:.3E}, mean:{:.3E}, std:{:.3E}"
+ .format(np.min(r), np.max(r), np.mean(r), np.std(r)))
+
+ for n in [5000]:
+ print(n)
+ a = np.random.rand(n // 4, 100)
+ labels_a = np.random.randint(10, size=(n // 4))
+ b = np.random.rand(n, 100)
+ time1 = time.time()
+ transport = ot.da.OTDA_lpl1()
+ transport.fit(a, labels_a, b)
+ G1 = transport.G
+ time2 = time.time()
+ transport = ot.gpu.da.OTDA_lpl1()
+ transport.fit(a, labels_a, b)
+ G2 = transport.G
+ time3 = time.time()
+ print("Normal sinkhorn lpl1, time: {:6.2f} sec ".format(
+ time2 - time1))
+ describeRes(G1)
+ print(" GPU sinkhorn lpl1, time: {:6.2f} sec ".format(
+ time3 - time2))
+ describeRes(G2)
diff --git a/test/test_gpu_sinkhorn.py b/test/test_gpu_sinkhorn.py
deleted file mode 100644
index 841f062..0000000
--- a/test/test_gpu_sinkhorn.py
+++ /dev/null
@@ -1,28 +0,0 @@
-import ot
-import numpy as np
-import time
-import ot.gpu
-
-
-def describeRes(r):
- print("min:{:.3E}, max::{:.3E}, mean::{:.3E}, std::{:.3E}".format(
- np.min(r), np.max(r), np.mean(r), np.std(r)))
-
-
-for n in [5000, 10000, 15000, 20000]:
- print(n)
- a = np.random.rand(n // 4, 100)
- b = np.random.rand(n, 100)
- time1 = time.time()
- transport = ot.da.OTDA_sinkhorn()
- transport.fit(a, b)
- G1 = transport.G
- time2 = time.time()
- transport = ot.gpu.da.OTDA_sinkhorn()
- transport.fit(a, b)
- G2 = transport.G
- time3 = time.time()
- print("Normal sinkhorn, time: {:6.2f} sec ".format(time2 - time1))
- describeRes(G1)
- print(" GPU sinkhorn, time: {:6.2f} sec ".format(time3 - time2))
- describeRes(G2)
diff --git a/test/test_gpu_sinkhorn_lpl1.py b/test/test_gpu_sinkhorn_lpl1.py
deleted file mode 100644
index f0eb7e6..0000000
--- a/test/test_gpu_sinkhorn_lpl1.py
+++ /dev/null
@@ -1,29 +0,0 @@
-import ot
-import numpy as np
-import time
-import ot.gpu
-
-
-def describeRes(r):
- print("min:{:.3E}, max:{:.3E}, mean:{:.3E}, std:{:.3E}"
- .format(np.min(r), np.max(r), np.mean(r), np.std(r)))
-
-
-for n in [5000, 10000, 15000, 20000]:
- print(n)
- a = np.random.rand(n // 4, 100)
- labels_a = np.random.randint(10, size=(n // 4))
- b = np.random.rand(n, 100)
- time1 = time.time()
- transport = ot.da.OTDA_lpl1()
- transport.fit(a, labels_a, b)
- G1 = transport.G
- time2 = time.time()
- transport = ot.gpu.da.OTDA_lpl1()
- transport.fit(a, labels_a, b)
- G2 = transport.G
- time3 = time.time()
- print("Normal sinkhorn lpl1, time: {:6.2f} sec ".format(time2 - time1))
- describeRes(G1)
- print(" GPU sinkhorn lpl1, time: {:6.2f} sec ".format(time3 - time2))
- describeRes(G2)
diff --git a/test/test_load_module.py b/test/test_load_module.py
deleted file mode 100644
index d77261e..0000000
--- a/test/test_load_module.py
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-import ot
-import doctest
-
-# test lp solver
-doctest.testmod(ot.lp, verbose=True)
-
-# test bregman solver
-doctest.testmod(ot.bregman, verbose=True)
diff --git a/test/test_ot.py b/test/test_ot.py
new file mode 100644
index 0000000..51ee510
--- /dev/null
+++ b/test/test_ot.py
@@ -0,0 +1,55 @@
+
+
+import ot
+import numpy as np
+
+#import pytest
+
+
+def test_doctest():
+
+ import doctest
+
+ # test lp solver
+ doctest.testmod(ot.lp, verbose=True)
+
+ # test bregman solver
+ doctest.testmod(ot.bregman, verbose=True)
+
+
+#@pytest.mark.skip(reason="Seems to be a conflict between pytest and multiprocessing")
+def test_emd_multi():
+
+ from ot.datasets import get_1D_gauss as gauss
+
+ n = 1000 # nb bins
+
+ # bin positions
+ x = np.arange(n, dtype=np.float64)
+
+ # Gaussian distributions
+ a = gauss(n, m=20, s=5) # m= mean, s= std
+
+ ls = np.arange(20, 1000, 10)
+ nb = len(ls)
+ b = np.zeros((n, nb))
+ for i in range(nb):
+ b[:, i] = gauss(n, m=ls[i], s=10)
+
+ # loss matrix
+ M = ot.dist(x.reshape((n, 1)), x.reshape((n, 1)))
+ # M/=M.max()
+
+ print('Computing {} EMD '.format(nb))
+
+ # emd loss 1 proc
+ ot.tic()
+ emd1 = ot.emd2(a, b, M, 1)
+ ot.toc('1 proc : {} s')
+
+ # emd loss multipro proc
+ ot.tic()
+ emdn = ot.emd2(a, b, M)
+ ot.toc('multi proc : {} s')
+
+ assert np.allclose(emd1, emdn)