Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#### Closed issues

- Fix integer row and scalar indexing of weighted low-rank lazy transport plans returning an extra leading dimension (PR #893, Issue #892).
- Fix dead links in the README (three example gallery pages and the reference [39]), the user guide and the contributing guide (PR #928)
- Fix ordinary JAX gradients for dense `ot.emd2` and preserve the magnitude and higher-order dependence of gradients supplied to `JaxBackend.set_gradients`, including the envelope gradients in `ot.solve` (Issue #625)
- Fix `ot.semidiscrete_wasserstein2_unif_circle` pairing sorted sample locations with unsorted weights, which broke permutation and rotation invariance for nonuniform weights (Issue #921)
Expand Down
2 changes: 1 addition & 1 deletion ot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ def func(i, j, Q, R):
else:

def func(i, j, Q, R, d):
return nx.dot(Q[i] * d[None, :], R[j].T)
return nx.dot(Q[i] * d, R[j].T)

T = LazyTensor(shape, func, Q=Q, R=R, d=d)

Expand Down
29 changes: 29 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,35 @@ def test_lowrank_LazyTensor(nx):
np.testing.assert_allclose(nx.to_numpy(T[:]), nx.to_numpy(T0))


@pytest.mark.parametrize("weighted", [False, True])
@pytest.mark.parametrize(
"index",
[
0,
-1,
(1, 2),
(-1, -2),
(1, slice(1, None)),
(slice(None), 1),
(slice(1, 3), slice(None)),
slice(None),
],
)
def test_lowrank_LazyTensor_indexing(nx, weighted, index):
Q, R, d = nx.from_numpy(
np.arange(10, dtype=float).reshape(5, 2),
np.arange(6, dtype=float).reshape(3, 2),
np.array([0.25, 2.0]),
)
if not weighted:
d = None
T = ot.utils.get_lowrank_lazytensor(Q, R, d)
dense = nx.dot(Q if d is None else Q * d, R.T)

assert T[index].shape == dense[index].shape
np.testing.assert_allclose(nx.to_numpy(T[index]), nx.to_numpy(dense[index]))


def test_labels_to_mask_helper(nx):
y = np.array([1, 0, 2, 2, 1])
out = np.array(
Expand Down
Loading