Skip to content

Commit 9324b5a

Browse files
committed
Fix ambiguities in SparseMatrix setindex!
1 parent 042c2b8 commit 9324b5a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

stdlib/SparseArrays/src/sparsematrix.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,10 +2326,10 @@ getindex(A::SparseMatrixCSC, I::AbstractVector{<:Integer}, J::AbstractVector{Boo
23262326
getindex(A::SparseMatrixCSC, I::AbstractVector{Bool}, J::AbstractVector{<:Integer}) = A[findall(I),J]
23272327

23282328
## setindex!
2329-
function setindex!(A::SparseMatrixCSC{Tv,Ti}, v, i::Integer, j::Integer) where Tv where Ti
2330-
setindex!(A, convert(Tv, v), convert(Ti, i), convert(Ti, j))
2331-
end
2332-
function setindex!(A::SparseMatrixCSC{Tv,Ti}, v::Tv, i::Ti, j::Ti) where Tv where Ti<:Integer
2329+
function setindex!(A::SparseMatrixCSC{Tv,Ti}, _v, _i::Integer, _j::Integer) where Tv where Ti
2330+
v = convert(Tv, _v)
2331+
i = convert(Ti, _i)
2332+
j = convert(Ti, _j)
23332333
if !((1 <= i <= A.m) & (1 <= j <= A.n))
23342334
throw(BoundsError(A, (i,j)))
23352335
end
@@ -2521,13 +2521,17 @@ function _spsetnz_setindex!(A::SparseMatrixCSC{Tv}, x::Tv,
25212521
return A
25222522
end
25232523

2524+
setindex!(A::SparseMatrixCSC{Tv,Ti}, S::Matrix, I::Integer, J::Integer) where {Tv,Ti} = setindex!(A, convert(Tv, S), I, J)
25242525
setindex!(A::SparseMatrixCSC{Tv,Ti}, S::Matrix, I::Union{Integer, AbstractVector{T}}, J::Union{Integer, AbstractVector{T}}) where {Tv,Ti,T<:Integer} =
2525-
setindex!(A, convert(SparseMatrixCSC{Tv,Ti}, S), I, J)
2526+
setindex!(A, convert(SparseMatrixCSC{Tv,Ti}, S), I, J)
25262527

2528+
setindex!(A::SparseMatrixCSC, v::AbstractVector, I::Integer, J::Integer) = setindex!(A, convert(Tv, v), I, J)
25272529
setindex!(A::SparseMatrixCSC, v::AbstractVector, I::Union{Integer, AbstractVector{T}}, J::Union{Integer, AbstractVector{T}}) where {T<:Integer} =
2528-
setindex!(A, reshape(v, length(I), length(J)), I, J)
2530+
setindex!(A, reshape(v, length(I), length(J)), I, J)
25292531

25302532
# A[I,J] = B
2533+
setindex!(A::SparseMatrixCSC{Tv,Ti}, B::SparseMatrixCSC{Tv,Ti}, I::Integer, J::Integer) where {Tv,Ti} =
2534+
setindex!(A, convert(Tv, I, J), I, J)
25312535
function setindex!(A::SparseMatrixCSC{Tv,Ti}, B::SparseMatrixCSC{Tv,Ti}, I::Union{Integer, AbstractVector{T}}, J::Union{Integer, AbstractVector{T}}) where {Tv,Ti,T<:Integer}
25322536
if size(B,1) != length(I) || size(B,2) != length(J)
25332537
throw(DimensionMismatch(""))

0 commit comments

Comments
 (0)