Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch.result_type does not define result of most cross-integral type operations #279

Open
mdhaber opened this issue Mar 17, 2025 · 1 comment

Comments

@mdhaber
Copy link

mdhaber commented Mar 17, 2025

The result_type of many int/uint and uint/uint combinations are defined by the standard, but torch.result_type does not support them. For instance:

from array_api_compat import torch
torch.result_type(torch.uint16, torch.uint32)
# RuntimeError: Promotion for uint16, uint32, uint64 types is not supported, attempted to promote UInt16 and UInt32
from array_api_compat import numpy, torch
import array_api_strict as strict


for xp in [numpy, torch, dask, jax, tensorflow]:
    dtypes = ["int8", "int16", "int32", "int64",
              "uint8", "uint16", "uint32", "uint64"]
    for dtype_a in dtypes:
        for dtype_b in dtypes:
            try:
                res = xp.result_type(getattr(xp, dtype_a), getattr(xp, dtype_b))
            except:
                try:
                    res = strict.result_type(getattr(strict, dtype_a), getattr(strict, dtype_b))
                    print(f"`result_type({dtype_a}, {dtype_b})` is defined by the standard, but torch does not support it.")
                except:
                    pass
                    # print(f"`result_type({dtype_a}, {dtype_b})` not defined by the standard.")
`result_type(int8, uint16)` is defined by the standard, but torch does not support it.
`result_type(int8, uint32)` is defined by the standard, but torch does not support it.
`result_type(int16, uint16)` is defined by the standard, but torch does not support it.
`result_type(int16, uint32)` is defined by the standard, but torch does not support it.
`result_type(int32, uint16)` is defined by the standard, but torch does not support it.
`result_type(int32, uint32)` is defined by the standard, but torch does not support it.
`result_type(int64, uint16)` is defined by the standard, but torch does not support it.
`result_type(int64, uint32)` is defined by the standard, but torch does not support it.
`result_type(uint8, uint16)` is defined by the standard, but torch does not support it.
`result_type(uint8, uint32)` is defined by the standard, but torch does not support it.
`result_type(uint8, uint64)` is defined by the standard, but torch does not support it.
`result_type(uint16, int8)` is defined by the standard, but torch does not support it.
`result_type(uint16, int16)` is defined by the standard, but torch does not support it.
`result_type(uint16, int32)` is defined by the standard, but torch does not support it.
`result_type(uint16, int64)` is defined by the standard, but torch does not support it.
`result_type(uint16, uint8)` is defined by the standard, but torch does not support it.
`result_type(uint16, uint32)` is defined by the standard, but torch does not support it.
`result_type(uint16, uint64)` is defined by the standard, but torch does not support it.
`result_type(uint32, int8)` is defined by the standard, but torch does not support it.
`result_type(uint32, int16)` is defined by the standard, but torch does not support it.
`result_type(uint32, int32)` is defined by the standard, but torch does not support it.
`result_type(uint32, int64)` is defined by the standard, but torch does not support it.
`result_type(uint32, uint8)` is defined by the standard, but torch does not support it.
`result_type(uint32, uint16)` is defined by the standard, but torch does not support it.
`result_type(uint32, uint64)` is defined by the standard, but torch does not support it.
`result_type(uint64, uint8)` is defined by the standard, but torch does not support it.
`result_type(uint64, uint16)` is defined by the standard, but torch does not support it.
`result_type(uint64, uint32)` is defined by the standard, but torch does not support it.
@ev-br
Copy link
Member

ev-br commented Mar 17, 2025

Basically, torch uintN support is very incomplete: #253

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants