Open
Description
Per the 2024.12 standard, these should work, but don't:
from array_api_compat import torch as xp
xp.minimum(xp.asarray(1), 2) # TypeError: minimum(): argument 'other' (position 2) must be Tensor, not int
xp.minimum(2, xp.asarray(1)) # TypeError: minimum(): argument 'input' (position 1) must be Tensor, not int
xp.copysign(xp.asarray(1.), 2) # OK
xp.copysign(2, xp.asarray(1.))
# TypeError: copysign() received an invalid combination of arguments - got (int, Tensor), but expected one of:
# * (Tensor input, Tensor other, *, Tensor out = None)
# * (Tensor input, Number other, *, Tensor out = None)
Looks like maximum
also has trouble. Haven't checked the rest of the functions that now accept scalars, but I assume others may have trouble.
Activity
xp_
functions,xp.asarray
on elementwise function args scipy/scipy#22683ev-br commentedon Mar 14, 2025
Would be great to report these to pytorch itself. Meanwhile we'll need a workaround in
-compat
indeed.mdhaber commentedon Mar 14, 2025
Maybe once we figure out the extent of the problem (e.g. other functions beyond
maximum
), we can report it.Or I've suggested before that we can probably work out a more streamlined reporting mechanism than to file the same issue in multiple places, customized for each affected backend. It might help if we can just ping someone from the libraries in these sorts of issues, and they can just add a link in a tracking issue in their project or something. Do you know anyone on the Torch side who is interested in array API compatibility who we might ping here?
ev-br commentedon Mar 15, 2025
cross-ref #272 and data-apis/array-api-tests#348
The bottom line seems to be that that in torch accepting scalars is more of an exception than a rule.
Not sure who to ping, sadly, and a conclusion from my offline discussions with several pytorch devs is that it's on us to report these sorts of issues. A pytorch issue will probably not be closed, but whether someone will open it for us.... I doubt it.
ev-br commentedon Mar 21, 2025
Testing shows 16 missing kernels, all xfailed for now: https://github.com/data-apis/array-api-compat/blob/1.11.2/torch-xfails.txt#L139
[-]`torch.minimum` and `torch.copysign` don't accept scalars for one argument[/-][+]several `torch` binary functions don't accept scalars for one argument[/+]diff
to allow Python scalar or 0d arrayappend
andprepend
? data-apis/array-api#930