Skip to content

Weighted low-rank LazyTensor integer indexing keeps an extra dimension #892

Open

Description

@ktz03

Describe the bug

Integer row indexing of a weighted get_lowrank_lazytensor(Q, R, d) adds an extra leading dimension. A row has shape (1, m) instead of (m,), and a single entry has shape (1,) instead of (). The unweighted tensor and the equivalent dense product have the expected shapes.

To Reproduce

Code sample

import numpy as np
from ot.utils import get_lowrank_lazytensor

Q = np.arange(10, dtype=float).reshape(5, 2)
R = np.arange(6, dtype=float).reshape(3, 2)
d = np.array([0.25, 2.0])
lazy = get_lowrank_lazytensor(Q, R, d)
dense = (Q * d) @ R.T

print(lazy[0].shape, dense[0].shape)
print(lazy[0, 0].shape, dense[0, 0].shape)

On current master c02a25cbb0536bd53ba071acd03733c52c2f3be5:

(1, 3) (3,)
(1,) ()

Expected behavior

Integer and mixed integer/slice indexing should return the same shapes and values as the dense Q @ diag(d) @ R.T, consistently with the unweighted path. Full matrices, block slices, and column slices already have the correct shapes.

Environment

  • Windows 11 (Windows-11-10.0.26200-SP0), Python 3.12.14.
  • POT 0.9.8.dev, built from the master commit above with uv pip install --no-build-isolation -e ., including the repository-pinned Eigen submodule.
  • NumPy 2.5.4, SciPy 1.18.1; the same regression also reproduces with PyTorch 2.14.1 on CPU.
  • No GPU test was run.

Additional context

The weighted callback multiplies an indexed row by d[None, :], which restores a leading axis when Q[i] is one-dimensional. Broadcasting with d directly preserves the indexed rank. This also affects the lazy_plan returned by lowrank_sinkhorn; I reproduced the row and scalar shapes through that public solver. A focused NumPy/PyTorch regression has 10 shape failures and 24 passing controls on unchanged production source, and all 34 pass with that one-line change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions