Delete! in sparse matrix

suppose you have the following sparse matrix

julia> type A end

julia> m=spzeros(A,10,10)
10×10 SparseMatrixCSC{A,Int64} with 0 stored entries

julia> m[1,1] = A()
A()

Now I would like to remove the element in (1,1).
If m was a dictionary I would use delete!(m, (1,1)). Is there a similar method for sparse matrices?

Cheers,
Carlo

1 Like

You need to define what “zero” means for your type, consider:

julia> m[1,2]
------ MethodError --------------------- Stacktrace (most recent call last)

 [1] — getindex(::SparseMatrixCSC{A,Int64}, ::Int64, ::Int64) at sparsematrix.jl:2092

MethodError: no method matching zero(::Type{A})
Closest candidates are:
  zero(::Type{Base.LibGit2.Oid}) at libgit2/oid.jl:88
  zero(::Type{Base.Pkg.Resolve.VersionWeights.VWPreBuildItem}) at pkg/resolve/versionweight.jl:80
  zero(::Type{Base.Pkg.Resolve.VersionWeights.VWPreBuild}) at pkg/resolve/versionweight.jl:120
  ...

Once you’ve done that, set m[1,1]=your_zero. If you want to free the memory used now storing a “zero” at m[1,1] use dropzero!.

1 Like

nice, thanks!