From 219603021fbee4aec8947fdeaed2498b45657e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Thu, 1 Jun 2023 13:00:25 +0200 Subject: [PATCH 1/5] Start exporting SparseMatrixCSC Interface --- src/SparseArrays.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SparseArrays.jl b/src/SparseArrays.jl index 4c0bf829..1a56f433 100644 --- a/src/SparseArrays.jl +++ b/src/SparseArrays.jl @@ -33,6 +33,9 @@ export AbstractSparseArray, AbstractSparseMatrix, AbstractSparseVector, sprand, sprandn, spzeros, nnz, permute, findnz, fkeep!, ftranspose!, sparse_hcat, sparse_vcat, sparse_hvcat +export AbstractSparseMatrixCSC, getcolptr, getrowval, nonzeros + + const LinAlgLeftQs = Union{HessenbergQ,QRCompactWYQ,QRPackedQ} # helper function needed in sparsematrix, sparsevector and higherorderfns From bf83a7c74b99555be2868857f0c775666c22fc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Thu, 1 Jun 2023 14:06:27 +0200 Subject: [PATCH 2/5] Remove inconsistent methods which are supposed to return a SparseMatrixCSC, but would not. See https://github.com/JuliaSparse/SparseArrays.jl/issues/265#issuecomment-1438645148 --- src/sparsematrix.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index fe6fbe43..1b76a372 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -750,11 +750,11 @@ function Base.sizehint!(S::SparseMatrixCSC, n::Integer) end # converting between SparseMatrixCSC types -SparseMatrixCSC(S::AbstractSparseMatrixCSC) = copy(S) + AbstractMatrix{Tv}(A::AbstractSparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv}(A) SparseMatrixCSC{Tv}(S::AbstractSparseMatrixCSC{Tv}) where {Tv} = copy(S) SparseMatrixCSC{Tv}(S::AbstractSparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv,eltype(getcolptr(S))}(S) -SparseMatrixCSC{Tv,Ti}(S::AbstractSparseMatrixCSC{Tv,Ti}) where {Tv,Ti} = copy(S) + function SparseMatrixCSC{Tv,Ti}(S::AbstractSparseMatrixCSC) where {Tv,Ti} eltypeTicolptr = Vector{Ti}(getcolptr(S)) eltypeTirowval = Vector{Ti}(rowvals(S)) From 97ec3a10c1cf7ea82016196deeabfe5cf056044d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Thu, 1 Jun 2023 15:35:59 +0200 Subject: [PATCH 3/5] Tests (besides "ambiguous") --- src/sparsematrix.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index 1b76a372..c69d4efe 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -752,8 +752,10 @@ end # converting between SparseMatrixCSC types AbstractMatrix{Tv}(A::AbstractSparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv}(A) -SparseMatrixCSC{Tv}(S::AbstractSparseMatrixCSC{Tv}) where {Tv} = copy(S) +SparseMatrixCSC{Tv}(S::AbstractSparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv}(S) SparseMatrixCSC{Tv}(S::AbstractSparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv,eltype(getcolptr(S))}(S) +SparseMatrixCSC(S::SparseMatrixCSC)=copy(S) + function SparseMatrixCSC{Tv,Ti}(S::AbstractSparseMatrixCSC) where {Tv,Ti} eltypeTicolptr = Vector{Ti}(getcolptr(S)) From 3469864a0333c861ab70340585ed1250f9f5a7eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Thu, 5 Dec 2024 13:06:48 +0100 Subject: [PATCH 4/5] Remove all method overwrites Don't implement any new functionality. --- src/sparsematrix.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index 3401068c..64eb12f4 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -768,13 +768,11 @@ function Base.sizehint!(S::SparseMatrixCSC, n::Integer) end # converting between SparseMatrixCSC types - +SparseMatrixCSC(S::AbstractSparseMatrixCSC) = copy(S) AbstractMatrix{Tv}(A::AbstractSparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv}(A) -SparseMatrixCSC{Tv}(S::AbstractSparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv}(S) +SparseMatrixCSC{Tv}(S::AbstractSparseMatrixCSC{Tv}) where {Tv} = copy(S) SparseMatrixCSC{Tv}(S::AbstractSparseMatrixCSC) where {Tv} = SparseMatrixCSC{Tv,eltype(getcolptr(S))}(S) -SparseMatrixCSC(S::SparseMatrixCSC)=copy(S) - - +SparseMatrixCSC{Tv,Ti}(S::AbstractSparseMatrixCSC{Tv,Ti}) where {Tv,Ti} = copy(S) function SparseMatrixCSC{Tv,Ti}(S::AbstractSparseMatrixCSC) where {Tv,Ti} eltypeTicolptr = Vector{Ti}(getcolptr(S)) eltypeTirowval = Vector{Ti}(rowvals(S)) From a602de5e661ac824254ea264a1ae635dba26a2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Fuhrmann?= Date: Thu, 5 Dec 2024 13:09:45 +0100 Subject: [PATCH 5/5] Don't mention "AbstractSparseMatrixCSC interface" in the docs. Just describe which methods are expected to be implemented. --- src/abstractsparse.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/abstractsparse.jl b/src/abstractsparse.jl index 4df865a4..e0074c7c 100644 --- a/src/abstractsparse.jl +++ b/src/abstractsparse.jl @@ -37,9 +37,9 @@ const AbstractSparseVecOrMat = Union{AbstractSparseVector,AbstractSparseMatrix} """ AbstractSparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti} -Supertype for matrix with compressed sparse column (CSC). -Subtypes of this type are expected to follow the `AbstractSparseMatrixCSC` interface -consisting of [`nnz`](@ref), [`rowvals`](@ref), [`nzrange`](@ref), [`nonzeros`](@ref) and [`getcolptr`](@ref). +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