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

Docstrings for constructors #36

Merged
merged 4 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,27 @@ mutable struct DynamicSparseMatrix{K,L,T}
rowmajor::Union{MappedPackedCSC{L,K,T}, Nothing}
end

"""
dynamicsparse(I, J, V, [m, n])

Creates a dynamic sparse matrix `S` of dimensions `m`×`n` such that `S[I[k], J[k]] = V[k]`.
"""
function dynamicsparse(I::Vector{K}, J::Vector{L}, V::Vector{T}, m = _guess_length(I), n = _guess_length(J)) where {K,L,T}
return DynamicSparseMatrix(
m, n, false, nothing, dynamicsparsecolmajor(I,J,V), dynamicsparsecolmajor(J,I,V)
)
end

"""
dynamicsparse(Ti, Tj, Tv [; fill_mode = true])

Creates an empty dynamic sparse matrix with row keys of type `Ti`, column keys of
type `Tj`, and non-zero values of type `Tv`.
By default, the matrix is returned in a "fill mode".
This allows the user to fill the matrix with non-zero entries.
All the write operations are stored in a `Dict`.
When the matrix is filled, the user must call `closefillmode!(matrix)`.
"""
function dynamicsparse(::Type{K}, ::Type{L}, ::Type{T}; fill_mode = true) where {K,L,T}
return if fill_mode
DynamicSparseMatrix(
Expand Down
7 changes: 7 additions & 0 deletions src/vector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ function dynamicsparsevec(
end

dynamicsparsevec(I,V) = dynamicsparsevec(I,V,+)

"""
dynamicsparsevec(I, V, [combine, n])

Creates a dynamic sparse vector `S` of length `n` such that `S[I[k]] = S[V[k]]`.
The combine operator is used to combine the values of `V` that have same id in `I`.
"""
dynamicsparsevec(I::Vector{K},V,n::K) where K = dynamicsparsevec(I,V,+,n)

shrink_size!(v::DynamicSparseVector) = v.n = _guess_length(v.pma)
Expand Down