(nx)
| 530 | |
| 531 | |
| 532 | def 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 | |
| 578 | def test_solve_sample_lazy(nx): |
nothing calls this directly
no test coverage detected