|
2 | 2 |
|
3 | 3 | ### Common definitions
|
4 | 4 |
|
5 |
| -import Base: sort, findall, copy! |
| 5 | +import Base: sort!, findall, copy! |
6 | 6 | import LinearAlgebra: promote_to_array_type, promote_to_arrays_
|
7 | 7 | using LinearAlgebra: _SpecialArrays, _DenseConcatGroup
|
8 | 8 |
|
@@ -2123,15 +2123,15 @@ function _densifystarttolastnz!(x::SparseVector)
|
2123 | 2123 | end
|
2124 | 2124 |
|
2125 | 2125 | #sorting
|
2126 |
| -function sort(x::AbstractCompressedVector{Tv,Ti}; kws...) where {Tv,Ti} |
2127 |
| - allvals = push!(copy(nonzeros(x)),zero(Tv)) |
2128 |
| - sinds = sortperm(allvals;kws...) |
2129 |
| - n,k = length(x),length(allvals) |
2130 |
| - z = findfirst(isequal(k),sinds)::Int |
2131 |
| - newnzind = Vector{Ti}(1:k-1) |
2132 |
| - newnzind[z:end] .+= n-k+1 |
2133 |
| - newnzvals = allvals[deleteat!(sinds[1:k],z)] |
2134 |
| - typeof(x)(n,newnzind,newnzvals) |
| 2126 | +function sort!(x::AbstractCompressedVector; kws...) |
| 2127 | + nz = nonzeros(x) |
| 2128 | + sort!(nz; kws...) |
| 2129 | + i = searchsortedfirst(nz, zero(eltype(x)); kws...) |
| 2130 | + I = nonzeroinds(x) |
| 2131 | + Base.require_one_based_indexing(x, nz, I) |
| 2132 | + I[1:i-1] .= 1:i-1 |
| 2133 | + I[i:end] .= i+length(x)-length(nz):length(x) |
| 2134 | + x |
2135 | 2135 | end
|
2136 | 2136 |
|
2137 | 2137 | function fkeep!(f, x::AbstractCompressedVector{Tv}) where Tv
|
|
0 commit comments