From e83b50ca4b7f5586adf4f30125d41e91f92e55f9 Mon Sep 17 00:00:00 2001 From: Chris Ninham <61634310+Nin17@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:51:59 +0200 Subject: [PATCH 1/3] BUG: torch RuntimeError if no arrays --- array_api_compat/torch/_aliases.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/array_api_compat/torch/_aliases.py b/array_api_compat/torch/_aliases.py index 5969e4db..0105c731 100644 --- a/array_api_compat/torch/_aliases.py +++ b/array_api_compat/torch/_aliases.py @@ -936,7 +936,7 @@ def meshgrid(*arrays: Array, indexing: Literal['xy', 'ij'] = 'xy') -> tuple[Arra # torch <= 2.9 emits a UserWarning: "torch.meshgrid: in an upcoming release, it # will be required to pass the indexing argument." # Thus always pass it explicitly. - return torch.meshgrid(*arrays, indexing=indexing) + return torch.meshgrid(*arrays, indexing=indexing) if arrays else () __all__ = ['asarray', 'result_type', 'can_cast', From 72ffa81654eca2a921fc84f478ee3aeb5f5e785d Mon Sep 17 00:00:00 2001 From: Chris Ninham <61634310+Nin17@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:24:10 +0200 Subject: [PATCH 2/3] TST: torch.meshgrid no arrays --- tests/test_torch.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_torch.py b/tests/test_torch.py index b064a46d..3d6ebc46 100644 --- a/tests/test_torch.py +++ b/tests/test_torch.py @@ -115,7 +115,7 @@ def apply_clip_compat(a): def test_meshgrid(): - """Verify that array_api_compat.torch.meshgrid defaults to indexing='xy'.""" + """Verify that array_api_compat.torch.meshgrid defaults to indexing='xy', and supports passing no arrays.""" x, y = xp.asarray([1, 2]), xp.asarray([4]) @@ -142,6 +142,8 @@ def test_meshgrid(): assert Y.shape == Y_ij.shape assert xp.all(Y == Y_ij) + assert not xp.meshgrid() + def test_argsort_stable(): """Verify that argsort defaults to a stable sort.""" From 8422e6953f14069d7bec82978b9af1df8d3b76e7 Mon Sep 17 00:00:00 2001 From: Chris Ninham <61634310+Nin17@users.noreply.github.com> Date: Mon, 27 Apr 2026 15:36:34 +0200 Subject: [PATCH 3/3] BUG: torch.meshgrid check indexing first - consistency with numpy+jax.numpy --- array_api_compat/torch/_aliases.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/array_api_compat/torch/_aliases.py b/array_api_compat/torch/_aliases.py index 0105c731..e27c3ca2 100644 --- a/array_api_compat/torch/_aliases.py +++ b/array_api_compat/torch/_aliases.py @@ -936,6 +936,8 @@ def meshgrid(*arrays: Array, indexing: Literal['xy', 'ij'] = 'xy') -> tuple[Arra # torch <= 2.9 emits a UserWarning: "torch.meshgrid: in an upcoming release, it # will be required to pass the indexing argument." # Thus always pass it explicitly. + if indexing not in ("xy", "ij"): + raise ValueError(f'torch.meshgrid: indexing must be one of "xy" or "ij", but received: {indexing}') return torch.meshgrid(*arrays, indexing=indexing) if arrays else ()