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

Function test_sliced_backend

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

Source from the content-addressed store, hash-verified

127
128
129def test_sliced_backend(nx):
130 n = 100
131 rng = np.random.RandomState(0)
132
133 x = rng.randn(n, 2)
134 y = rng.randn(2 * n, 2)
135
136 P = rng.randn(2, 20)
137 P = P / np.sqrt((P**2).sum(0, keepdims=True))
138
139 n_projections = 20
140
141 xb, yb, Pb = nx.from_numpy(x, y, P)
142
143 val0 = ot.sliced_wasserstein_distance(x, y, projections=P)
144
145 val = ot.sliced_wasserstein_distance(xb, yb, n_projections=n_projections, seed=0)
146 val2 = ot.sliced_wasserstein_distance(xb, yb, n_projections=n_projections, seed=0)
147
148 assert val > 0
149 assert val == val2
150
151 valb = nx.to_numpy(ot.sliced_wasserstein_distance(xb, yb, projections=Pb))
152
153 assert np.allclose(val0, valb)
154
155
156def test_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