1
- module ArrayInterfaceBlockBandedMatrices
1
+ module ArrayInterfaceBlockBandedMatricesExt
2
2
3
- using ArrayInterfaceCore
4
- using ArrayInterfaceBandedMatrices
5
- using BlockArrays
6
- using BlockBandedMatrices
3
+ using ArrayInterface
4
+ using ArrayInterface: BandedMatrixIndex
7
5
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
9
15
count:: Int
10
16
refinds:: Array{Int,1}
11
17
refcoords:: Array{Int,1} # storing col or row inds at ref points
@@ -15,8 +21,8 @@ Base.firstindex(i::BlockBandedMatrixIndex) = 1
15
21
Base. lastindex (i:: BlockBandedMatrixIndex ) = i. count
16
22
Base. length (i:: BlockBandedMatrixIndex ) = lastindex (i)
17
23
function 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 )
20
26
sortedinds = sort (
21
27
[(blockrowind[i], blockcolind[i]) for i = 1 : length (blockrowind)],
22
28
by= x -> x[1 ],
@@ -81,7 +87,7 @@ Base.@propagate_inbounds function Base.getindex(ind::BlockBandedMatrixIndex, i::
81
87
end
82
88
end
83
89
84
- function ArrayInterfaceCore . findstructralnz (x:: BlockBandedMatrices.BlockBandedMatrix )
90
+ function ArrayInterface . findstructralnz (x:: BlockBandedMatrices.BlockBandedMatrix )
85
91
l, u = BlockBandedMatrices. blockbandwidths (x)
86
92
nrowblock = BlockBandedMatrices. blocksize (x, 1 )
87
93
ncolblock = BlockBandedMatrices. blocksize (x, 2 )
@@ -96,11 +102,11 @@ function ArrayInterfaceCore.findstructralnz(x::BlockBandedMatrices.BlockBandedMa
96
102
u,
97
103
)
98
104
end
99
- struct BandedBlockBandedMatrixIndex <: ArrayInterfaceCore .MatrixIndex
105
+ struct BandedBlockBandedMatrixIndex <: ArrayInterface .MatrixIndex
100
106
count:: Int
101
107
refinds:: Array{Int,1}
102
108
refcoords:: Array{Int,1} # storing col or row inds at ref points
103
- reflocalinds:: Array{ArrayInterfaceBandedMatrices. BandedMatrixIndex,1}
109
+ reflocalinds:: Array{BandedMatrixIndex,1}
104
110
isrow:: Bool
105
111
end
106
112
Base. firstindex (i:: BandedBlockBandedMatrixIndex ) = 1
@@ -128,8 +134,8 @@ function BandedBlockBandedMatrixIndex(
128
134
lambda,
129
135
mu,
130
136
)
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 )
133
139
sortedinds = sort (
134
140
[(blockrowind[i], blockcolind[i]) for i = 1 : length (blockrowind)],
135
141
by= x -> x[1 ],
@@ -143,14 +149,14 @@ function BandedBlockBandedMatrixIndex(
143
149
refinds = Array {Int,1} ()
144
150
refrowcoords = Array {Int,1} ()
145
151
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} ()
148
154
for ind in sortedinds
149
155
rowind, colind = ind
150
156
localrowind =
151
- ArrayInterfaceBandedMatrices . BandedMatrixIndex (rowsizes[rowind], colsizes[colind], lambda, mu, true )
157
+ BandedMatrixIndex (rowsizes[rowind], colsizes[colind], lambda, mu, true )
152
158
localcolind =
153
- ArrayInterfaceBandedMatrices . BandedMatrixIndex (rowsizes[rowind], colsizes[colind], lambda, mu, false )
159
+ BandedMatrixIndex (rowsizes[rowind], colsizes[colind], lambda, mu, false )
154
160
push! (refinds, currenti)
155
161
push! (refrowcoords, rowheights[rowind])
156
162
push! (refcolcoords, colwidths[colind])
@@ -178,7 +184,7 @@ function BandedBlockBandedMatrixIndex(
178
184
rowindobj, colindobj
179
185
end
180
186
181
- function ArrayInterfaceCore . findstructralnz (x:: BlockBandedMatrices.BandedBlockBandedMatrix )
187
+ function ArrayInterface . findstructralnz (x:: BlockBandedMatrices.BandedBlockBandedMatrix )
182
188
l, u = BlockBandedMatrices. blockbandwidths (x)
183
189
lambda, mu = BlockBandedMatrices. subblockbandwidths (x)
184
190
nrowblock = BlockBandedMatrices. blocksize (x, 1 )
@@ -197,19 +203,19 @@ function ArrayInterfaceCore.findstructralnz(x::BlockBandedMatrices.BandedBlockBa
197
203
)
198
204
end
199
205
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
206
212
207
- function ArrayInterfaceCore . matrix_colors (A:: BlockBandedMatrices.BlockBandedMatrix )
213
+ function ArrayInterface . matrix_colors (A:: BlockBandedMatrices.BlockBandedMatrix )
208
214
l, u = BlockBandedMatrices. blockbandwidths (A)
209
215
blockwidth = l + u + 1
210
216
nblock = BlockBandedMatrices. blocksize (A, 2 )
211
217
cols = BlockArrays. blocklengths (axes (A, 2 ))
212
- blockcolors = ArrayInterfaceCore . _cycle (1 : blockwidth, nblock)
218
+ blockcolors = ArrayInterface . _cycle (1 : blockwidth, nblock)
213
219
# the reserved number of colors of a block is the maximum length of columns of blocks with the same block color
214
220
ncolors = [maximum (cols[i: blockwidth: nblock]) for i = 1 : blockwidth]
215
221
endinds = cumsum (ncolors)
@@ -221,14 +227,14 @@ function ArrayInterfaceCore.matrix_colors(A::BlockBandedMatrices.BlockBandedMatr
221
227
return reduce (vcat, colors)
222
228
end
223
229
224
- function ArrayInterfaceCore . matrix_colors (A:: BlockBandedMatrices.BandedBlockBandedMatrix )
230
+ function ArrayInterface . matrix_colors (A:: BlockBandedMatrices.BandedBlockBandedMatrix )
225
231
l, u = BlockBandedMatrices. blockbandwidths (A)
226
232
lambda, mu = BlockBandedMatrices. subblockbandwidths (A)
227
233
blockwidth = l + u + 1
228
234
subblockwidth = lambda + mu + 1
229
235
nblock = BlockBandedMatrices. blocksize (A, 2 )
230
236
cols = BlockArrays. blocklengths (axes (A, 2 ))
231
- blockcolors = ArrayInterfaceCore . _cycle (1 : blockwidth, nblock)
237
+ blockcolors = ArrayInterface . _cycle (1 : blockwidth, nblock)
232
238
# 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
233
239
ncolors = [
234
240
min (subblockwidth, maximum (cols[i: blockwidth: nblock]))
@@ -237,7 +243,7 @@ function ArrayInterfaceCore.matrix_colors(A::BlockBandedMatrices.BandedBlockBand
237
243
endinds = cumsum (ncolors)
238
244
startinds = [endinds[i] - ncolors[i] + 1 for i = 1 : min (blockwidth, nblock)]
239
245
colors = [
240
- ArrayInterfaceCore . _cycle (startinds[blockcolors[i]]: endinds[blockcolors[i]], cols[i])
246
+ ArrayInterface . _cycle (startinds[blockcolors[i]]: endinds[blockcolors[i]], cols[i])
241
247
for i = 1 : nblock
242
248
]
243
249
return reduce (vcat, colors)
0 commit comments