diff --git a/base/deprecated.jl b/base/deprecated.jl index 34132cfbc097b..4559e55082be7 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -574,13 +574,14 @@ end # issue #...: nonscalar indexed assignment of many values to many locations function deprecate_nonscalar_indexed_assignment!(A::AbstractArray, X::AbstractArray, I...) - shape = Base.index_shape(I...) + J = to_indices(A, I) + shape = Base.index_shape(J...) if shape == axes(X) depwarn("using `A[I...] = X` to implicitly broadcast the elements of `X` to many locations in `A` is deprecated. Use `A[I...] .= X` to explicitly opt-in to broadcasting.", :setindex!) - A[I...] .= X + A[J...] .= X else depwarn("using `A[I...] = X` to implicitly broadcast the elements of `X` to many locations in `A` is deprecated. Use `A[I...] .= reshape(X, axes(view(A, I...)))` to explicitly opt-in to broadcasting.", :setindex!) - A[I...] .= reshape(X, shape) + A[J...] .= reshape(X, shape) end end _unsafe_setindex!(::IndexStyle, A::AbstractArray, X::AbstractArray, I::Union{Real,AbstractArray}...) = deprecate_nonscalar_indexed_assignment!(A, X, I...) diff --git a/stdlib/SparseArrays/src/deprecated.jl b/stdlib/SparseArrays/src/deprecated.jl index 76f9f461a9b1e..6aa083dfbb993 100644 --- a/stdlib/SparseArrays/src/deprecated.jl +++ b/stdlib/SparseArrays/src/deprecated.jl @@ -227,6 +227,17 @@ import Base: asyncmap @deprecate dropzeros!(x, trim) dropzeros!(x, trim = trim) @deprecate droptol!(A, tol, trim) droptol!(A, tol, trim = trim) +# Multi-value setindex broadcasting +setindex!(A::SparseMatrixCSC, x::AbstractArray, i::Colon) = Base.deprecate_nonscalar_indexed_assignment!(A, x, i) +setindex!(A::SparseMatrixCSC, x::AbstractArray, i::Colon, j::Colon) = Base.deprecate_nonscalar_indexed_assignment!(A, x, i, j) +setindex!(A::SparseMatrixCSC, x::AbstractArray, i::Colon, j::Union{Integer, AbstractVector}) = Base.deprecate_nonscalar_indexed_assignment!(A, x, i, j) +setindex!(A::SparseMatrixCSC, x::AbstractArray, i::Union{Integer, AbstractVector}, j::Colon) = Base.deprecate_nonscalar_indexed_assignment!(A, x, i, j) +setindex!(A::SparseMatrixCSC, x::AbstractArray, i::Integer, J::AbstractVector{<:Integer}) = Base.deprecate_nonscalar_indexed_assignment!(A, x, i, J) +setindex!(A::SparseMatrixCSC, x::AbstractArray, I::AbstractVector{<:Integer}, j::Integer) = Base.deprecate_nonscalar_indexed_assignment!(A, x, I, j) +setindex!(A::SparseMatrixCSC, x::AbstractArray, I::AbstractVector{<:Integer}, J::AbstractVector{<:Integer}) = Base.deprecate_nonscalar_indexed_assignment!(A, x, I, J) +setindex!(A::SparseMatrixCSC, x::AbstractArray, I::AbstractVector{<:Real}) = Base.deprecate_nonscalar_indexed_assignment!(A, x, I) +setindex!(A::SparseMatrixCSC, x::AbstractArray, I::AbstractMatrix{Bool}) = Base.deprecate_nonscalar_indexed_assignment!(A, x, I) + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index f84f8b3a36c34..8931b39c133e1 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -2327,11 +2327,8 @@ function setindex!(A::SparseMatrixCSC{Tv,Ti}, v::Tv, i::Ti, j::Ti) where Tv wher return A end -setindex!(A::SparseMatrixCSC, v::AbstractMatrix, i::Integer, J::AbstractVector{<:Integer}) = setindex!(A, v, [i], J) -setindex!(A::SparseMatrixCSC, v::AbstractMatrix, I::AbstractVector{<:Integer}, j::Integer) = setindex!(A, v, I, [j]) - -setindex!(A::SparseMatrixCSC, x::Number, i::Integer, J::AbstractVector{<:Integer}) = setindex!(A, x, [i], J) -setindex!(A::SparseMatrixCSC, x::Number, I::AbstractVector{<:Integer}, j::Integer) = setindex!(A, x, I, [j]) +setindex!(A::SparseMatrixCSC, x, i::Integer, J::AbstractVector{<:Integer}) = setindex!(A, x, [i], J) +setindex!(A::SparseMatrixCSC, x, I::AbstractVector{<:Integer}, j::Integer) = setindex!(A, x, I, [j]) # Colon translation setindex!(A::SparseMatrixCSC, x, ::Colon) = setindex!(A, x, 1:length(A)) @@ -2339,7 +2336,7 @@ setindex!(A::SparseMatrixCSC, x, ::Colon, ::Colon) = setindex!(A, x, 1:size(A, 1 setindex!(A::SparseMatrixCSC, x, ::Colon, j::Union{Integer, AbstractVector}) = setindex!(A, x, 1:size(A, 1), j) setindex!(A::SparseMatrixCSC, x, i::Union{Integer, AbstractVector}, ::Colon) = setindex!(A, x, i, 1:size(A, 2)) -function setindex!(A::SparseMatrixCSC{Tv}, x::Number, +function setindex!(A::SparseMatrixCSC{Tv}, x, I::AbstractVector{<:Integer}, J::AbstractVector{<:Integer}) where Tv if isempty(I) || isempty(J); return A; end # lt=≤ to check for strict sorting @@ -2500,155 +2497,6 @@ function _spsetnz_setindex!(A::SparseMatrixCSC{Tv}, x::Tv, return A end -setindex!(A::SparseMatrixCSC{Tv,Ti}, S::Matrix, I::AbstractVector{T}, J::AbstractVector{T}) where {Tv,Ti,T<:Integer} = - setindex!(A, convert(SparseMatrixCSC{Tv,Ti}, S), I, J) - -setindex!(A::SparseMatrixCSC, v::AbstractVector, I::AbstractVector{<:Integer}, j::Integer) = setindex!(A, v, I, [j]) -setindex!(A::SparseMatrixCSC, v::AbstractVector, i::Integer, J::AbstractVector{<:Integer}) = setindex!(A, v, [i], J) -setindex!(A::SparseMatrixCSC, v::AbstractVector, I::AbstractVector{T}, J::AbstractVector{T}) where {T<:Integer} = - setindex!(A, reshape(v, length(I), length(J)), I, J) - -# A[I,J] = B -function setindex!(A::SparseMatrixCSC{Tv,Ti}, B::SparseMatrixCSC{Tv,Ti}, I::AbstractVector{T}, J::AbstractVector{T}) where {Tv,Ti,T<:Integer} - if size(B,1) != length(I) || size(B,2) != length(J) - throw(DimensionMismatch("")) - end - - issortedI = issorted(I) - issortedJ = issorted(J) - - if !issortedI && !issortedJ - pI = sortperm(I); @inbounds I = I[pI] - pJ = sortperm(J); @inbounds J = J[pJ] - B = B[pI, pJ] - elseif !issortedI - pI = sortperm(I); @inbounds I = I[pI] - B = B[pI,:] - elseif !issortedJ - pJ = sortperm(J); @inbounds J = J[pJ] - B = B[:, pJ] - end - - m, n = size(A) - mB, nB = size(B) - - if (!isempty(I) && (I[1] < 1 || I[end] > m)) || (!isempty(J) && (J[1] < 1 || J[end] > n)) - throw(BoundsError(A, (I, J))) - end - - if isempty(I) || isempty(J) - return A - end - - nI = length(I) - nJ = length(J) - - colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval - colptrB = B.colptr; rowvalB = B.rowval; nzvalB = B.nzval - - nnzS = nnz(A) + nnz(B) - - colptrS = copy(A.colptr) - rowvalS = copy(A.rowval) - nzvalS = copy(A.nzval) - - resize!(rowvalA, nnzS) - resize!(nzvalA, nnzS) - - colB = 1 - asgn_col = J[colB] - - I_asgn = falses(m) - I_asgn[I] = true - - ptrS = 1 - - @inbounds for col = 1:n - - # Copy column of A if it is not being assigned into - if colB > nJ || col != J[colB] - colptrA[col+1] = colptrA[col] + (colptrS[col+1]-colptrS[col]) - - for k = colptrS[col]:colptrS[col+1]-1 - rowvalA[ptrS] = rowvalS[k] - nzvalA[ptrS] = nzvalS[k] - ptrS += 1 - end - continue - end - - ptrA::Int = colptrS[col] - stopA::Int = colptrS[col+1] - ptrB::Int = colptrB[colB] - stopB::Int = colptrB[colB+1] - - while ptrA < stopA && ptrB < stopB - rowA = rowvalS[ptrA] - rowB = I[rowvalB[ptrB]] - if rowA < rowB - rowvalA[ptrS] = rowA - nzvalA[ptrS] = I_asgn[rowA] ? zero(Tv) : nzvalS[ptrA] - ptrS += 1 - ptrA += 1 - elseif rowB < rowA - if nzvalB[ptrB] != zero(Tv) - rowvalA[ptrS] = rowB - nzvalA[ptrS] = nzvalB[ptrB] - ptrS += 1 - end - ptrB += 1 - else - rowvalA[ptrS] = rowB - nzvalA[ptrS] = nzvalB[ptrB] - ptrS += 1 - ptrB += 1 - ptrA += 1 - end - end - - while ptrA < stopA - rowA = rowvalS[ptrA] - rowvalA[ptrS] = rowA - nzvalA[ptrS] = I_asgn[rowA] ? zero(Tv) : nzvalS[ptrA] - ptrS += 1 - ptrA += 1 - end - - while ptrB < stopB - rowB = I[rowvalB[ptrB]] - if nzvalB[ptrB] != zero(Tv) - rowvalA[ptrS] = rowB - nzvalA[ptrS] = nzvalB[ptrB] - ptrS += 1 - end - ptrB += 1 - end - - colptrA[col+1] = ptrS - colB += 1 - end - - deleteat!(rowvalA, colptrA[end]:length(rowvalA)) - deleteat!(nzvalA, colptrA[end]:length(nzvalA)) - - return A -end - -# Logical setindex! - -setindex!(A::SparseMatrixCSC, x::Matrix, I::Integer, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, findall(J)) -setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::Integer) = setindex!(A, sparse(x), findall(I), J) -setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), findall(I), findall(J)) -setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = setindex!(A, sparse(x), I, findall(J)) -setindex!(A::SparseMatrixCSC, x::Matrix, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = setindex!(A, sparse(x), findall(I),J) - -setindex!(A::Matrix, x::SparseMatrixCSC, I::Integer, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, findall(J)) -setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::Integer) = setindex!(A, Array(x), findall(I), J) -setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{Bool}) = setindex!(A, Array(x), findall(I), findall(J)) -setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{<:Integer}, J::AbstractVector{Bool}) = setindex!(A, Array(x), I, findall(J)) -setindex!(A::Matrix, x::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = setindex!(A, Array(x), findall(I), J) - -setindex!(A::SparseMatrixCSC, x, I::AbstractVector{Bool}) = throw(BoundsError()) function setindex!(A::SparseMatrixCSC, x, I::AbstractMatrix{Bool}) checkbounds(A, I) n = sum(I) @@ -2782,7 +2630,7 @@ function setindex!(A::SparseMatrixCSC, x, I::AbstractVector{<:Real}) # copy from last position till current column if (nadd > 0) - colptrB[(lastcol+1):col] = colptrA[(lastcol+1):col] .+ nadd + colptrB[(lastcol+1):col] .= colptrA[(lastcol+1):col] .+ nadd copylen = r1 - aidx if copylen > 0 copyto!(rowvalB, bidx, rowvalA, aidx, copylen) @@ -2857,6 +2705,167 @@ function setindex!(A::SparseMatrixCSC, x, I::AbstractVector{<:Real}) A end +# Multi-value indexed assignment A[...] .= B gets represented as `broadcast!(identity, view(A, ...), B)` +const _Idx = Union{Integer,AbstractVector{<:Integer}} +const CSCAssignmentView{I<:Union{Tuple{_Idx},Tuple{_Idx,_Idx}}} = SubArray{<:Any,<:Any,<:SparseMatrixCSC,I,false} +_getij(S::CSCAssignmentView{<:Tuple{AbstractVector,AbstractVector}}) = S.indices +_getij(S::CSCAssignmentView{<:Tuple{Integer,Integer}}) = (S.indices[1]:S.indices[1], S.indices[2]:S.indices[2]) +_getij(S::CSCAssignmentView{<:Tuple{Integer,AbstractVector}}) = (S.indices[1]:S.indices[1], S.indices[2]) +_getij(S::CSCAssignmentView{<:Tuple{AbstractVector,Integer}}) = (S.indices[1], S.indices[2]:S.indices[2]) +function _getij(S::CSCAssignmentView{<:Tuple{Integer}}) + v = CartesianIndices(S.parent)[S.indices[1]] + return (v.I[1]:v.I[1], v.I[2]:v.I[2]) +end +function _getij(S::CSCAssignmentView{<:Tuple{AbstractArray{CartesianIndex{2}}}}) + V = reinterpret(Int, S.indices[1]) + return @views (V[1:2:end], V[2:2:end]) +end +function _getij(S::CSCAssignmentView{<:Tuple{AbstractArray}}) + V = reinterpret(Int, CartesianIndices(S.parent)[S.indices[1]]) + return @views (V[1:2:end], V[2:2:end]) +end + +function broadcast!(::typeof(identity), V::CSCAssignmentView, B::SparseMatrixCSC) + A = V.parent + I, J = _getij(V) + return multivaluesetindex!(A, B, I, J) +end +# Historically, we've only supported specialized methods based upon the value for Matrix +# and Vector by converting them to SparseMatrixCSCs of the correct shape. This could be +# extended to any AbstractArray in the future. +broadcast!(::typeof(identity), V::CSCAssignmentView, B::Matrix) = broadcast!(identity, V, convert(SparseMatrixCSC, B)) +function broadcast!(::typeof(identity), V::CSCAssignmentView, x::Vector) + A = V.parent + I, J, = _getij(V) + return multivaluesetindex!(A, convert(SparseMatrixCSC, reshape(x, length(I), length(J))), I, J) +end + +# A[I,J] .= B +function multivaluesetindex!(A::SparseMatrixCSC{Tv}, B::SparseMatrixCSC, I::AbstractVector{T}, J::AbstractVector{T}) where {Tv,T<:Integer} + if size(B,1) != length(I) || size(B,2) != length(J) + throw(DimensionMismatch("")) + end + + issortedI = issorted(I) + issortedJ = issorted(J) + + if !issortedI && !issortedJ + pI = sortperm(I); @inbounds I = I[pI] + pJ = sortperm(J); @inbounds J = J[pJ] + B = B[pI, pJ] + elseif !issortedI + pI = sortperm(I); @inbounds I = I[pI] + B = B[pI,:] + elseif !issortedJ + pJ = sortperm(J); @inbounds J = J[pJ] + B = B[:, pJ] + end + + m, n = size(A) + mB, nB = size(B) + + if (!isempty(I) && (I[1] < 1 || I[end] > m)) || (!isempty(J) && (J[1] < 1 || J[end] > n)) + throw(BoundsError(A, (I, J))) + end + + if isempty(I) || isempty(J) + return A + end + + nI = length(I) + nJ = length(J) + + colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval + colptrB = B.colptr; rowvalB = B.rowval; nzvalB = B.nzval + + nnzS = nnz(A) + nnz(B) + + colptrS = copy(A.colptr) + rowvalS = copy(A.rowval) + nzvalS = copy(A.nzval) + + resize!(rowvalA, nnzS) + resize!(nzvalA, nnzS) + + colB = 1 + asgn_col = J[colB] + + I_asgn = falses(m) + I_asgn[I] = true + + ptrS = 1 + + @inbounds for col = 1:n + + # Copy column of A if it is not being assigned into + if colB > nJ || col != J[colB] + colptrA[col+1] = colptrA[col] + (colptrS[col+1]-colptrS[col]) + + for k = colptrS[col]:colptrS[col+1]-1 + rowvalA[ptrS] = rowvalS[k] + nzvalA[ptrS] = nzvalS[k] + ptrS += 1 + end + continue + end + + ptrA::Int = colptrS[col] + stopA::Int = colptrS[col+1] + ptrB::Int = colptrB[colB] + stopB::Int = colptrB[colB+1] + + while ptrA < stopA && ptrB < stopB + rowA = rowvalS[ptrA] + rowB = I[rowvalB[ptrB]] + if rowA < rowB + rowvalA[ptrS] = rowA + nzvalA[ptrS] = I_asgn[rowA] ? zero(Tv) : nzvalS[ptrA] + ptrS += 1 + ptrA += 1 + elseif rowB < rowA + if nzvalB[ptrB] != zero(Tv) + rowvalA[ptrS] = rowB + nzvalA[ptrS] = nzvalB[ptrB] + ptrS += 1 + end + ptrB += 1 + else + rowvalA[ptrS] = rowB + nzvalA[ptrS] = nzvalB[ptrB] + ptrS += 1 + ptrB += 1 + ptrA += 1 + end + end + + while ptrA < stopA + rowA = rowvalS[ptrA] + rowvalA[ptrS] = rowA + nzvalA[ptrS] = I_asgn[rowA] ? zero(Tv) : nzvalS[ptrA] + ptrS += 1 + ptrA += 1 + end + + while ptrB < stopB + rowB = I[rowvalB[ptrB]] + if nzvalB[ptrB] != zero(Tv) + rowvalA[ptrS] = rowB + nzvalA[ptrS] = nzvalB[ptrB] + ptrS += 1 + end + ptrB += 1 + end + + colptrA[col+1] = ptrS + colB += 1 + end + + deleteat!(rowvalA, colptrA[end]:length(rowvalA)) + deleteat!(nzvalA, colptrA[end]:length(nzvalA)) + + return A +end + ## dropstored! methods """ dropstored!(A::SparseMatrixCSC, i::Integer, j::Integer) diff --git a/stdlib/SparseArrays/src/sparsevector.jl b/stdlib/SparseArrays/src/sparsevector.jl index fae9d203cb770..b56b5d2800717 100644 --- a/stdlib/SparseArrays/src/sparsevector.jl +++ b/stdlib/SparseArrays/src/sparsevector.jl @@ -1914,7 +1914,7 @@ function _densifyfirstnztoend!(x::SparseVector) nextpos = newpos - 1 end # finally update lengthened nzinds - x.nzind[2:end] = (x.nzind[1]+1):x.n + x.nzind[2:end] .= (x.nzind[1]+1):x.n x end "Densifies `x::SparseVector` from its beginning (`x[1]`) through its last nonzero (`x[x.nzind[end]]`)." @@ -1937,7 +1937,7 @@ function _densifystarttolastnz!(x::SparseVector) end nextpos > 0 && (x.nzval[1:nextpos] = 0) # finally update lengthened nzinds - x.nzind[1:newnnz] = 1:newnnz + x.nzind[1:newnnz] .= 1:newnnz x end diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index ac92f97dc773c..ad46fd569db0e 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -790,9 +790,9 @@ end @test nnz(a) == 20 @test count(!iszero, a) == 11 - a[1,:] = 1:10 + a[1,:] .= 1:10 @test a[1,:] == sparse([1:10;]) - a[:,2] = 1:10 + a[:,2] .= 1:10 @test a[:,2] == sparse([1:10;]) a[1,1:0] = [] @@ -808,11 +808,11 @@ end a[1:0,2] = 1 @test a[:,2] == sparse([1:10;]) - @test_throws BoundsError a[:,11] = spzeros(10,1) - @test_throws BoundsError a[11,:] = spzeros(1,10) - @test_throws BoundsError a[:,-1] = spzeros(10,1) - @test_throws BoundsError a[-1,:] = spzeros(1,10) - @test_throws BoundsError a[0:9] = spzeros(1,10) + @test_throws BoundsError a[:,11] .= spzeros(10,1) + @test_throws BoundsError a[11,:] .= spzeros(1,10) + @test_throws BoundsError a[:,-1] .= spzeros(10,1) + @test_throws BoundsError a[-1,:] .= spzeros(1,10) + @test_throws BoundsError a[0:9] .= spzeros(1,10) @test_throws BoundsError a[:,11] = 0 @test_throws BoundsError a[11,:] = 0 @test_throws BoundsError a[:,-1] = 0 @@ -824,10 +824,10 @@ end @test_throws BoundsError a[-1,:] = 1 @test_throws BoundsError a[0:9] = 1 - @test_throws DimensionMismatch a[1:2,1:2] = 1:3 - @test_throws DimensionMismatch a[1:2,1] = 1:3 - @test_throws DimensionMismatch a[1,1:2] = 1:3 - @test_throws DimensionMismatch a[1:2] = 1:3 + @test_throws DimensionMismatch a[1:2,1:2] .= 1:3 + @test_throws DimensionMismatch a[1:2,1] .= 1:3 + @test_throws DimensionMismatch a[1,1:2] .= 1:3 + @test_throws DimensionMismatch a[1:2] .= 1:3 A = spzeros(Int, 10, 20) A[1:5,1:10] = 10 @@ -853,12 +853,12 @@ end A[1:TSZ, 1:(2*TSZ)] = 0 nB = count(!iszero, A) @test nB == (nA - nx) - A[1:TSZ, 1:(2*TSZ)] = x + A[1:TSZ, 1:(2*TSZ)] .= x @test count(!iszero, A) == nA @test A == B A[1:TSZ, 1:(2*TSZ)] = 10 @test count(!iszero, A) == nB + 2*TSZ*TSZ - A[1:TSZ, 1:(2*TSZ)] = x + A[1:TSZ, 1:(2*TSZ)] .= x @test count(!iszero, A) == nA @test A == B @@ -866,19 +866,19 @@ end lininds = 1:10 X=reshape([trues(10); falses(15)],5,5) @test A[lininds] == A[X] == [1,0,0,0,0,0,1,0,0,0] - A[lininds] = [1:10;] + A[lininds] .= [1:10;] @test A[lininds] == A[X] == 1:10 - A[lininds] = zeros(Int, 10) + A[lininds] .= zeros(Int, 10) @test nnz(A) == 13 @test count(!iszero, A) == 3 @test A[lininds] == A[X] == zeros(Int, 10) c = Vector(11:20); c[1] = c[3] = 0 - A[lininds] = c + A[lininds] .= c @test nnz(A) == 13 @test count(!iszero, A) == 11 @test A[lininds] == A[X] == c A = sparse(1I, 5, 5) - A[lininds] = c + A[lininds] .= c @test nnz(A) == 12 @test count(!iszero, A) == 11 @test A[lininds] == A[X] == c @@ -910,7 +910,7 @@ end @test nnz(S) == nnzS3 @test count(!iszero, S) == cnzS2 - S[FI] = [1:sum(FI);] + S[FI] .= [1:sum(FI);] @test sum(S) == sumS2 + sum(1:sum(FI)) S = sprand(50, 30, 0.5, x -> round.(Int, rand(x) * 100)) @@ -921,7 +921,7 @@ end sumS2 = sum(S[I]) S[I] = 0 @test sum(S) == (sumS1 - sumS2) - S[I] = J + S[I] .= J @test sum(S) == (sumS1 - sumS2 + sum(J)) end end diff --git a/stdlib/SparseArrays/test/sparsevector.jl b/stdlib/SparseArrays/test/sparsevector.jl index 576ed031c02f0..1c58ccff4d1a4 100644 --- a/stdlib/SparseArrays/test/sparsevector.jl +++ b/stdlib/SparseArrays/test/sparsevector.jl @@ -445,7 +445,7 @@ end @test nnz(H) == tnnz Hr = zeros(m, n) for j = 1:n - Hr[:,j] = Array(A[j]) + Hr[:,j] .= Array(A[j]) end @test Array(H) == Hr