diff --git a/docs/src/index.md b/docs/src/index.md index 225d5a0b..8153af3e 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -217,6 +217,7 @@ DocTestSetup = nothing SparseArrays.AbstractSparseArray SparseArrays.AbstractSparseVector SparseArrays.AbstractSparseMatrix +SparseArrays.AbstractSparseMatrixCSC SparseArrays.SparseVector SparseArrays.SparseMatrixCSC SparseArrays.sparse @@ -238,6 +239,7 @@ SparseArrays.sprandn SparseArrays.nonzeros SparseArrays.rowvals SparseArrays.nzrange +SparseArrays.getcolptr SparseArrays.droptol! SparseArrays.dropzeros! SparseArrays.dropzeros diff --git a/src/SparseArrays.jl b/src/SparseArrays.jl index 2688a449..54a0cf16 100644 --- a/src/SparseArrays.jl +++ b/src/SparseArrays.jl @@ -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 diff --git a/src/abstractsparse.jl b/src/abstractsparse.jl index d23eebca..e0074c7c 100644 --- a/src/abstractsparse.jl +++ b/src/abstractsparse.jl @@ -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 diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index 6d6d880d..64eb12f4 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -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))") @@ -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 @@ -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