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

Function test_solve

test/test_solvers.py:105–148  ·  view source on GitHub ↗
(nx)

Source from the content-addressed store, hash-verified

103
104
105def test_solve(nx):
106 n_samples_s = 10
107 n_samples_t = 7
108 n_features = 2
109 rng = np.random.RandomState(0)
110
111 x = rng.randn(n_samples_s, n_features)
112 y = rng.randn(n_samples_t, n_features)
113 a = ot.utils.unif(n_samples_s)
114 b = ot.utils.unif(n_samples_t)
115
116 M = ot.dist(x, y)
117 reg = 1e-1
118
119 # solve unif weights
120 sol0 = ot.solve(M, reg=reg)
121
122 print(sol0)
123
124 # solve signe weights
125 sol = ot.solve(M, a, b, reg=reg)
126
127 # check some attributes
128 sol.potentials
129 sol.sparse_plan
130 sol.marginals
131 sol.status
132
133 # print("dual = {}".format(sol.potentials))
134 # assert_allclose_sol(sol0, sol)
135
136 # solve in backend
137 ab, bb, Mb = nx.from_numpy(a, b, M)
138 solb = ot.solve(M, a, b)
139
140 assert_allclose_sol(sol, solb)
141
142 # test not implemented unbalanced and check raise
143 with pytest.raises(NotImplementedError):
144 sol0 = ot.solve(M, unbalanced=1, unbalanced_type="cryptic divergence")
145
146 # test not implemented reg_type and check raise
147 with pytest.raises(NotImplementedError):
148 sol0 = ot.solve(M, reg=1, reg_type="cryptic divergence")
149
150
151@pytest.mark.skipif(not torch, reason="torch no installed")

Callers

nothing calls this directly

Calls 4

assert_allclose_solFunction · 0.85
from_numpyMethod · 0.80
randnMethod · 0.45
solveMethod · 0.45

Tested by

no test coverage detected