Skip to content

BUG: torch.meshgrid RuntimeError if no arrays#425

Open
Nin17 wants to merge 3 commits intodata-apis:mainfrom
Nin17:torch_meshgrid
Open

BUG: torch.meshgrid RuntimeError if no arrays#425
Nin17 wants to merge 3 commits intodata-apis:mainfrom
Nin17:torch_meshgrid

Conversation

@Nin17
Copy link
Copy Markdown

@Nin17 Nin17 commented Apr 27, 2026

fixes #424

Copilot AI review requested due to automatic review settings April 27, 2026 12:55
@Nin17 Nin17 changed the title BUG: torch RuntimeError if no arrays BUG: torch.meshgrid RuntimeError if no arrays Apr 27, 2026
@Nin17
Copy link
Copy Markdown
Author

Nin17 commented Apr 27, 2026

Should I also update the tests to test for this? Or should this be tested at array-api-tests?

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes PyTorch backend meshgrid behavior to match NumPy/Array API expectations when called with no input arrays.

Changes:

  • Return an empty tuple from array_api_compat.torch.meshgrid() when called with no arrays (avoids PyTorch RuntimeError).
  • Keep explicitly passing indexing= through to torch.meshgrid for non-empty inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread array_api_compat/torch/_aliases.py
Comment thread array_api_compat/torch/_aliases.py
@ev-br
Copy link
Copy Markdown
Member

ev-br commented Apr 27, 2026

Should I also update the tests to test for this? Or should this be tested at array-api-tests?

Given that the array-api-tests test does not catch this, I think it could be nice to add a quick test here, yes. https://github.com/data-apis/array-api-compat/blob/main/tests/test_torch.py#L117 is the existing torch / meshrid test.

Nin17 added 2 commits April 27, 2026 15:24
check indexing first - consistency with numpy+jax.numpy
@ev-br ev-br added this to the 1.15 milestone Apr 27, 2026
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.

torch.meshgrid raises RuntimeError if no arrays are passed

3 participants