-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFM: Added permute!, permute!! (renamed permute -> permutedims) #2201
Conversation
Why is the reason of the second |
Maybe |
The current |
The main trick for permuting in place is finding the start of each cycle in the permutation. The literature suggests testing successive indices in the permutation array to see if it is the min element in a new cycle, but these papers were concerned with permuting very small lists, and doing this is really slow. I also tried keeping a separate The double-bang version is still useful to export if you want to reuse a permutation and Regarding naming: how about I'm also okay with |
|
|
I've changed |
We can probably just keep |
Can I suggest instead keeping |
But I can change |
OK, I would like to merge this very soon so we can get the renames in for 0.1. |
Sorry about the commented-out code. I had removed it at one point, but I forgot to push that change. I finished updating the documentation and added some tests. The tests are currently part of sorting, though it might be good to create a set of combinatorics tests, since not many of those functions are currently tested. |
Just noticed that I forgot to update permutedims/ipermutedims tests. |
* these permute an array according to a given permutation * permute renamed to permutedims * findnext defined (and used by permute!) * findfirst defined in terms of findnext
Fixed now. |
This is great. The test and doc updates are much appreciated! |
RFM: Added permute!, permute!! (renamed permute -> permutedims)
Yes, I think that permutedims is a great name – it's super clear. Having an addition argument to transpose might be nice, but it's not nearly as clear to read. I'm even warming to the idea of having permute!! as a function name. I mean, there's no way you're going to use that by accident, right? But it's there if you just happen to need it. |
These functions apply a permutation to a vector (or strings, whatever) in place. They're slower than simply writing
a[p]
, wherep
is a permutation, but are useful when memory is a concern. In particular, I'm wanting to use a version of them for sorting DataFrames.Also added
findnext
, and definedfindfirst
in terms offindnext
(used bypermute!!
).I could just put these in DataFrames, but thought they would be more generally useful.
Unfortunately, the names conflict with
permute
, which permutes the order of the dimensions of an array. So eitherpermute
orpermute!{!}
should probably be renamed. I don't really like the naming ofpermute
, but it has historical precedence (and matlab users would be very confused if it changed...).Edit: per the discussion below, permute was renamed to permutedims.