several `torch` binary functions don't accept scalars for one argument
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.
Would be great to report these to pytorch itself. Meanwhile we'll need a workaround in -compat indeed.
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?
cross-ref https://github.com/data-apis/array-api-compat/pull/272 and https://github.com/data-apis/array-api-tests/pull/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.
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
This is marked as "blocked by upstream", but couldn't array_api_compat convert the scalar argument to a tensor of the result dtype before passing it to torch?