Skip to content

Commit

Permalink
added warning for iterating while mutating a sparse matrix (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
matbesancon authored Jul 21, 2023
1 parent f8f0f40 commit b3872c8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ column. In conjunction with [`nonzeros`](@ref) and
# perform sparse wizardry...
end
end
!!! warning
Adding or removing nonzero elements to the matrix may invalidate the `nzrange`, one should not mutate the matrix while iterating.
"""
nzrange(S::AbstractSparseMatrixCSC, col::Integer) = getcolptr(S)[col]:(getcolptr(S)[col+1]-1)
nzrange(S::SparseMatrixCSCView, col::Integer) = nzrange(S.parent, S.indices[2][col])
Expand Down

0 comments on commit b3872c8

Please sign in to comment.