Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Common definitions

import Base: sort, findall, copy!
import Base: sort!, findall, copy!
import LinearAlgebra: promote_to_array_type, promote_to_arrays_
using LinearAlgebra: _SpecialArrays, _DenseConcatGroup

Expand Down Expand Up @@ -2123,15 +2123,15 @@ function _densifystarttolastnz!(x::SparseVector)
end

#sorting
function sort(x::AbstractCompressedVector{Tv,Ti}; kws...) where {Tv,Ti}
allvals = push!(copy(nonzeros(x)),zero(Tv))
sinds = sortperm(allvals;kws...)
n,k = length(x),length(allvals)
z = findfirst(isequal(k),sinds)::Int
newnzind = Vector{Ti}(1:k-1)
newnzind[z:end] .+= n-k+1
newnzvals = allvals[deleteat!(sinds[1:k],z)]
typeof(x)(n,newnzind,newnzvals)
function sort!(x::AbstractCompressedVector; kws...)
nz = nonzeros(x)
sort!(nz; kws...)
i = searchsortedfirst(nz, zero(eltype(x)); kws...)
I = nonzeroinds(x)
Base.require_one_based_indexing(x, nz, I)
I[1:i-1] .= 1:i-1
I[i:end] .= i+length(x)-length(nz):length(x)
x
end

function fkeep!(f, x::AbstractCompressedVector{Tv}) where Tv
Expand Down