Skip to content

Commit

Permalink
Fix a row-indexing bug with sparse matrices
Browse files Browse the repository at this point in the history
that have non-Int indices, introduced by #13612
and which has caused `make -C test/perf` to fail for the last 9 months

searchsortedfirst does not have methods for general Integer indices
  • Loading branch information
tkelman committed Aug 14, 2016
1 parent 2359ef8 commit b1d5321
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ function Base.getindex{Tv,Ti}(A::SparseMatrixCSC{Tv,Ti}, i::Integer, J::Abstract
@inbounds for j = 1:nJ
col = J[j]
rowI = i
ptrA = colptrA[col]
stopA = colptrA[col+1]-1
ptrA = Int(colptrA[col])
stopA = Int(colptrA[col+1]-1)
if ptrA <= stopA
if rowvalA[ptrA] <= rowI
ptrA = searchsortedfirst(rowvalA, rowI, ptrA, stopA, Base.Order.Forward)
Expand Down
5 changes: 5 additions & 0 deletions test/sparsedir/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1588,3 +1588,8 @@ end

# Test temporary fix for issue #16548 in PR #16979. Brittle. Expect to remove with `\` revisions.
@test which(\, (SparseMatrixCSC, AbstractVecOrMat)).module == Base.SparseArrays

# Row indexing a SparseMatrixCSC with non-Int integer type
let A = sparse(UInt32[1,2,3], UInt32[1,2,3], [1.0,2.0,3.0])
@test A[1,1:3] == A[1,:] == [1,0,0]
end

0 comments on commit b1d5321

Please sign in to comment.