Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move findnz to SparseArrays module #25641

Merged
merged 2 commits into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make findnz for SparseVector consistent with SparseMatrix method
0335175 changed the SparseMatrix method to also return stored zeros,
but it forgot to change the SparseVector method.
  • Loading branch information
nalimilan committed Jan 19, 2018
commit b77b4693431e69e9e4d5365fc2d08fcab0d3452c
14 changes: 2 additions & 12 deletions stdlib/SparseArrays/src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -716,19 +716,9 @@ function findnz(x::SparseVector{Tv,Ti}) where {Tv,Ti}
nzind = x.nzind
nzval = x.nzval

count = 1
@inbounds for i = 1 : numnz
if nzval[i] != 0
I[count] = nzind[i]
V[count] = nzval[i]
count += 1
end
end

count -= 1
if numnz != count
deleteat!(I, (count+1):numnz)
deleteat!(V, (count+1):numnz)
I[i] = nzind[i]
V[i] = nzval[i]
end

return (I, V)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/SparseArrays/test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ end
@test findnz(spv_x1) == (findall(!iszero, x1_full), filter(x->x!=0, x1_full))
let xc = SparseVector(8, [2, 3, 5], [1.25, 0, -0.75]), fc = Array(xc)
@test findall(!iszero, xc) == findall(!iszero, fc)
@test findnz(xc) == ([2, 5], [1.25, -0.75])
@test findnz(xc) == ([2, 3, 5], [1.25, 0, -0.75])
end
end
### Array manipulation
Expand Down