Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sparse Subarray fill! #38021

Merged
merged 7 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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