-
Notifications
You must be signed in to change notification settings - Fork 4
Tracker: semantic differences between numpy and pytorch #5
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
Comments
Here's one possibly ugly corner with scalars vs zero-dim arrays. I'm trying to have a system where
|
Hmm, maybe it's necessary to not support using as Python scalars (e.g. by using an ndarray subclass or a special flag to indicate that the 0-D array was actually a scalar). Or maybe it's too much of a corner case. Probably for now just document the problem, add an |
Let's see if we can pull off the following: scalars are 0d arrays and do not decay to python scalars unless explicitly requested. In the example above this means the Out[357] behavior unless there is an explicit conversion to the python scalar, as in int(np.int32(2)) * [1, 2, 3]. We might even follow pytorch in allowing int(torch.Tensor([[[1]]])) which numpy raises on. |
As long as we do not special-case scalars, let's relax the NumPy casting rule that scalars do not upcast arrays. So, the casting rule is then everything upcasts everything else, and there is no value-based casting. |
Am splitting this tracker into two: this one is for numpy/pytorch differences, and gh-73 attempt to track the differences between the original numpy and our wrapper. |
This is to track situations where eponymous functions in numpy and torch have different semantics, and to record decisions about these. Typically, the difference is views vs copies.
flip:
np.flip
creates a view,torch.flip
creates a copy.slicing with negative step is not supported:
strides
are value strides, not byte stridesif given an
out=
array of a wrong size, numpy raises on an attempt to broadcast, while pytorch emits a warning and resizes the out arraysqueeze
on axes of non-zero length is a noop in torch, while numpy raisesndim == 0
: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 :
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 better document the difference.The text was updated successfully, but these errors were encountered: