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

Open
#279 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python, pytorch
Domain
data

Research direction

Start by reproducing the failing calls through array_api_compat.torch.result_type, using the integer and unsigned-integer combinations listed in the issue. Compare the results with strict.result_type and confirm that the standard-defined combinations no longer raise the reported promotion error.

Written by the indexing model from the issue text.

Description

blocked by upstream

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.
Dominant language
Python
Stars
131
Forks
49
Avg merge
2d 8h
Merged PRs (30d)
6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from data-apis/array-api-compat

All issues in data-apis/array-api-compat

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.