Skip to content

Commit

Permalink
Fix sparse Subarray fill! (JuliaLang#38021)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Bauman <[email protected]>
  • Loading branch information
dkarrasch and mbauman authored Oct 20, 2020
1 parent 7cd892f commit a188457
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ function Base.fill!(V::SubArray{Tv, <:Any, <:AbstractSparseMatrixCSC{Tv}, <:Tupl
end
end
"""
Helper method for immediately preceding setindex! method. For all (i,j) such that i in I and
Helper method for immediately preceding fill! method. For all (i,j) such that i in I and
j in J, assigns zero to A[i,j] if A[i,j] is a presently-stored entry, and otherwise does nothing.
"""
function _spsetz_setindex!(A::AbstractSparseMatrixCSC,
Expand Down Expand Up @@ -2624,7 +2624,7 @@ function _spsetz_setindex!(A::AbstractSparseMatrixCSC,
end
end
"""
Helper method for immediately preceding setindex! method. For all (i,j) such that i in I
Helper method for immediately preceding fill! method. For all (i,j) such that i in I
and j in J, assigns x to A[i,j] if A[i,j] is a presently-stored entry, and allocates and
assigns x to A[i,j] if A[i,j] is not presently stored.
"""
Expand Down Expand Up @@ -2704,7 +2704,7 @@ function _spsetnz_setindex!(A::AbstractSparseMatrixCSC{Tv}, x::Tv,
resize!(nzvalA, nnzA)
end
r = rowidx:(rowidx+(new_stop-new_ptr))
rowvalA[r] .= I[new_ptr:new_stop]
rowvalA[r] .= I isa Number ? I : I[new_ptr:new_stop]
for rr in r
nzvalA[rr] = x
end
Expand Down
6 changes: 6 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,12 @@ end
@test a[1,:] == sparse([1; 1; 3:10])
a[1:0,2] .= 1
@test a[:,2] == sparse([1:10;])
a[3,2:3] .= 1 # one stored, one new value
@test a[3,2:3] == sparse([1; 1])
a[5:6,1] .= 1 # only new values
@test a[:,1] == sparse([1; 0; 0; 0; 1; 1; 0; 0; 0; 0;])
a[2:4,2:3] .= 3 # two ranges
@test nnz(a) == 24

@test_throws BoundsError a[:,11] = spzeros(10,1)
@test_throws BoundsError a[11,:] = spzeros(1,10)
Expand Down

0 comments on commit a188457

Please sign in to comment.