From 67c4c895e7a91b25500895a01a2a8aa2f1016be7 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Mon, 16 Nov 2015 12:02:37 -0500 Subject: [PATCH] Fix sparse matrix row slices Fix #14013 --- base/sparse/sparsevector.jl | 2 +- test/sparsedir/sparsevector.jl | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index 457873d8f65dc..5cc5d886ca9fd 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -392,7 +392,7 @@ function Base.getindex{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, i::Integer, J::Abstract if rowvalA[ptrA] <= rowI ptrA = searchsortedfirst(rowvalA, rowI, ptrA, stopA, Base.Order.Forward) if ptrA <= stopA && rowvalA[ptrA] == rowI - push!(nzinds, ptrI) + push!(nzinds, j) push!(nzvals, nzvalA[ptrA]) end end diff --git a/test/sparsedir/sparsevector.jl b/test/sparsedir/sparsevector.jl index 90dbd2dfcee9a..ed065b645ae99 100644 --- a/test/sparsedir/sparsevector.jl +++ b/test/sparsedir/sparsevector.jl @@ -749,3 +749,11 @@ let S = SparseMatrixCSC(10,1,[1,6],[1,3,5,6,7],[0,1,2,0,3]), x = SparseVector(10 @test S[[1 3 5; 2 4 6]] == x[[1 3 5; 2 4 6]] @test nnz(S[[1 3 5; 2 4 6]]) == nnz(x[[1 3 5; 2 4 6]]) end + +# Issue 14013 +s14013 = sparse([10.0 0.0 30.0; 0.0 1.0 0.0]) +a14013 = [10.0 0.0 30.0; 0.0 1.0 0.0] +@test s14013 == a14013 +@test vec(s14013) == s14013[:] == a14013[:] +@test full(s14013)[1,:] == s14013[1,:] == a14013[1,:] == [10.0, 0.0, 30.0] +@test full(s14013)[2,:] == s14013[2,:] == a14013[2,:] == [0.0, 1.0, 0.0]