Skip to content

Fix PyTorch triangular-index NumPy contract - #5389

Merged
FlorianPfaff merged 2 commits into
mainfrom
fix/pytorch-triangular-indices-numpy-contract
Aug 22, 2026
Merged

Fix PyTorch triangular-index NumPy contract#5389
FlorianPfaff merged 2 commits into
mainfrom
fix/pytorch-triangular-indices-numpy-contract

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

Fixes tril_indices and triu_indices on the PyTorch backend so they follow the NumPy-shaped backend API instead of exposing torch.tril_indices/torch.triu_indices directly.

Before this change:

  • backend.tril_indices(3) raises because Torch requires both row and col.
  • Supplying Torch-style dimensions returns one 2 x N tensor instead of NumPy's (rows, cols) tuple.
  • Negative dimensions raise in Torch although NumPy returns empty index arrays.

The compatibility hook now:

  • accepts (n, k=0, m=None),
  • returns a tuple of 1-D tensors,
  • matches NumPy for square/rectangular, offset, and negative-dimension cases,
  • preserves optional Torch dtype, device, and layout keywords for raw-backend callers.

Regression tests cover both the public PyTorch backend and the raw PyTorch backend when NumPy is the selected public backend.

@FlorianPfaff
FlorianPfaff enabled auto-merge (squash) August 22, 2026 07:05
@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 7.91s
✅ JSON prettier 7 0 0 0 0.92s
✅ JSON v8r 7 0 0 4.44s
✅ MARKDOWN markdownlint 68 0 0 0 1.85s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.41s
✅ PYTHON black 2007 23 0 0 58.89s
✅ PYTHON isort 2007 39 0 0 2.86s
✅ REPOSITORY betterleaks yes no no 1.16s
✅ REPOSITORY checkov yes no no 34.04s
✅ REPOSITORY git_diff yes no no 0.1s
✅ REPOSITORY secretlint yes no no 101.32s
✅ REPOSITORY syft yes no no 2.96s
✅ REPOSITORY trivy-sbom yes no no 2.64s
✅ YAML prettier 11 0 0 0 0.52s
✅ YAML v8r 11 0 0 16.06s
✅ YAML yamllint 11 0 0 0.85s

Notices

⚠️ Your configuration references items that have been removed from MegaLinter and are ignored: MAKEFILE_CHECKMAKE. See Removed linters to find their replacements.

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@10.0.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is provided by OX Security
Show us your support by starring ⭐ the repository

@FlorianPfaff
FlorianPfaff merged commit e141379 into main Aug 22, 2026
15 of 26 checks passed
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.

1 participant