Skip to content

What to do for torch result_type()? #43

Closed
@tylerjereddy

Description

@tylerjereddy

While working on scipy/scipy#18286 and tylerjereddy/scipy#70 to test passing through different array types in scipy.signal.welch() I ran into the same thing Ralf did a few years ago here: pytorch/pytorch#51284

Since that has been open for quite some time, should we add a shim to deal with torch.result_type only accepting numbers/tensors and not types proper? Or should downstream libs deal with this in their own way?

Traceback I saw was:

/home/tyler/python_310_scipy_dev_work/lib/python3.10/site-packages/array_api_compat-1.2-py3.10.egg/array_api_compat/torch/_aliases.py:124: in result_type
    return torch.result_type(x, y)
E   TypeError: result_type() received an invalid combination of arguments - got (Tensor, torch.dtype), but expected one of:
E    * (Tensor tensor, Tensor other)
E         didn't match because some of the arguments have invalid types: (Tensor, !torch.dtype!)
E    * (Number scalar, Tensor tensor)
E         didn't match because some of the arguments have invalid types: (!Tensor!, !torch.dtype!)
E    * (Tensor tensor, Number other)
E         didn't match because some of the arguments have invalid types: (Tensor, !torch.dtype!)
E    * (Number scalar1, Number scalar2)
E         didn't match because some of the arguments have invalid types: (!Tensor!, !torch.dtype!)
        arrays_and_dtypes = (tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]), torch.complex64)
        x          = tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
        xdt        = torch.float32
        y          = torch.complex64
        ydt        = torch.complex64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions