1
+ # ###
2
+ # Matrix memory layout traits
3
+ #
4
+ # if MemoryLayout(A) returns BandedColumnMajor, you must override
5
+ # pointer and leadingdimension
6
+ # in addition to the banded matrix interface
7
+ # ###
8
+
9
+ abstract type AbstractBlockBandedLayout <: MemoryLayout end
10
+
11
+ struct BandedBlockBandedColumns{LAY} <: AbstractBlockBandedLayout end
12
+ struct BandedBlockBandedRows{LAY} <: AbstractBlockBandedLayout end
13
+ struct BlockBandedColumns{LAY} <: AbstractBlockBandedLayout end
14
+ struct BlockBandedRows{LAY} <: AbstractBlockBandedLayout end
15
+
16
+ const BandedBlockBandedColumnMajor = BandedBlockBandedColumns{ColumnMajor}
17
+ const BandedBlockBandedRowMajor = BandedBlockBandedColumns{RowMajor}
18
+ const BlockBandedColumnMajor = BlockBandedColumns{ColumnMajor}
19
+ const BlockBandedRowMajor = BlockBandedColumns{RowMajor}
20
+
21
+ transposelayout (:: BandedBlockBandedColumnMajor ) = BandedBlockBandedRowMajor ()
22
+ transposelayout (:: BandedBlockBandedRowMajor ) = BandedBlockBandedColumnMajor ()
23
+ transposelayout (:: BlockBandedColumnMajor ) = BlockBandedRowMajor ()
24
+ transposelayout (:: BlockBandedRowMajor ) = BlockBandedColumnMajor ()
25
+ conjlayout (:: Type{<:Complex} , M:: AbstractBlockBandedLayout ) = ConjLayout (M)
26
+
27
+
28
+
1
29
# AbstractBandedMatrix must implement
2
30
3
31
# A BlockBandedMatrix is a BlockMatrix, but is not a BandedMatrix
@@ -9,7 +37,7 @@ abstract type AbstractBlockBandedMatrix{T} <: AbstractBlockMatrix{T} end
9
37
10
38
Returns a tuple containing the upper and lower blockbandwidth of `A`.
11
39
"""
12
- blockbandwidths (A:: AbstractMatrix ) = (nblocks (A,1 )- 1 , nblocks (A,2 )- 1 )
40
+ blockbandwidths (A:: AbstractMatrix ) = (blocksize (A,1 )- 1 , blocksize (A,2 )- 1 )
13
41
14
42
"""
15
43
blockbandwidth(A,i)
@@ -29,9 +57,9 @@ blockbandrange(A::AbstractMatrix) = -blockbandwidth(A,1):blockbandwidth(A,2)
29
57
30
58
# start/stop indices of the i-th column/row, bounded by actual matrix size
31
59
@inline blockcolstart (A:: AbstractVecOrMat , i:: Integer ) = Block (max (i- colblockbandwidth (A,2 )[i], 1 ))
32
- @inline blockcolstop (A:: AbstractVecOrMat , i:: Integer ) = Block (max (min (i+ colblockbandwidth (A,1 )[i], nblocks (A, 1 )), 0 ))
60
+ @inline blockcolstop (A:: AbstractVecOrMat , i:: Integer ) = Block (max (min (i+ colblockbandwidth (A,1 )[i], blocksize (A, 1 )), 0 ))
33
61
@inline blockrowstart (A:: AbstractVecOrMat , i:: Integer ) = Block (max (i- rowblockbandwidth (A,1 )[i], 1 ))
34
- @inline blockrowstop (A:: AbstractVecOrMat , i:: Integer ) = Block (max (min (i+ rowblockbandwidth (A,2 )[i], nblocks (A, 2 )), 0 ))
62
+ @inline blockrowstop (A:: AbstractVecOrMat , i:: Integer ) = Block (max (min (i+ rowblockbandwidth (A,2 )[i], blocksize (A, 2 )), 0 ))
35
63
36
64
for Func in (:blockcolstart , :blockcolstop , :blockrowstart , :blockrowstop )
37
65
@eval $ Func (A, i:: Block{1} ) = $ Func (A, Int (i))
46
74
@inline blockrowlength (A:: AbstractVecOrMat , i) = max (Int (blockrowstop (A, i)) - Int (blockrowstart (A, i)) + 1 , 0 )
47
75
48
76
# this gives the block bandwidth in each block column/row
49
- @inline colblockbandwidths (A:: AbstractMatrix ) = Fill .(blockbandwidths (A), nblocks (A,2 ))
50
- @inline rowblockbandwidths (A:: AbstractMatrix ) = Fill .(blockbandwidths (A), nblocks (A,1 ))
77
+ @inline colblockbandwidths (A:: AbstractMatrix ) = Fill .(blockbandwidths (A), blocksize (A,2 ))
78
+ @inline rowblockbandwidths (A:: AbstractMatrix ) = Fill .(blockbandwidths (A), blocksize (A,1 ))
51
79
52
80
@inline colblockbandwidth (bs, i:: Int ) = colblockbandwidths (bs)[i]
53
81
@inline rowblockbandwidth (bs, i:: Int ) = rowblockbandwidths (bs)[i]
@@ -88,25 +116,35 @@ const BlockSlice1 = BlockSlice{Block{1,Int}}
88
116
# RaggedMatrix interface
89
117
# #####################################
90
118
119
+ @inline colstart (A:: AbstractBlockBandedMatrix , i:: Integer ) =
120
+ first (axes (A,1 )[blockcolstart (A,findblock (axes (A,2 ),i))])
91
121
92
-
93
- @inline function colstart (A:: AbstractBlockBandedMatrix , i:: Integer )
94
- bs = A. block_sizes. block_sizes
95
- bs. cumul_sizes[1 ][Int (blockcolstart (A, _find_block (bs, 2 , i)[1 ]))]
96
- end
97
122
@inline function colstop (A:: AbstractBlockBandedMatrix , i:: Integer )
98
- bs = A. block_sizes. block_sizes
99
- bs. cumul_sizes[1 ][Int (blockcolstop (A, _find_block (bs, 2 , i)[1 ]))+ 1 ]- 1
100
- end
101
- @inline function rowstart (A:: AbstractBlockBandedMatrix , i:: Integer )
102
- bs = A. block_sizes. block_sizes
103
- bs. cumul_sizes[2 ][Int (blockrowstart (A, _find_block (bs, 1 , i)[1 ]))]
123
+ CS = blockcolstop (A,findblock (axes (A,2 ),i))
124
+ CS == Block (0 ) && return 0
125
+ last (axes (A,1 )[CS])
104
126
end
127
+
128
+ @inline rowstart (A:: AbstractBlockBandedMatrix , i:: Integer ) =
129
+ first (axes (A,2 )[blockrowstart (A,findblock (axes (A,1 ),i))])
130
+
105
131
@inline function rowstop (A:: AbstractBlockBandedMatrix , i:: Integer )
106
- bs = A. block_sizes. block_sizes
107
- bs. cumul_sizes[2 ][Int (blockrowstop (A, _find_block (bs, 1 , i)[1 ]))+ 1 ]- 1
132
+ CS = blockrowstop (A,findblock (axes (A,1 ),i))
133
+ CS == Block (0 ) && return 0
134
+ last (axes (A,2 )[CS])
108
135
end
109
136
137
+ @inline blockbanded_colsupport (A, j:: Integer ) = colrange (A, j)
138
+ @inline blockbanded_rowsupport (A, j:: Integer ) = rowrange (A, j)
139
+
140
+ @inline blockbanded_rowsupport (A, j) = isempty (j) ? (1 : 0 ) : rowstart (A,minimum (j)): rowstop (A,maximum (j))
141
+ @inline blockbanded_colsupport (A, j) = isempty (j) ? (1 : 0 ) : colstart (A,minimum (j)): colstop (A,maximum (j))
142
+
143
+ @inline colsupport (:: AbstractBlockBandedLayout , A, j) = blockbanded_colsupport (A, j)
144
+ @inline rowsupport (:: AbstractBlockBandedLayout , A, j) = blockbanded_rowsupport (A, j)
145
+
146
+
147
+
110
148
# default implementation loops over all indices, including zeros
111
149
function fill! (A:: AbstractBlockBandedMatrix , val:: Any )
112
150
iszero (val) || throw (BandError (A))
0 commit comments