Skip to content

Commit

Permalink
add documentation for findnz w/ SparseVector (#36089)
Browse files Browse the repository at this point in the history
* add documentation for findnz w/ SparseVector

* change docstring to include paramtype

* Update abstractsparse.jl

Co-authored-by: Viral B. Shah <ViralBShah@users.noreply.github.com>
  • Loading branch information
ssikdar1 and ViralBShah authored Jun 2, 2020
1 parent 147d5b1 commit fc279ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/SparseArrays/src/abstractsparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function findprev(f::Function, v::AbstractSparseArray, i)
end

"""
findnz(A)
findnz(A::SparseMatrixCSC)
Return a tuple `(I, J, V)` where `I` and `J` are the row and column indices of the stored
("structurally non-zero") values in sparse matrix `A`, and `V` is a vector of the values.
Expand Down
19 changes: 19 additions & 0 deletions stdlib/SparseArrays/src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,25 @@ end
findall(p::Base.Fix2{typeof(in)}, x::SparseVector{<:Any,Ti}) where {Ti} =
invoke(findall, Tuple{Base.Fix2{typeof(in)}, AbstractArray}, p, x)

"""
findnz(x::SparseVector)
Return a tuple `(I, V)` where `I` is the indices of the stored ("structurally non-zero")
values in sparse vector `x` and `V` is a vector of the values.
# Examples
```jldoctest
julia> x = sparsevec([1 2 0; 0 0 3; 0 4 0])
9-element SparseVector{Int64,Int64} with 4 stored entries:
[1] = 1
[4] = 2
[6] = 4
[8] = 3
julia> findnz(x)
([1, 4, 6, 8], [1, 2, 4, 3])
```
"""
function findnz(x::SparseVector{Tv,Ti}) where {Tv,Ti}
numnz = nnz(x)

Expand Down

2 comments on commit fc279ca

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.