From 158df1f3562051001bd34844069f0e64f8456a37 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 23 Aug 2019 16:04:16 -0700 Subject: [PATCH 1/3] [ci skip] RFC: AbstractSparseMatrixCSC --- .../docs/src/AbstractSparseMatrixCSC.md | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md diff --git a/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md b/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md new file mode 100644 index 0000000000000..06e168ad2dca0 --- /dev/null +++ b/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md @@ -0,0 +1,59 @@ + AbstractSparseMatrixCSC{Tv,Ti<:Integer} <: AbstractSparseMatrix{Tv,Ti} + +Supertype for matrix with compressed sparse column (CSC). + +## `AbstractSparseMatrixCSC` interface + +In addition to the [Abstract array interface](@ref man-interface-array), every +`AbstractSparseMatrixCSC` subtype `TS` must provide the following methods: + +* [`size(::TS)`](@ref size) +* [`getcolptr(::TS) :: AbstractVector{<:Ti}`](@ref getcolptr) +* [`rowvals(::TS) :: AbstractVector{<:Ti}`](@ref rowvals) +* [`nonzeros(::TS) :: AbstractVector{<:Tv}`](@ref nonzeros) + +Other sparse matrix methods such as [`nzrange`](@ref) and [`nnz`](@ref) are automatically +defined in terms of above functions. + +## Assumed invariance + +To use algorithms defined in SparseArrays, a matrix `A` of type `AbstractSparseMatrixCSC` +must satisfy the following constraints. + +### Matrix `A` and all vectors constituting `A` have one-based indexing + +```julia +@assert !has_offset_axes(A) +@assert !has_offset_axes(getcolptr(A)) +@assert !has_offset_axes(rowvals(A)) +@assert !has_offset_axes(nonzeros(A)) +``` + +### Row indices in `rowval(A)` for each column are sorted + +```julia +for col in axes(A, 2) + @assert issorted(rowval(A)[nzrange(A, col)]) +end +``` + +### Column pointers in `getcolptr(A)` are increasing, started at 1 + +```julia +@assert getcolptr(A)[1] === 1 +@assert all(diff(getcolptr(A)) .>= 0) +``` + +### Row index vector `rowvals(A)` and non-zero value vector `nonzeros(A)` are long enough + +```julia +@assert nnz(A) <= length(rowvals(A)) +@assert nnz(A) <= length(nonzeros(A)) +``` + +### Indices for rows, `rowvals(A)` and `nonzeros(A)` are representable by `Ti` + +```julia +@assert size(A, 1) <= typemax(Ti) +@assert nnz(A) <= typemax(Ti) +``` From ae92d377f1337ddb4472415a777107e690d2d75b Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Fri, 23 Aug 2019 20:35:09 -0700 Subject: [PATCH 2/3] [ci skip] Add compat --- stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md b/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md index 06e168ad2dca0..4c3b23b2e3740 100644 --- a/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md +++ b/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md @@ -2,6 +2,9 @@ Supertype for matrix with compressed sparse column (CSC). +!!! compat "Julia 1.4" + `AbstractSparseMatrixCSC` requires at least Julia 1.4. + ## `AbstractSparseMatrixCSC` interface In addition to the [Abstract array interface](@ref man-interface-array), every From 03e904d01ace7e34f1e825a18856ae1e0228f49d Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 25 Aug 2019 00:46:29 -0700 Subject: [PATCH 3/3] Rename getcolptr to coloffsets --- .../SparseArrays/docs/src/AbstractSparseMatrixCSC.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md b/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md index 4c3b23b2e3740..f704af1771332 100644 --- a/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md +++ b/stdlib/SparseArrays/docs/src/AbstractSparseMatrixCSC.md @@ -11,7 +11,7 @@ In addition to the [Abstract array interface](@ref man-interface-array), every `AbstractSparseMatrixCSC` subtype `TS` must provide the following methods: * [`size(::TS)`](@ref size) -* [`getcolptr(::TS) :: AbstractVector{<:Ti}`](@ref getcolptr) +* [`coloffsets(::TS) :: AbstractVector{<:Ti}`](@ref coloffsets) * [`rowvals(::TS) :: AbstractVector{<:Ti}`](@ref rowvals) * [`nonzeros(::TS) :: AbstractVector{<:Tv}`](@ref nonzeros) @@ -27,7 +27,7 @@ must satisfy the following constraints. ```julia @assert !has_offset_axes(A) -@assert !has_offset_axes(getcolptr(A)) +@assert !has_offset_axes(coloffsets(A)) @assert !has_offset_axes(rowvals(A)) @assert !has_offset_axes(nonzeros(A)) ``` @@ -40,11 +40,11 @@ for col in axes(A, 2) end ``` -### Column pointers in `getcolptr(A)` are increasing, started at 1 +### Column pointers in `coloffsets(A)` are increasing, started at 1 ```julia -@assert getcolptr(A)[1] === 1 -@assert all(diff(getcolptr(A)) .>= 0) +@assert coloffsets(A)[1] === 1 +@assert all(diff(coloffsets(A)) .>= 0) ``` ### Row index vector `rowvals(A)` and non-zero value vector `nonzeros(A)` are long enough