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

Function test_solve_sample

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

Source from the content-addressed store, hash-verified

530
531
532def test_solve_sample(nx):
533 # test solve_sample when is_Lazy = False
534 n = 20
535 X_s = np.reshape(1.0 * np.arange(n), (n, 1))
536 X_t = np.reshape(1.0 * np.arange(0, n), (n, 1))
537
538 a = ot.utils.unif(X_s.shape[0])
539 b = ot.utils.unif(X_t.shape[0])
540
541 M = ot.dist(X_s, X_t)
542
543 # solve with ot.solve
544 sol00 = ot.solve(M, a, b)
545
546 # solve unif weights
547 sol0 = ot.solve_sample(X_s, X_t)
548
549 # solve signe weights
550 sol = ot.solve_sample(X_s, X_t, a, b)
551
552 # check some attributes
553 sol.potentials
554 sol.sparse_plan
555 sol.marginals
556 sol.status
557
558 assert_allclose_sol(sol0, sol)
559 assert_allclose_sol(sol0, sol00)
560
561 # solve in backend
562 X_sb, X_tb, ab, bb = nx.from_numpy(X_s, X_t, a, b)
563 solb = ot.solve_sample(X_sb, X_tb, ab, bb)
564
565 assert_allclose_sol(sol, solb)
566
567 # test not implemented unbalanced and check raise
568 with pytest.raises(NotImplementedError):
569 sol0 = ot.solve_sample(
570 X_s, X_t, unbalanced=1, unbalanced_type="cryptic divergence"
571 )
572
573 # test not implemented reg_type and check raise
574 with pytest.raises(NotImplementedError):
575 sol0 = ot.solve_sample(X_s, X_t, reg=1, reg_type="cryptic divergence")
576
577
578def test_solve_sample_lazy(nx):

Callers

nothing calls this directly

Calls 5

assert_allclose_solFunction · 0.85
from_numpyMethod · 0.80
reshapeMethod · 0.45
arangeMethod · 0.45
solveMethod · 0.45

Tested by

no test coverage detected