Skip to content

Commit

Permalink
fix off-by-one in findn and findnz
Browse files Browse the repository at this point in the history
``count`` was equal to the number of nonzero elements plus one, so the output vectors had an extra element with junk.
  • Loading branch information
mlubin committed Jan 13, 2014
1 parent 5e22c08 commit 5446521
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ function findn{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti})
end
end

if numnz != count-1
count -= 1
if numnz != count
I = I[1:count]
J = J[1:count]
end
Expand All @@ -324,7 +325,8 @@ function findnz{Tv,Ti}(S::SparseMatrixCSC{Tv,Ti})
end
end

if numnz != count-1
count -= 1
if numnz != count
I = I[1:count]
J = J[1:count]
V = V[1:count]
Expand Down

0 comments on commit 5446521

Please sign in to comment.