Skip to content
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

MAINT: random shuffle: warn on unrecognized objects, fix empty array bug #18211

Merged
merged 3 commits into from
Jan 24, 2021

Conversation

rgommers
Copy link
Member

@rgommers rgommers commented Jan 23, 2021

Closes gh-18206, which showed applying np.random.shuffle on PyTorch tensors gave silently incorrect results.

Also found an unrelated bug where shuffling empty array with axis=1 was broken for Generator.shuffle. This would trigger:

NotImplementedError: Axis argument is only supported on ndarray objects

because empty arrays would take the "untyped" path.

The bug exists only for Generator, not for RandomState (it doesn't have axis keyword for shuffle), but update both because it keeps implementations in sync and the change results in more understandable code also for RandomState.

This would trigger:
```
NotImplementedError: Axis argument is only supported on ndarray objects
```
because empty arrays and array scalars would take the "untyped" path.

The bug exists only for Generator, not in RandomState (it doesn't have
axis keyword for `shuffle`), but update both because it keeps
implementations in sync and the change results in more understandable
code also for RandomState.
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@charris charris merged commit 04b58d3 into numpy:master Jan 24, 2021
@charris
Copy link
Member

charris commented Jan 24, 2021

Thanks Ralf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[np.random] shuffle is not compatible with pytorch tensor
4 participants