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

Export AbstractSparseMatrixCSC + interface #395

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ DocTestSetup = nothing
SparseArrays.AbstractSparseArray
SparseArrays.AbstractSparseVector
SparseArrays.AbstractSparseMatrix
SparseArrays.AbstractSparseMatrixCSC
SparseArrays.SparseVector
SparseArrays.SparseMatrixCSC
SparseArrays.sparse
Expand All @@ -238,6 +239,7 @@ SparseArrays.sprandn
SparseArrays.nonzeros
SparseArrays.rowvals
SparseArrays.nzrange
SparseArrays.getcolptr
SparseArrays.droptol!
SparseArrays.dropzeros!
SparseArrays.dropzeros
Expand Down
4 changes: 2 additions & 2 deletions src/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import Base: adjoint, argmin, argmax, Array, broadcast, circshift!, complex, Com
using Random: default_rng, AbstractRNG, randsubseq, randsubseq!

export AbstractSparseArray, AbstractSparseMatrix, AbstractSparseVector,
SparseMatrixCSC, SparseVector, blockdiag, droptol!, dropzeros!, dropzeros,
issparse, nonzeros, nzrange, rowvals, sparse, sparsevec, spdiagm,
AbstractSparseMatrixCSC, SparseMatrixCSC, SparseVector, blockdiag, droptol!, dropzeros!, dropzeros,
issparse, nonzeros, nzrange, rowvals, getcolptr, sparse, sparsevec, spdiagm,
sprand, sprandn, spzeros, nnz, permute, findnz, fkeep!, ftranspose!,
sparse_hcat, sparse_vcat, sparse_hvcat

Expand Down
4 changes: 3 additions & 1 deletion src/abstractsparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const AbstractSparseVecOrMat = Union{AbstractSparseVector,AbstractSparseMatrix}
"""
AbstractSparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti}

Supertype for matrix with compressed sparse column (CSC).
Supertype for sparse matrix with elements of type `Tv` and index type `Ti`
in compressed sparse column (CSC) format. Subtypes of this type are expected to implement
[`nnz`](@ref), [`rowvals`](@ref), [`nzrange`](@ref), [`nonzeros`](@ref) and [`getcolptr`](@ref).
"""
abstract type AbstractSparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti} end

Expand Down
28 changes: 26 additions & 2 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,30 @@ const SparseMatrixCSCColumnSubset{Tv,Ti} =
Tuple{Base.Slice{Base.OneTo{Int}},I}} where {I<:AbstractVector{<:Integer}}
const SparseMatrixCSCUnion2{Tv,Ti} = Union{AbstractSparseMatrixCSC{Tv,Ti}, SparseMatrixCSCColumnSubset{Tv,Ti}}

"""
getcolptr(A::AbstractSparseMatrixCSC)

Return a vector of column pointers of `A`. Any modifications to the returned
vector will mutate `A` as well. Providing access to how the column pointers are
stored internally can be useful in conjunction with passing data to factorizations
and preconditioners. See also [`rowvals`](@ref), [`nonzeros`](@ref) and [`nzrange`](@ref).

# Examples
```jldoctest
julia> A = sparse(2I, 3, 3)
3×3 SparseMatrixCSC{Int64, Int64} with 3 stored entries:
2 ⋅ ⋅
⋅ 2 ⋅
⋅ ⋅ 2

julia> getcolptr(A)
4-element Vector{Int64}:
1
2
3
4
```
"""
getcolptr(S::SorF) = getfield(S, :colptr)
getcolptr(S::SparseMatrixCSCView) = view(getcolptr(parent(S)), first(S.indices[2]):(last(S.indices[2]) + 1))
getcolptr(S::SparseMatrixCSCColumnSubset) = error("getcolptr not well-defined for $(typeof(S))")
Expand Down Expand Up @@ -236,7 +260,7 @@ Return a vector of the structural nonzero values in sparse array `A`. This
includes zeros that are explicitly stored in the sparse array. The returned
vector points directly to the internal nonzero storage of `A`, and any
modifications to the returned vector will mutate `A` as well. See
[`rowvals`](@ref) and [`nzrange`](@ref).
[`rowvals`](@ref), [`getcolptr`](@ref) and [`nzrange`](@ref).

# Examples
```jldoctest
Expand Down Expand Up @@ -264,7 +288,7 @@ nonzeros(S::LowerTriangular{<:Any,<:SparseMatrixCSCUnion}) = nonzeros(S.data)
Return a vector of the row indices of `A`. Any modifications to the returned
vector will mutate `A` as well. Providing access to how the row indices are
stored internally can be useful in conjunction with iterating over structural
nonzero values. See also [`nonzeros`](@ref) and [`nzrange`](@ref).
nonzero values. See also [`getcolptr`](@ref), [`nonzeros`](@ref) and [`nzrange`](@ref).

# Examples
```jldoctest
Expand Down
Loading