Skip to content

Commit e24faa5

Browse files
authored
fix dropstored for sparse matrices (#20516)
1 parent 1b7a684 commit e24faa5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

base/sparse/sparsematrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2745,7 +2745,7 @@ function dropstored!(A::SparseMatrixCSC, i::Integer, j::Integer)
27452745
# Entry A[i,j] is stored. Drop and return.
27462746
deleteat!(A.rowval, searchk)
27472747
deleteat!(A.nzval, searchk)
2748-
@simd for m in j:(A.n + 1)
2748+
@simd for m in (j+1):(A.n + 1)
27492749
@inbounds A.colptr[m] -= 1
27502750
end
27512751
end

test/sparse/sparse.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,3 +1705,19 @@ end
17051705
@testset "issue #14398" begin
17061706
@test transpose(view(speye(10), 1:5, 1:5)) eye(5,5)
17071707
end
1708+
1709+
@testset "dropstored issue #20513" begin
1710+
x = sparse(rand(3,3))
1711+
Base.SparseArrays.dropstored!(x, 1, 1)
1712+
@test x[1, 1] == 0.0
1713+
@test x.colptr == [1, 3, 6, 9]
1714+
Base.SparseArrays.dropstored!(x, 2, 1)
1715+
@test x.colptr == [1, 2, 5, 8]
1716+
@test x[2, 1] == 0.0
1717+
Base.SparseArrays.dropstored!(x, 2, 2)
1718+
@test x.colptr == [1, 2, 4, 7]
1719+
@test x[2, 2] == 0.0
1720+
Base.SparseArrays.dropstored!(x, 2, 3)
1721+
@test x.colptr == [1, 2, 4, 6]
1722+
@test x[2, 3] == 0.0
1723+
end

0 commit comments

Comments
 (0)