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

Function test_max_sliced_backend

test/test_sliced.py:200–228  ·  view source on GitHub ↗
(nx)

Source from the content-addressed store, hash-verified

198
199
200def test_max_sliced_backend(nx):
201 n = 100
202 rng = np.random.RandomState(0)
203
204 x = rng.randn(n, 2)
205 y = rng.randn(2 * n, 2)
206
207 P = rng.randn(2, 20)
208 P = P / np.sqrt((P**2).sum(0, keepdims=True))
209
210 n_projections = 20
211
212 xb, yb, Pb = nx.from_numpy(x, y, P)
213
214 val0 = ot.max_sliced_wasserstein_distance(x, y, projections=P)
215
216 val = ot.max_sliced_wasserstein_distance(
217 xb, yb, n_projections=n_projections, seed=0
218 )
219 val2 = ot.max_sliced_wasserstein_distance(
220 xb, yb, n_projections=n_projections, seed=0
221 )
222
223 assert val > 0
224 assert val == val2
225
226 valb = nx.to_numpy(ot.max_sliced_wasserstein_distance(xb, yb, projections=Pb))
227
228 assert np.allclose(val0, valb)
229
230
231def test_max_sliced_backend_type_devices(nx):

Callers

nothing calls this directly

Calls 6

from_numpyMethod · 0.80
to_numpyMethod · 0.80
randnMethod · 0.45
sqrtMethod · 0.45
sumMethod · 0.45
allcloseMethod · 0.45

Tested by

no test coverage detected