Skip to content

Commit

Permalink
Fix and test SparseMatrixCSC indexing with empty indices
Browse files Browse the repository at this point in the history
  • Loading branch information
simonster committed Jan 20, 2015
1 parent 4c6a3d2 commit 5c5bf9d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ function getindex_cols{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, J::AbstractVector)
# for indexing whole columns
(m, n) = size(A)
nJ = length(J)
(maximum(J) <= n) || throw(BoundsError())
nJ == 0 || maximum(J) <= n || throw(BoundsError())

colptrA = A.colptr; rowvalA = A.rowval; nzvalA = A.nzval

Expand Down
9 changes: 9 additions & 0 deletions test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,15 @@ for (aa116, ss116) in [(a116, s116), (ad116, sd116)]
@test full(ss116[i,lj]) == aa116[i,lj]
@test full(ss116[:,lj]) == aa116[:,lj]
@test full(ss116[li,lj]) == aa116[li,lj]

# empty indices
for empty in (1:0, Int[])
@test full(ss116[empty,:]) == aa116[empty,:]
@test full(ss116[:,empty]) == aa116[:,empty]''
@test full(ss116[empty,lj]) == aa116[empty,lj]
@test full(ss116[li,empty]) == aa116[li,empty]
@test full(ss116[empty,empty]) == aa116[empty,empty]
end
end

# workaround issue #7197: comment out let-block
Expand Down

0 comments on commit 5c5bf9d

Please sign in to comment.