Skip to content

add shuffle(::NTuple) to Random #56906

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Conversation

nsajko
Copy link
Contributor

@nsajko nsajko commented Dec 26, 2024

Fixes #56728

@nsajko nsajko added randomness Random number generation and the Random stdlib stdlib Julia's standard library feature Indicates new feature / enhancement requests labels Dec 26, 2024
@rfourquet rfourquet added needs docs Documentation for this change is required needs news A NEWS entry is required for this change labels May 9, 2025
@nsajko nsajko force-pushed the shuffle_ntuple branch from 213f598 to 7bb811d Compare May 9, 2025 10:29
@nsajko nsajko force-pushed the shuffle_ntuple branch from 70fa8ac to 4577162 Compare May 9, 2025 10:39
@nsajko nsajko added status: waiting for PR reviewer DO NOT MERGE Do not merge this PR! and removed needs news A NEWS entry is required for this change needs docs Documentation for this change is required status: waiting for PR reviewer labels May 9, 2025
@nsajko
Copy link
Contributor Author

nsajko commented May 9, 2025

Unlike shuffle!, randperm! is currently restricted to Array, not admitting Memory, so this PR now depends on randperm! supporting Memory. Clearly it would be good to support more types than just Array with randperm! anyway. Will probably make another PR for that soon.

EDIT: decided to just forgo randperm! for now

@nsajko nsajko removed the DO NOT MERGE Do not merge this PR! label May 9, 2025
@rfourquet rfourquet added the needs compat annotation Add !!! compat "Julia x.y" to the docstring label May 12, 2025
@rfourquet
Copy link
Member

I'm surprised to see that your implementation allocates on the master branch, but not on v1.12, do you have an idea why that is the case? Not necessariy a problem though, it seems to be roughly the same speed.

@nsajko
Copy link
Contributor Author

nsajko commented May 31, 2025

I'm surprised to see that your implementation allocates on the master branch, but not on v1.12, do you have an idea why that is the case?

Can't reproduce:

julia> rng::Xoshiro = Xoshiro();

julia> tup::NTuple{15, Int} = ntuple(identity, 15)
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)

julia> @btime shuffle(rng, tup)
  71.280 ns (0 allocations: 0 bytes)
(13, 4, 6, 12, 2, 15, 3, 10, 1, 11, 8, 9, 5, 7, 14)

Perhaps it was an issue only for some commits on the master branch, now fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Indicates new feature / enhancement requests randomness Random number generation and the Random stdlib status: waiting for PR reviewer stdlib Julia's standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support shuffle(::NTuple)
3 participants