Skip to content

Normalize CatLinearOperator slice bounds without modulo wrapping - #138

Open
AHMETHAKANBEZIR1 wants to merge 1 commit into
cornellius-gp:mainfrom
AHMETHAKANBEZIR1:fix/cat-slice-bounds
Open

AHMETHAKANBEZIR1 wants to merge 1 commit into
cornellius-gp:mainfrom
AHMETHAKANBEZIR1:fix/cat-slice-bounds

Conversation

@AHMETHAKANBEZIR1

Copy link
Copy Markdown

Fixes #137.

Problem

CatLinearOperator._split_slice normalizes bounds with modulo. A stop equal to the concatenated size becomes zero; out-of-bounds endpoints wrap rather than clip. Consequently even op[:, :op.size(-1)] can return the wrong shape or raise. Reversed/empty ranges can also select nonempty components.

Change

Normalize bounds with Python's slice.indices(cat_size). For an empty range, select a zero-length slice from the first component. The existing lazy component splitting and unsupported-step behavior are retained; no full matrix materialization is added.

The tests compare directly against torch.cat(...)[slice]: 36 dense cases across row/column/batch concatenation check values, shapes and input gradients; 20 nonempty Diag/Identity cases cover structured components. They include explicit full-size stops, clipping beyond positive/negative bounds, empty ranges and in-range controls.

Validation

  • Clean main 1c5e24b: 46 new subcases raise, 10 controls pass.
  • Python 3.12.14 / PyTorch 2.10.0+cpu: entire unittest suite: 5,048 tests passed, including all 56 new subcases.
  • Python 3.14.6 / PyTorch 2.13.0+cpu: all 56 new subcases passed.
  • All 15 configured pre-commit hooks pass or report no applicable files, including full flake8/ufmt/ASCII; git diff --check passes.
  • Full Sphinx documentation build with -W: passed.

All verification used this source checkout on Windows CPU. GPU/Inductor and other matrix environments were not run. No public API/docstring change.

Scope

This follows up on #80's negative-bound handling. Boolean indexing and explicit slice steps are unchanged. Empty slicing of some structured components has existing underlying interpolation/device limitations; this PR verifies empty dense selections and nonempty structured selections, and does not claim to repair those generic limitations.

AI disclosure

OpenAI Codex autonomously reproduced, implemented and tested this contribution at the account owner's request. No independent human code review is claimed. The commit includes Codex co-authorship.

Co-authored-by: Codex <noreply@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CatLinearOperator wraps full-length and clipped slice endpoints

1 participant