Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/SparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import Base: adjoint, argmin, argmax, Array, broadcast, circshift!, complex, Com

using Random: default_rng, AbstractRNG, randsubseq, randsubseq!

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

public sparse!, spzeros!
Expand Down
5 changes: 5 additions & 0 deletions src/abstractsparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ end
issparse(A::DenseArray) = false
issparse(S::AbstractSparseArray) = true

"""
indtype(S)

Return the type used to index sparse array entries.
"""
indtype(S::AbstractSparseArray{<:Any,Ti}) where {Ti} = Ti
indtype(T::UpperOrLowerTriangular{<:Any,<:AbstractSparseArray}) = indtype(parent(T))

Expand Down
25 changes: 25 additions & 0 deletions src/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ 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(S)

Return the vector of column start indices in an `AbstractSparseMatrixCSC` pointing
into [`nonzeros`](@ref) and [`rowvals`](@ref). The returned vector aliases `S`,
but implementations with fixed sparsity may make it read-only. When it is
writable, modifications to it mutate `S`. Providing access to the column start
indices can be useful in preconditioners and sparse direct solvers.

# 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
Loading