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

Function test_solve_batch

test/batch/test_solve_batch.py:28–62  ·  view source on GitHub ↗

Check that solve_batch gives the same results as solve for each instance in the batch.

(solver, reg_type)

Source from the content-addressed store, hash-verified

26@pytest.mark.parametrize("solver", ["sinkhorn", "log_sinkhorn"])
27@pytest.mark.parametrize("reg_type", ["kl", "entropy"])
28def test_solve_batch(solver, reg_type):
29 """Check that solve_batch gives the same results as solve for each instance in the batch."""
30 batchsize = 4
31 n = 16
32 rng = np.random.RandomState(0)
33
34 M = rng.rand(batchsize, n, n)
35
36 reg = 0.1
37 max_iter = 10000
38 tol = 1e-5
39
40 res = solve_batch(
41 M,
42 a=None,
43 b=None,
44 reg=reg,
45 max_iter=max_iter,
46 tol=tol,
47 solver=solver,
48 reg_type=reg_type,
49 grad="detach",
50 )
51 plan_batch = res.plan
52 values_batch = res.value_linear
53
54 for i in range(batchsize):
55 M_i = M[i]
56 res_i = solve(
57 M_i, a=None, b=None, reg=reg, max_iter=max_iter, tol=tol, reg_type=reg_type
58 )
59 plan_i = res_i.plan
60 value_i = res_i.value_linear
61 np.testing.assert_allclose(plan_i, plan_batch[i], atol=1e-05)
62 np.testing.assert_allclose(value_i, values_batch[i], atol=1e-4)
63
64
65def test_bregman_batch():

Callers

nothing calls this directly

Calls 3

solve_batchFunction · 0.90
solveFunction · 0.90
randMethod · 0.45

Tested by

no test coverage detected