Add dtype checks in meta dispatch for various ordering ops (#159556)

This adds data type checks for the unsupported bool and complex types for argmax/min topk, sort, minimum, maximum. As listed here:

0a99b026d6/torch/testing/_internal/common_methods_invocations.py (L21076)

Currently the ops will fail on CPU or CUDA calculation, rather than at meta dispatch stage as with for example max: 0a99b026d6/aten/src/ATen/native/TensorCompare.cpp (L285) . This will catch it early.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/159556
Approved by: https://github.com/janeyx99
This commit is contained in:
Matthew Haddock
2025-08-14 17:06:23 +00:00
committed by PyTorch MergeBot
parent cd8d8c18f5
commit 077cb38974
4 changed files with 71 additions and 6 deletions

View File

@ -179,7 +179,7 @@ class TestSortAndSelect(TestCase):
def test_complex_unsupported_cpu(self):
x = torch.tensor([3.0 + 2j, 4.0 + 3j])
with self.assertRaisesRegex(
ValueError, "Sort currently does not support complex dtypes on CPU."
RuntimeError, " Sort does not support complex dtypes on CPU"
):
torch.sort(input=x)