Open
Description
If you try to use filter!
on a SparseVector
, it fails with an internal method error for deleteat!
. And then your sparse vector is corrupted:
julia> using SparseArrays
julia> x = sparsevec(1:2:7, 1:4, 8)
8-element SparseVector{Int64, Int64} with 4 stored entries:
[1] = 1
[3] = 2
[5] = 3
[7] = 4
julia> filter!(iseven, x)
ERROR: MethodError: no method matching deleteat!(::SparseVector{Int64, Int64}, ::UnitRange{Int64})
Closest candidates are:
deleteat!(::Vector, ::AbstractUnitRange{<:Integer})
@ Base array.jl:1525
deleteat!(::Vector, ::AbstractVector)
@ Base array.jl:1567
deleteat!(::Vector, ::Any)
@ Base array.jl:1566
...
Stacktrace:
[1] filter!(f::typeof(iseven), a::SparseVector{Int64, Int64})
@ Base .\array.jl:2662
[2] top-level scope
@ REPL[23]:1
julia> x
8-element SparseVector{Int64, Int64} with 6 stored entries:
[1] = 0
[2] = 2
[3] = 0
[4] = 0
[5] = 4
[7] = 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment