Skip to content

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

Merged
charris merged 3 commits intonumpy:masterfrom
rgommers:fix-shuffle-object
Jan 24, 2021
Merged

MAINT: random shuffle: warn on unrecognized objects, fix empty array bug#18211
charris merged 3 commits intonumpy:masterfrom
rgommers:fix-shuffle-object

Conversation

@rgommers
Copy link
Copy Markdown
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
Copy Markdown
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