8000 exceptions which differ in numpy and pytorch · Issue #20 · Quansight-Labs/numpy_pytorch_interop · GitHub
[go: up one dir, main page]

Skip to content 8000
exceptions which differ in numpy and pytorch #20
@ev-br

Description

@ev-br

In some cases NumPy and PyTorch raise different exception classes: numpy raises a ValueError or TypeError, while pytorch defaults to RuntimeError.

For instance (this one is straight from the numpy test suite) subtracting booleans :

In [12]: a = np.ones((), dtype=np.bool_); a - a
Input In [12], in <cell line: 1>()
----> 1 a = np.ones((), dtype=np.bool_); a - a

TypeError: numpy boolean subtract, the `-` operator, is not supported, use the bitwise_xor, the `^` operator, or the logical_xor function instead.

The matching pytorch call raises a RuntmeError.

For the time being, I'm adding a raises((TypeError, RuntimeError)) in the test suite, with an intention to revisit this later, and either translate exceptions everywhere, or just document the difference.

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

      0