Part of fastpass in 'sort.list' can make sorting unstable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Part of fastpass in 'sort.list' can make sorting unstable

R devel mailing list
In the code of functions 'order' and 'sort.list' in R 3.5.0 alpha (in https://svn.r-project.org/R/branches/R-3-5-branch/src/library/base/R/sort.R), in "fastpass, take advantage of ALTREP metadata", there is "try the reverse since that's easy too...". If it succeeds, ties are reordered, violating stability of sorting.

Example:
x <- sort(c(1, 1, 3))
x  # 1 1 3
sort.list(x, decreasing=TRUE)  # should be 3 1 2

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Part of fastpass in 'sort.list' can make sorting unstable

Gabe Becker
Thanks for catching this. This is easy to take out without touching the
rest of the machinery. It also wouldn't be too hard to write a
still-faster-but-not-quite-as-much-path which correctly reverses the
sortedness of a sorted vector that includes ties. My suspicion, without
being the one who will ultimately make that decision, is that that wouldn't
go into 3.5.0 though.

Best,
~G

On Fri, Apr 6, 2018 at 3:03 PM, Suharto Anggono Suharto Anggono via R-devel
<[hidden email]> wrote:

> In the code of functions 'order' and 'sort.list' in R 3.5.0 alpha (in
> https://svn.r-project.org/R/branches/R-3-5-branch/src/
> library/base/R/sort.R), in "fastpass, take advantage of ALTREP metadata",
> there is "try the reverse since that's easy too...". If it succeeds, ties
> are reordered, violating stability of sorting.
>
> Example:
> x <- sort(c(1, 1, 3))
> x  # 1 1 3
> sort.list(x, decreasing=TRUE)  # should be 3 1 2
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>


--
Gabriel Becker, Ph.D
Scientist
Bioinformatics and Computational Biology
Genentech Research

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Part of fastpass in 'sort.list' can make sorting unstable

Tierney, Luke
In reply to this post by R devel mailing list
Thanks -- fixed in R-devel and R-3-5-branch.

luke

On Fri, 6 Apr 2018, Suharto Anggono Suharto Anggono via R-devel wrote:

> In the code of functions 'order' and 'sort.list' in R 3.5.0 alpha (in https://svn.r-project.org/R/branches/R-3-5-branch/src/library/base/R/sort.R), in "fastpass, take advantage of ALTREP metadata", there is "try the reverse since that's easy too...". If it succeeds, ties are reordered, violating stability of sorting.
>
> Example:
> x <- sort(c(1, 1, 3))
> x  # 1 1 3
> sort.list(x, decreasing=TRUE)  # should be 3 1 2
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa                  Phone:             319-335-3386
Department of Statistics and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   [hidden email]
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel