Skip to content

Commit d7aa0f0

Browse files
add fast_matrix_colors
1 parent 961ecf9 commit d7aa0f0

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ Determine whether `findstructralnz` accepts the parameter `x`
3333
Returns iterators `(I,J)` of the non-zeros in the structure of the matrix `x`.
3434
The same as the to first two elements of `findnz(::SparseMatrixCSC)`
3535

36+
## fast_matrix_colors(A)
37+
38+
A trait function for whether `matrix_colors(A)` is a fast algorithm or a slow
39+
(graphically-based) method.
40+
3641
## matrix_colors(A)
3742

3843
Returns an array of for the sparsity colors of a matrix type `A`. Also includes

src/ArrayInterface.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ end
125125

126126
abstract type ColoringAlgorithm end
127127

128+
"""
129+
fast_matrix_colors(A)
130+
131+
Query whether a matrix has a fast algorithm for getting the structural
132+
colors of the matrix.
133+
"""
134+
fast_matrix_colors(A) = false
135+
fast_matrix_colors(A::Union{Diagonal,Bidiagonal,Tridiagonal,SymTridiagonal}) = true
136+
128137
"""
129138
matrix_colors(A::Union{Array,UpperTriangular,LowerTriangular})
130139
@@ -170,20 +179,22 @@ function __init__()
170179

171180
@require BandedMatrices="aae01518-5342-5314-be14-df237901396f" begin
172181
is_structured(::BandedMatrices.BandedMatrix) = true
173-
174-
function matrix_colors(A::BandedMatrix)
182+
fast_matrix_colors(::BandedMatrices.BandedMatrix) = true
183+
function matrix_colors(A::BandedMatrices.BandedMatrix)
175184
u,l=bandwidths(A)
176185
width=u+l+1
177186
_cycle(1:width,size(A,2))
178187
end
179-
188+
180189
end
181190

182191
@require BlockBandedMatrices="aae01518-5342-5314-be14-df237901396f" begin
183192
is_structured(::BandedMatrices.BlockBandedMatrix) = true
184193
is_structured(::BandedMatrices.BandedBlockBandedMatrix) = true
194+
fast_matrix_colors(::BlockBandedMatrices.BlockBandedMatrix) = true
195+
fast_matrix_colors(::BlockBandedMatrices.BandedBlockBandedMatrix) = true
185196

186-
function matrix_colors(A::BlockBandedMatrix)
197+
function matrix_colors(A::BlockBandedMatrices.BlockBandedMatrix)
187198
l,u=blockbandwidths(A)
188199
blockwidth=l+u+1
189200
nblock=nblocks(A,2)
@@ -197,7 +208,7 @@ function __init__()
197208
vcat(colors...)
198209
end
199210

200-
function matrix_colors(A::BandedBlockBandedMatrix)
211+
function matrix_colors(A::BlockBandedMatrices.BandedBlockBandedMatrix)
201212
l,u=blockbandwidths(A)
202213
lambda,mu=subblockbandwidths(A)
203214
blockwidth=l+u+1

0 commit comments

Comments
 (0)