Skip to content

exceptions which differ in numpy and pytorch #20

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

Closed
ev-br opened this issue Jan 13, 2023 · 1 comment
Closed

exceptions which differ in numpy and pytorch #20

ev-br opened this issue Jan 13, 2023 · 1 comment

Comments

@ev-br
Copy link
Collaborator

ev-br commented Jan 13, 2023

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.

@ev-br
Copy link
Collaborator Author

ev-br commented Feb 28, 2023

Let's fold this into #5 and close as a duplicate.

@ev-br ev-br closed this as completed Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant