1- module ArrayInterfaceBlockBandedMatrices
1+ module ArrayInterfaceBlockBandedMatricesExt
22
3- using ArrayInterfaceCore
4- using ArrayInterfaceBandedMatrices
5- using BlockArrays
6- using BlockBandedMatrices
3+ using ArrayInterface
4+ using ArrayInterface: BandedMatrixIndex
75
8- struct BlockBandedMatrixIndex <: ArrayInterfaceCore.MatrixIndex
6+ if isdefined (Base, :get_extension )
7+ using BlockBandedMatrices
8+ using BlockBandedMatrices. BlockArrays
9+ else
10+ using .. BlockBandedMatrices
11+ using .. BlockBandedMatrices. BlockArrays
12+ end
13+
14+ struct BlockBandedMatrixIndex <: ArrayInterface.MatrixIndex
915 count:: Int
1016 refinds:: Array{Int,1}
1117 refcoords:: Array{Int,1} # storing col or row inds at ref points
@@ -15,8 +21,8 @@ Base.firstindex(i::BlockBandedMatrixIndex) = 1
1521Base. lastindex (i:: BlockBandedMatrixIndex ) = i. count
1622Base. length (i:: BlockBandedMatrixIndex ) = lastindex (i)
1723function BlockBandedMatrixIndex (nrowblock, ncolblock, rowsizes, colsizes, l, u)
18- blockrowind = ArrayInterfaceBandedMatrices . BandedMatrixIndex (nrowblock, ncolblock, l, u, true )
19- blockcolind = ArrayInterfaceBandedMatrices . BandedMatrixIndex (nrowblock, ncolblock, l, u, false )
24+ blockrowind = BandedMatrixIndex (nrowblock, ncolblock, l, u, true )
25+ blockcolind = BandedMatrixIndex (nrowblock, ncolblock, l, u, false )
2026 sortedinds = sort (
2127 [(blockrowind[i], blockcolind[i]) for i = 1 : length (blockrowind)],
2228 by= x -> x[1 ],
@@ -81,7 +87,7 @@ Base.@propagate_inbounds function Base.getindex(ind::BlockBandedMatrixIndex, i::
8187 end
8288end
8389
84- function ArrayInterfaceCore . findstructralnz (x:: BlockBandedMatrices.BlockBandedMatrix )
90+ function ArrayInterface . findstructralnz (x:: BlockBandedMatrices.BlockBandedMatrix )
8591 l, u = BlockBandedMatrices. blockbandwidths (x)
8692 nrowblock = BlockBandedMatrices. blocksize (x, 1 )
8793 ncolblock = BlockBandedMatrices. blocksize (x, 2 )
@@ -96,11 +102,11 @@ function ArrayInterfaceCore.findstructralnz(x::BlockBandedMatrices.BlockBandedMa
96102 u,
97103 )
98104end
99- struct BandedBlockBandedMatrixIndex <: ArrayInterfaceCore .MatrixIndex
105+ struct BandedBlockBandedMatrixIndex <: ArrayInterface .MatrixIndex
100106 count:: Int
101107 refinds:: Array{Int,1}
102108 refcoords:: Array{Int,1} # storing col or row inds at ref points
103- reflocalinds:: Array{ArrayInterfaceBandedMatrices. BandedMatrixIndex,1}
109+ reflocalinds:: Array{BandedMatrixIndex,1}
104110 isrow:: Bool
105111end
106112Base. firstindex (i:: BandedBlockBandedMatrixIndex ) = 1
@@ -128,8 +134,8 @@ function BandedBlockBandedMatrixIndex(
128134 lambda,
129135 mu,
130136)
131- blockrowind = ArrayInterfaceBandedMatrices . BandedMatrixIndex (nrowblock, ncolblock, l, u, true )
132- blockcolind = ArrayInterfaceBandedMatrices . BandedMatrixIndex (nrowblock, ncolblock, l, u, false )
137+ blockrowind = BandedMatrixIndex (nrowblock, ncolblock, l, u, true )
138+ blockcolind = BandedMatrixIndex (nrowblock, ncolblock, l, u, false )
133139 sortedinds = sort (
134140 [(blockrowind[i], blockcolind[i]) for i = 1 : length (blockrowind)],
135141 by= x -> x[1 ],
@@ -143,14 +149,14 @@ function BandedBlockBandedMatrixIndex(
143149 refinds = Array {Int,1} ()
144150 refrowcoords = Array {Int,1} ()
145151 refcolcoords = Array {Int,1} ()
146- reflocalrowinds = Array {ArrayInterfaceBandedMatrices. BandedMatrixIndex,1} ()
147- reflocalcolinds = Array {ArrayInterfaceBandedMatrices. BandedMatrixIndex,1} ()
152+ reflocalrowinds = Array {BandedMatrixIndex,1} ()
153+ reflocalcolinds = Array {BandedMatrixIndex,1} ()
148154 for ind in sortedinds
149155 rowind, colind = ind
150156 localrowind =
151- ArrayInterfaceBandedMatrices . BandedMatrixIndex (rowsizes[rowind], colsizes[colind], lambda, mu, true )
157+ BandedMatrixIndex (rowsizes[rowind], colsizes[colind], lambda, mu, true )
152158 localcolind =
153- ArrayInterfaceBandedMatrices . BandedMatrixIndex (rowsizes[rowind], colsizes[colind], lambda, mu, false )
159+ BandedMatrixIndex (rowsizes[rowind], colsizes[colind], lambda, mu, false )
154160 push! (refinds, currenti)
155161 push! (refrowcoords, rowheights[rowind])
156162 push! (refcolcoords, colwidths[colind])
@@ -178,7 +184,7 @@ function BandedBlockBandedMatrixIndex(
178184 rowindobj, colindobj
179185end
180186
181- function ArrayInterfaceCore . findstructralnz (x:: BlockBandedMatrices.BandedBlockBandedMatrix )
187+ function ArrayInterface . findstructralnz (x:: BlockBandedMatrices.BandedBlockBandedMatrix )
182188 l, u = BlockBandedMatrices. blockbandwidths (x)
183189 lambda, mu = BlockBandedMatrices. subblockbandwidths (x)
184190 nrowblock = BlockBandedMatrices. blocksize (x, 1 )
@@ -197,19 +203,19 @@ function ArrayInterfaceCore.findstructralnz(x::BlockBandedMatrices.BandedBlockBa
197203 )
198204end
199205
200- ArrayInterfaceCore . has_sparsestruct (:: Type{<:BlockBandedMatrices.BlockBandedMatrix} ) = true
201- ArrayInterfaceCore . has_sparsestruct (:: Type{<:BlockBandedMatrices.BandedBlockBandedMatrix} ) = true
202- ArrayInterfaceCore . isstructured (:: Type{<:BlockBandedMatrices.BlockBandedMatrix} ) = true
203- ArrayInterfaceCore . isstructured (:: Type{<:BlockBandedMatrices.BandedBlockBandedMatrix} ) = true
204- ArrayInterfaceCore . fast_matrix_colors (:: Type{<:BlockBandedMatrices.BlockBandedMatrix} ) = true
205- ArrayInterfaceCore . fast_matrix_colors (:: Type{<:BlockBandedMatrices.BandedBlockBandedMatrix} ) = true
206+ ArrayInterface . has_sparsestruct (:: Type{<:BlockBandedMatrices.BlockBandedMatrix} ) = true
207+ ArrayInterface . has_sparsestruct (:: Type{<:BlockBandedMatrices.BandedBlockBandedMatrix} ) = true
208+ ArrayInterface . isstructured (:: Type{<:BlockBandedMatrices.BlockBandedMatrix} ) = true
209+ ArrayInterface . isstructured (:: Type{<:BlockBandedMatrices.BandedBlockBandedMatrix} ) = true
210+ ArrayInterface . fast_matrix_colors (:: Type{<:BlockBandedMatrices.BlockBandedMatrix} ) = true
211+ ArrayInterface . fast_matrix_colors (:: Type{<:BlockBandedMatrices.BandedBlockBandedMatrix} ) = true
206212
207- function ArrayInterfaceCore . matrix_colors (A:: BlockBandedMatrices.BlockBandedMatrix )
213+ function ArrayInterface . matrix_colors (A:: BlockBandedMatrices.BlockBandedMatrix )
208214 l, u = BlockBandedMatrices. blockbandwidths (A)
209215 blockwidth = l + u + 1
210216 nblock = BlockBandedMatrices. blocksize (A, 2 )
211217 cols = BlockArrays. blocklengths (axes (A, 2 ))
212- blockcolors = ArrayInterfaceCore . _cycle (1 : blockwidth, nblock)
218+ blockcolors = ArrayInterface . _cycle (1 : blockwidth, nblock)
213219 # the reserved number of colors of a block is the maximum length of columns of blocks with the same block color
214220 ncolors = [maximum (cols[i: blockwidth: nblock]) for i = 1 : blockwidth]
215221 endinds = cumsum (ncolors)
@@ -221,14 +227,14 @@ function ArrayInterfaceCore.matrix_colors(A::BlockBandedMatrices.BlockBandedMatr
221227 return reduce (vcat, colors)
222228end
223229
224- function ArrayInterfaceCore . matrix_colors (A:: BlockBandedMatrices.BandedBlockBandedMatrix )
230+ function ArrayInterface . matrix_colors (A:: BlockBandedMatrices.BandedBlockBandedMatrix )
225231 l, u = BlockBandedMatrices. blockbandwidths (A)
226232 lambda, mu = BlockBandedMatrices. subblockbandwidths (A)
227233 blockwidth = l + u + 1
228234 subblockwidth = lambda + mu + 1
229235 nblock = BlockBandedMatrices. blocksize (A, 2 )
230236 cols = BlockArrays. blocklengths (axes (A, 2 ))
231- blockcolors = ArrayInterfaceCore . _cycle (1 : blockwidth, nblock)
237+ blockcolors = ArrayInterface . _cycle (1 : blockwidth, nblock)
232238 # the reserved number of colors of a block is the min of subblockwidth and the largest length of columns of blocks with the same block color
233239 ncolors = [
234240 min (subblockwidth, maximum (cols[i: blockwidth: nblock]))
@@ -237,7 +243,7 @@ function ArrayInterfaceCore.matrix_colors(A::BlockBandedMatrices.BandedBlockBand
237243 endinds = cumsum (ncolors)
238244 startinds = [endinds[i] - ncolors[i] + 1 for i = 1 : min (blockwidth, nblock)]
239245 colors = [
240- ArrayInterfaceCore . _cycle (startinds[blockcolors[i]]: endinds[blockcolors[i]], cols[i])
246+ ArrayInterface . _cycle (startinds[blockcolors[i]]: endinds[blockcolors[i]], cols[i])
241247 for i = 1 : nblock
242248 ]
243249 return reduce (vcat, colors)
0 commit comments