MCPcopy Create free account
hub / github.com/PythonOT/POT / test_clean_discrete_measure

Function test_clean_discrete_measure

test/test_ot.py:784–815  ·  view source on GitHub ↗
(nx)

Source from the content-addressed store, hash-verified

782
783
784def test_clean_discrete_measure(nx):
785 a = nx.ones(3) / 3.0
786 X = nx.from_numpy(np.array([[1.0, 1.0], [1.0, 1.0], [2.0, 2.0]]))
787 X_clean, a_clean = ot.lp._barycenter_solvers._clean_discrete_measure(X, a)
788 a_true = nx.from_numpy(np.array([2 / 3, 1 / 3]))
789 X_true = nx.from_numpy(np.array([[1.0, 1.0], [2.0, 2.0]]))
790 assert a_clean.shape == a_true.shape
791 assert X_clean.shape == X_true.shape
792 np.testing.assert_allclose(a_clean, a_true)
793 np.testing.assert_allclose(X_clean, X_true)
794
795 a = nx.ones(3) / 3.0
796 X = nx.from_numpy(np.array([[1.0, 1.0], [2.0, 2.0], [1.0, 1.0]]))
797 X_clean, a_clean = ot.lp._barycenter_solvers._clean_discrete_measure(X, a, nx=nx)
798 a_true = nx.from_numpy(np.array([2 / 3, 1 / 3]))
799 X_true = nx.from_numpy(np.array([[1.0, 1.0], [2.0, 2.0]]))
800 assert a_clean.shape == a_true.shape
801 assert X_clean.shape == X_true.shape
802 np.testing.assert_allclose(a_clean, a_true)
803 np.testing.assert_allclose(X_clean, X_true)
804
805 n = 5
806 a = nx.ones(n) / n
807 v = nx.from_numpy(np.array([1.0, 2.0, 3.0]))
808 X = nx.stack([v] * n, axis=0)
809 X_clean, a_clean = ot.lp._barycenter_solvers._clean_discrete_measure(X, a)
810 a_true = np.array([1.0])
811 X_true = np.array([1.0, 2.0, 3.0]).reshape(1, 3)
812 assert a_clean.shape == a_true.shape
813 assert X_clean.shape == X_true.shape
814 np.testing.assert_allclose(a_clean, a_true)
815 np.testing.assert_allclose(X_clean, X_true)
816
817
818def test_to_int_array(nx):

Callers

nothing calls this directly

Calls 4

from_numpyMethod · 0.80
onesMethod · 0.45
stackMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected