Skip to content

Commit 1c30ba5

Browse files
committed
add docstrings
1 parent e25fef5 commit 1c30ba5

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

src/SparseMatrixCSR.jl

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
"""
3+
struct SparseMatrixCSR{T,Ti<:Integer} <: AbstractSparseMatrix{T,Ti}
4+
5+
Matrix type for storing sparse matrices in the
6+
Compressed Sparse Row format. The standard way
7+
of constructing SparseMatrixCSR is through the [`sparsecsr`](@ref) function.
8+
"""
29
struct SparseMatrixCSR{T,Ti<:Integer} <: AbstractSparseMatrix{T,Ti}
310
transpose :: SparseMatrixCSC{T,Ti}
411
end
@@ -8,15 +15,61 @@ show(io::IO, A::SparseMatrixCSR) = show(io, A.transpose)
815
size(A::SparseMatrixCSR) = (A.transpose.n, A.transpose.m)
916
getindex(A::SparseMatrixCSR, x::Integer, y::Integer) = getindex(A.transpose,y,x)
1017

11-
nnz(S::SparseMatrixCSR) = nnz(S.transpose)
18+
"""
19+
nnz(S::SparseMatrixCSR)
20+
21+
Returns the number of stored (filled) elements in a sparse array.
22+
"""
23+
nnz(S::SparseMatrixCSR) = nnz(S.transpose)
24+
25+
"""
26+
count(pred, S::SparseMatrixCSR) -> Integer
27+
28+
Count the number of elements in S for which predicate pred returns true.
29+
"""
1230
count(pred, S::SparseMatrixCSR) = count(pred, S.transpose)
1331

32+
"""
33+
nonzeros(S::SparseMatrixCSR)
34+
35+
Return a vector of the structural nonzero values in sparse array S.
36+
This includes zeros that are explicitly stored in the sparse array.
37+
The returned vector points directly to the internal nonzero storage of A,
38+
and any modifications to the returned vector will mutate A as well.
39+
"""
1440
nonzeros(S::SparseMatrixCSR) = S.transpose.nzval
1541

42+
"""
43+
nzrange(S::SparseMatrixCSR, row::Integer)
44+
45+
Return the range of indices to the structural nonzero values of a
46+
sparse matrix row.
47+
"""
1648
nzrange(S::SparseMatrixCSR, row::Integer) = nzrange(S.transpose, row)
1749

50+
"""
51+
findnz(S::SparseMatrixCSR)
52+
53+
Return a tuple (I, J, V) where I and J are the row and column indices
54+
of the stored ("structurally non-zero") values in sparse matrix A,
55+
and V is a vector of the values.
56+
"""
1857
findnz(S::SparseMatrixCSR) = findnz(S.transpose)
1958

59+
"""
60+
sparsecsr(I, J, V, [m, n, combine])
61+
62+
Create a sparse matrix S of dimensions m x n such that S[I[k], J[k]] = V[k].
63+
The combine function is used to combine duplicates.
64+
If m and n are not specified, they are set to
65+
maximum(I) and maximum(J) respectively.
66+
If the combine function is not supplied, combine defaults to +
67+
unless the elements of V are Booleans in which case combine defaults to |.
68+
All elements of I must satisfy 1 <= I[k] <= m,
69+
and all elements of J must satisfy 1 <= J[k] <= n.
70+
Numerical zeros in (I, J, V) are retained as structural nonzeros;
71+
to drop numerical zeros, use dropzeros!.
72+
"""
2073
sparsecsr(I,J,kwargs...) = SparseMatrixCSR(sparse(J,I,kwargs...))
2174

2275

0 commit comments

Comments
 (0)