From bb2f8efde5ec201cd4831664bed8e29d5c342a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Tue, 8 Sep 2026 09:36:19 +0200 Subject: [PATCH 1/6] Export AbstractSparseMatrixCSC, getcolptr, indtype AbstractSparseMatrixCSC and getcolptr are heavily used in LinearSolve.jl. We find uses of getcolptr in Sparspak.jl and Pardiso.jl indtype is a useful complement to eltype which could be extended for subtypes of AbstractSparseArray. --- src/SparseArrays.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SparseArrays.jl b/src/SparseArrays.jl index a3ef1767..a66ac799 100644 --- a/src/SparseArrays.jl +++ b/src/SparseArrays.jl @@ -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! From 0e08563c0d2d1e4e404804fe6347965b2a2f2862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Tue, 8 Sep 2026 11:56:31 +0200 Subject: [PATCH 2/6] fix syntax --- src/SparseArrays.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SparseArrays.jl b/src/SparseArrays.jl index a66ac799..7ca5103d 100644 --- a/src/SparseArrays.jl +++ b/src/SparseArrays.jl @@ -29,7 +29,7 @@ import Base: adjoint, argmin, argmax, Array, broadcast, circshift!, complex, Com using Random: default_rng, AbstractRNG, randsubseq, randsubseq! -export AbstractSparseArray, AbstractSparseMatrix, AbstractSparseVector, AbstractSparseMatrixCSC +export AbstractSparseArray, AbstractSparseMatrix, AbstractSparseVector, AbstractSparseMatrixCSC, SparseMatrixCSC, SparseVector, blockdiag, droptol!, dropzeros!, dropzeros, issparse, nonzeros, nzrange, rowvals, getcolptr, sparse, sparsevec, spdiagm, sprand, sprandn, spzeros, nnz, indtype, permute, findnz, fkeep!, ftranspose!, From 333eaf2001ef863a82b918db7502f9ecc65ae649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Tue, 8 Sep 2026 12:44:50 +0200 Subject: [PATCH 3/6] Add docstring for indtype --- src/abstractsparse.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/abstractsparse.jl b/src/abstractsparse.jl index 962759a0..322bde4a 100644 --- a/src/abstractsparse.jl +++ b/src/abstractsparse.jl @@ -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)) From 9aa8b447c1351512989fa68f7b3c847006e8d567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Tue, 8 Sep 2026 12:59:01 +0200 Subject: [PATCH 4/6] Add docstring for getcolptr --- src/sparsematrix.jl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index 6c138edb..627b4e0e 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(S) + +Return the vector of column start indices in an AbstractSparseMatrixCSC pointing +into [`nonzeros`](@ref) and [`rowvals`](@ref). Any modifications to the returned +vector will mutate `A` as well. 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))") From 52a85e65b202f526dff83751bd7890ddb4bb0c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Tue, 8 Sep 2026 13:25:05 +0200 Subject: [PATCH 5/6] fix doctests --- src/sparsematrix.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index 627b4e0e..bd526b4d 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -209,10 +209,10 @@ julia> A = sparse(2I, 3, 3) julia> getcolptr(A) 4-element Vector{Int64}: -1 -2 -3 -4 + 1 + 2 + 3 + 4 ``` """ getcolptr(S::SorF) = getfield(S, :colptr) From 4a8a3559a01da6d79d3d8c6726a4f6f83bfab9ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Tue, 8 Sep 2026 13:38:42 +0200 Subject: [PATCH 6/6] Update documentation for getcolptr function Suggested by copilot. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/sparsematrix.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index bd526b4d..7f3bf754 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -194,10 +194,11 @@ const SparseMatrixCSCUnion2{Tv,Ti} = Union{AbstractSparseMatrixCSC{Tv,Ti}, Spars """ getcolptr(S) -Return the vector of column start indices in an AbstractSparseMatrixCSC pointing -into [`nonzeros`](@ref) and [`rowvals`](@ref). Any modifications to the returned -vector will mutate `A` as well. Providing access to the column start indices -can be useful in preconditioners and sparse direct solvers. +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