Skip to content

Commit

Permalink
Fix DimensionMismatch in SparseMatrixCSC assignment (#30507)
Browse files Browse the repository at this point in the history
Use _setindex! to fix DimensionMismatch in sparse assignment
Fixes #28963
  • Loading branch information
raghav9-97 authored and staticfloat committed Jan 4, 2019
1 parent e11e494 commit 11ec344
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions stdlib/SparseArrays/src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2575,6 +2575,7 @@ function setindex!(A::SparseMatrixCSC{Tv,Ti}, V::AbstractVecOrMat, Ix::Union{Int
@assert !has_offset_axes(A, V, Ix, Jx)
(I, J) = Base.ensure_indexable(to_indices(A, (Ix, Jx)))
checkbounds(A, I, J)
Base._setindex!(IndexStyle(A), A, V, to_indices(A, (Ix, Jx))...)
B = _to_same_csc(A, V, I, J)

issortedI = issorted(I)
Expand Down
4 changes: 4 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ end
end
end

@testset "Issue #28963" begin
@test_throws DimensionMismatch (spzeros(10,10)[:, :] = sprand(10,20,0.5))
end

@testset "matrix-vector multiplication (non-square)" begin
for i = 1:5
a = sprand(10, 5, 0.5)
Expand Down

0 comments on commit 11ec344

Please sign in to comment.