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

Function test_solve_grid

test/test_solvers.py:281–353  ·  view source on GitHub ↗
(nx, reg, reg_type, unbalanced, unbalanced_type)

Source from the content-addressed store, hash-verified

279 itertools.product(lst_reg, lst_reg_type, lst_unbalanced, lst_unbalanced_type),
280)
281def test_solve_grid(nx, reg, reg_type, unbalanced, unbalanced_type):
282 n_samples_s = 10
283 n_samples_t = 7
284 n_features = 2
285 rng = np.random.RandomState(0)
286
287 x = rng.randn(n_samples_s, n_features)
288 y = rng.randn(n_samples_t, n_features)
289 a = ot.utils.unif(n_samples_s)
290 b = ot.utils.unif(n_samples_t)
291
292 M = ot.dist(x, y)
293
294 try:
295 if reg_type == "tuple":
296
297 def f(G):
298 return np.sum(G**2)
299
300 def df(G):
301 return 2 * G
302
303 reg_type = (f, df)
304
305 # solve unif weights
306 sol0 = ot.solve(
307 M,
308 reg=reg,
309 reg_type=reg_type,
310 unbalanced=unbalanced,
311 unbalanced_type=unbalanced_type,
312 )
313
314 # solve signe weights
315 sol = ot.solve(
316 M,
317 a,
318 b,
319 reg=reg,
320 reg_type=reg_type,
321 unbalanced=unbalanced,
322 unbalanced_type=unbalanced_type,
323 )
324
325 assert_allclose_sol(sol0, sol)
326
327 # solve in backend
328 ab, bb, Mb = nx.from_numpy(a, b, M)
329
330 if isinstance(reg_type, tuple):
331
332 def f(G):
333 return nx.sum(G**2)
334
335 def df(G):
336 return 2 * G
337
338 reg_type = (f, df)

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