@@ -1560,8 +1560,14 @@ function sortperm(A::AbstractArray;
1560
1560
order:: Ordering = Forward,
1561
1561
scratch:: Union{Vector{<:Integer}, Nothing} = nothing ,
1562
1562
dims... ) # to optionally specify dims argument
1563
- ordr = ord (lt,by,rev,order)
1564
- if ordr === Forward && isa (A,Vector) && eltype (A)<: Integer
1563
+ if rev === true
1564
+ _sortperm (A; alg, order= ord (lt, by, true , order), scratch, dims... )
1565
+ else
1566
+ _sortperm (A; alg, order= ord (lt, by, nothing , order), scratch, dims... )
1567
+ end
1568
+ end
1569
+ function _sortperm (A:: AbstractArray ; alg, order, scratch, dims... )
1570
+ if order === Forward && isa (A,Vector) && eltype (A)<: Integer
1565
1571
n = length (A)
1566
1572
if n > 1
1567
1573
min, max = extrema (A)
@@ -1573,7 +1579,7 @@ function sortperm(A::AbstractArray;
1573
1579
end
1574
1580
end
1575
1581
ix = copymutable (LinearIndices (A))
1576
- sort! (ix; alg, order = Perm (ordr , vec (A)), scratch, dims... )
1582
+ sort! (ix; alg, order = Perm (order , vec (A)), scratch, dims... )
1577
1583
end
1578
1584
1579
1585
@@ -1615,7 +1621,7 @@ julia> sortperm!(p, A; dims=2); p
1615
1621
2 4
1616
1622
```
1617
1623
"""
1618
- function sortperm! (ix:: AbstractArray{T} , A:: AbstractArray ;
1624
+ @inline function sortperm! (ix:: AbstractArray{T} , A:: AbstractArray ;
1619
1625
alg:: Algorithm = DEFAULT_UNSTABLE,
1620
1626
lt= isless,
1621
1627
by= identity,
@@ -1630,7 +1636,12 @@ function sortperm!(ix::AbstractArray{T}, A::AbstractArray;
1630
1636
if ! initialized
1631
1637
ix .= LinearIndices (A)
1632
1638
end
1633
- sort! (ix; alg, order = Perm (ord (lt, by, rev, order), vec (A)), scratch, dims... )
1639
+
1640
+ if rev === true
1641
+ sort! (ix; alg, order= Perm (ord (lt, by, true , order), vec (A)), scratch, dims... )
1642
+ else
1643
+ sort! (ix; alg, order= Perm (ord (lt, by, nothing , order), vec (A)), scratch, dims... )
1644
+ end
1634
1645
end
1635
1646
1636
1647
# sortperm for vectors of few unique integers
0 commit comments