(nx)
| 597 | |
| 598 | |
| 599 | def test_lowrank_LazyTensor(nx): |
| 600 | p = 5 |
| 601 | n1 = 100 |
| 602 | n2 = 200 |
| 603 | |
| 604 | shape = (n1, n2) |
| 605 | |
| 606 | rng = np.random.RandomState(42) |
| 607 | X1 = rng.randn(n1, p) |
| 608 | X2 = rng.randn(n2, p) |
| 609 | diag_d = rng.rand(p) |
| 610 | |
| 611 | X1, X2, diag_d = nx.from_numpy(X1, X2, diag_d) |
| 612 | |
| 613 | T0 = nx.dot(X1, X2.T) |
| 614 | |
| 615 | T = ot.utils.get_lowrank_lazytensor(X1, X2) |
| 616 | |
| 617 | np.testing.assert_allclose(nx.to_numpy(T[:]), nx.to_numpy(T0)) |
| 618 | |
| 619 | assert T.Q is X1 |
| 620 | assert T.R is X2 |
| 621 | |
| 622 | # get the full tensor (not lazy) |
| 623 | assert T[:].shape == shape |
| 624 | |
| 625 | # get one component |
| 626 | assert T[1, 1] == nx.dot(X1[1], X2[1].T) |
| 627 | |
| 628 | # get one row |
| 629 | assert T[1].shape == (n2,) |
| 630 | |
| 631 | # get one column with slices |
| 632 | assert T[::10, 5].shape == (10,) |
| 633 | |
| 634 | T0 = nx.dot(X1 * diag_d[None, :], X2.T) |
| 635 | |
| 636 | T = ot.utils.get_lowrank_lazytensor(X1, X2, diag_d, nx=nx) |
| 637 | |
| 638 | np.testing.assert_allclose(nx.to_numpy(T[:]), nx.to_numpy(T0)) |
| 639 | |
| 640 | |
| 641 | def test_labels_to_mask_helper(nx): |
nothing calls this directly
no test coverage detected