-
Notifications
You must be signed in to change notification settings - Fork 175
Make Sortex stable #2654
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
Make Sortex stable #2654
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2373,7 +2373,7 @@ InstallMethod( Sortex, | |
|
|
||
| n := Length(list); | ||
| index := [1..n]; | ||
| SortParallel(list, index); | ||
| StableSortParallel(list, index); | ||
| return PermList(index)^-1; | ||
|
|
||
| end ); | ||
|
|
@@ -2391,7 +2391,7 @@ InstallMethod( Sortex, | |
|
|
||
| n := Length(list); | ||
| index := [1..n]; | ||
| SortParallel(list, index, comp); | ||
| StableSortParallel(list, index, comp); | ||
| return PermList(index)^-1; | ||
|
|
||
| end ); | ||
|
|
@@ -2434,37 +2434,12 @@ end ); | |
| InstallMethod( SortingPerm, | ||
| [ IsDenseList ], | ||
| function( list ) | ||
| local both, perm, i, l; | ||
| local copy; | ||
|
|
||
| # {\GAP} supports permutations only up to `MAX_SIZE_LIST_INTERNAL'. | ||
| if not IsSmallList( list ) then | ||
| Error( "<list> must have length at most ", MAX_SIZE_LIST_INTERNAL ); | ||
| fi; | ||
|
|
||
| # make a new list that contains the elements of <list> and their indices | ||
| both := []; | ||
| l:= Length( list ); | ||
| for i in [ 1 .. l ] do | ||
| both[i] := [ list[i], i ]; | ||
| od; | ||
|
|
||
| # Sort the new list according to the first item (stable). | ||
| # This needs more memory than a call of 'Sort' but is much faster. | ||
| # (The change was proposed by Frank Lübeck.) | ||
| both := Set( both ); | ||
|
|
||
| # Remember the permutation. | ||
| perm := []; | ||
| perm{ [ 1 .. l ] }:= both{ [ 1 .. l ] }[2]; | ||
|
|
||
| # return the permutation mapping <list> onto the sorted list | ||
| return PermList( perm )^(-1); | ||
| copy := ShallowCopy(list); | ||
| return Sortex(copy); | ||
| end ); | ||
|
|
||
| InstallMethod( SortingPerm, | ||
| "for a dense and sorted list", | ||
| [ IsDenseList and IsSortedList ], SUM_FLAGS, | ||
| list -> () ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ChrisJefferson any particular reason this method was removed? I see no mention of this change in the PR description nor the commit message.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was part of making SortingPerm be exactly the same as SortEx.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why that requires removing this optimization, though? Now if the input is sorted, we make a copy, sort that, and compute the identity permutation from that...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could probably have been left in, I wouldn't have a problem with it being re-added but I wasn't sure it was worth it, for a fairly unusual case.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this method as an illustration of the idea to avoid working by using known information. |
||
|
|
||
|
|
||
| ############################################################################# | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| gap> ll:= [ 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 1, 1, 2, 1, 2, 1, 2, 2, 1, 2 ];; | ||
| gap> Sortex( ll ); | ||
| (2,13,19,10,5,15,7,16,8,4)(3,14,20,22,23,24,12,6)(9,17)(11,18,21) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move the paragraph to the beginning of the manual section on
Sorting Lists.In particular for someone reading the manual (and not the source),
it is not clear that this paragraph belongs to all subsections and not just to the last one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now done. Also mentioned better in the documentation for sortex that it is stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great.
Thanks for this improvement.