Skip to content

Commit 1b4926f

Browse files
authored
Updated docstrings for BlockSkylineMatrix & BandedBlockBandedMatrix (#79)
1 parent 91c7d48 commit 1b4926f

File tree

2 files changed

+90
-24
lines changed

2 files changed

+90
-24
lines changed

src/BandedBlockBandedMatrix.jl

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
function check_data_sizes(data::AbstractMatrix, raxis, (l,u), (λ,μ))
42
if blocksize(data,1)  l + u + 1 && !(blocksize(data,1) == 0 && (-l > u || -λ > μ))
53
throw(ArgumentError("Data matrix must have number of row blocks equal to number of block bands"))
@@ -40,8 +38,8 @@ end
4038

4139
const DefaultBandedBlockBandedMatrix{T} = BandedBlockBandedMatrix{T, PseudoBlockMatrix{T, Matrix{T}, NTuple{2,DefaultBlockAxis}}, DefaultBlockAxis}
4240

43-
@inline _BandedBlockBandedMatrix(data::AbstractMatrix, axes::NTuple{2,AbstractUnitRange{Int}}, lu::NTuple{2,Int}, λμ::NTuple{2,Int}) =
44-
_BandedBlockBandedMatrix(PseudoBlockArray(data,(blockedrange(Fill(sum(λμ)+1,sum(lu)+1)),axes[2])), axes[1], lu, λμ)
41+
@inline _BandedBlockBandedMatrix(data::AbstractMatrix, axes::NTuple{2,AbstractUnitRange{Int}}, lu::NTuple{2,Int}, λμ::NTuple{2,Int}) =
42+
_BandedBlockBandedMatrix(PseudoBlockArray(data,(blockedrange(Fill(sum(λμ)+1,sum(lu)+1)),axes[2])), axes[1], lu, λμ)
4543

4644
_BandedBlockBandedMatrix(data::AbstractMatrix,rblocksizes::AbstractVector{Int}, cblocksizes::AbstractVector{Int}, lu::NTuple{2,Int}, λμ::NTuple{2,Int}) =
4745
_BandedBlockBandedMatrix(data, (blockedrange(rblocksizes),blockedrange(cblocksizes)), lu, λμ)
@@ -63,11 +61,46 @@ BandedBlockBandedMatrix{T,B}(::UndefInitializer, rblocksizes::AbstractVector{Int
6361

6462

6563
"""
66-
BandedBlockBandedMatrix{T}(undef, (rows, cols), (l, u), (λ, μ))
67-
68-
returns an undef `sum(rows)`×`sum(cols)` banded-block-banded matrix `A`
69-
of type `T` with block-bandwidths `(l,u)` and where `A[Block(K,J)]`
70-
is a `BandedMatrix{T}` of size `rows[K]`×`cols[J]` with bandwidths `(λ,μ)`.
64+
BandedBlockBandedMatrix{T}(M::Union{UndefInitializer,UniformScaling,AbstractMatrix},
65+
rows, cols, (l, u), (λ, μ))
66+
67+
returns a `sum(rows)`×`sum(cols)` banded-block-banded matrix `A` of
68+
type `T` with block-bandwidths `(l,u)` and where `A[Block(K,J)]` is a
69+
`BandedMatrix{T}` of size `rows[K]`×`cols[J]` with bandwidths `(λ,μ)`.
70+
71+
# Examples
72+
73+
```jldoctest
74+
julia> BandedBlockBandedMatrix(I, [3,4,3], [3,4,3], (1,1), (1,1))
75+
3×3-blocked 10×10 BandedBlockBandedMatrix{Bool,BlockArrays.PseudoBlockArray{Bool,2,Array{Bool,2},Tuple{BlockArrays.BlockedUnitRange{Array{Int64,1}},BlockArrays.BlockedUnitRange{Array{Int64,1}}}},BlockArrays.BlockedUnitRange{Array{Int64,1}}}:
76+
1 0 ⋅ │ 0 0 ⋅ ⋅ │ ⋅ ⋅ ⋅
77+
0 1 0 │ 0 0 0 ⋅ │ ⋅ ⋅ ⋅
78+
⋅ 0 1 │ ⋅ 0 0 0 │ ⋅ ⋅ ⋅
79+
─────────┼──────────────┼─────────
80+
0 0 ⋅ │ 1 0 ⋅ ⋅ │ 0 0 ⋅
81+
0 0 0 │ 0 1 0 ⋅ │ 0 0 0
82+
⋅ 0 0 │ ⋅ 0 1 0 │ ⋅ 0 0
83+
⋅ ⋅ 0 │ ⋅ ⋅ 0 1 │ ⋅ ⋅ 0
84+
─────────┼──────────────┼─────────
85+
⋅ ⋅ ⋅ │ 0 0 ⋅ ⋅ │ 1 0 ⋅
86+
⋅ ⋅ ⋅ │ 0 0 0 ⋅ │ 0 1 0
87+
⋅ ⋅ ⋅ │ ⋅ 0 0 0 │ ⋅ 0 1
88+
89+
julia> BandedBlockBandedMatrix(Ones{Int}(10,13), [3,4,3], [4,5,4], (1,1), (1,1))
90+
3×3-blocked 10×13 BandedBlockBandedMatrix{Int64,BlockArrays.PseudoBlockArray{Int64,2,Array{Int64,2},Tuple{BlockArrays.BlockedUnitRange{Array{Int64,1}},BlockArrays.BlockedUnitRange{Array{Int64,1}}}},BlockArrays.BlockedUnitRange{Array{Int64,1}}}:
91+
1 1 ⋅ ⋅ │ 1 1 ⋅ ⋅ ⋅ │ ⋅ ⋅ ⋅ ⋅
92+
1 1 1 ⋅ │ 1 1 1 ⋅ ⋅ │ ⋅ ⋅ ⋅ ⋅
93+
⋅ 1 1 1 │ ⋅ 1 1 1 ⋅ │ ⋅ ⋅ ⋅ ⋅
94+
────────────┼─────────────────┼────────────
95+
1 1 ⋅ ⋅ │ 1 1 ⋅ ⋅ ⋅ │ 1 1 ⋅ ⋅
96+
1 1 1 ⋅ │ 1 1 1 ⋅ ⋅ │ 1 1 1 ⋅
97+
⋅ 1 1 1 │ ⋅ 1 1 1 ⋅ │ ⋅ 1 1 1
98+
⋅ ⋅ 1 1 │ ⋅ ⋅ 1 1 1 │ ⋅ ⋅ 1 1
99+
────────────┼─────────────────┼────────────
100+
⋅ ⋅ ⋅ ⋅ │ 1 1 ⋅ ⋅ ⋅ │ 1 1 ⋅ ⋅
101+
⋅ ⋅ ⋅ ⋅ │ 1 1 1 ⋅ ⋅ │ 1 1 1 ⋅
102+
⋅ ⋅ ⋅ ⋅ │ ⋅ 1 1 1 ⋅ │ ⋅ 1 1 1
103+
```
71104
"""
72105
BandedBlockBandedMatrix
73106

@@ -127,17 +160,17 @@ BandedBlockBandedMatrix{T}(m::Union{AbstractMatrix, UniformScaling},
127160
BandedBlockBandedMatrix{T,B,R}(m::Union{AbstractMatrix, UniformScaling},
128161
rdims::AbstractVector{Int}, cdims::AbstractVector{Int},
129162
lu::NTuple{2,Int}, λμ::NTuple{2,Int}) where {T,B,R<:AbstractUnitRange{Int}} =
130-
BandedBlockBandedMatrix{T,B,R}(m, (blockedrange(rdims),blockedrange(cdims)), lu, λμ)
163+
BandedBlockBandedMatrix{T,B,R}(m, (blockedrange(rdims),blockedrange(cdims)), lu, λμ)
131164

132165
BandedBlockBandedMatrix{T,B}(m::Union{AbstractMatrix, UniformScaling},
133166
rdims::AbstractVector{Int}, cdims::AbstractVector{Int},
134167
lu::NTuple{2,Int}, λμ::NTuple{2,Int}) where {T,B} =
135-
BandedBlockBandedMatrix{T,B}(m, (blockedrange(rdims),blockedrange(cdims)), lu, λμ)
168+
BandedBlockBandedMatrix{T,B}(m, (blockedrange(rdims),blockedrange(cdims)), lu, λμ)
136169

137170
BandedBlockBandedMatrix{T}(m::Union{AbstractMatrix, UniformScaling},
138171
rdims::AbstractVector{Int}, cdims::AbstractVector{Int},
139172
lu::NTuple{2,Int}, λμ::NTuple{2,Int}) where T =
140-
BandedBlockBandedMatrix{T}(m, (blockedrange(rdims),blockedrange(cdims)), lu, λμ)
173+
BandedBlockBandedMatrix{T}(m, (blockedrange(rdims),blockedrange(cdims)), lu, λμ)
141174

142175

143176
BandedBlockBandedMatrix(A::Union{AbstractMatrix,UniformScaling},
@@ -147,12 +180,12 @@ BandedBlockBandedMatrix(A::Union{AbstractMatrix,UniformScaling},
147180
BandedBlockBandedMatrix(A::Union{AbstractMatrix,UniformScaling},
148181
rdims::AbstractVector{Int}, cdims::AbstractVector{Int},
149182
lu::NTuple{2,Int}, λμ::NTuple{2,Int}) =
150-
BandedBlockBandedMatrix(A, (blockedrange(rdims),blockedrange(cdims)), lu, λμ)
151-
152-
183+
BandedBlockBandedMatrix(A, (blockedrange(rdims),blockedrange(cdims)), lu, λμ)
184+
185+
153186
function BandedBlockBandedMatrix{T,Blocks,RR}(A::AbstractMatrix, axes::NTuple{2,AbstractUnitRange{Int}}, lu::NTuple{2,Int}, λμ::NTuple{2,Int}) where {T,Blocks,RR<:AbstractUnitRange{Int}}
154187
ret = BandedBlockBandedMatrix{T,Blocks,RR}(Zeros{T}(size(A)), axes, lu, λμ)
155-
L,M = λμ
188+
L,M = λμ
156189
for J = blockaxes(ret,2), K = blockcolsupport(ret, J)
157190
kr, jr = axes[1][K], axes[2][J]
158191

@@ -189,7 +222,7 @@ similar(A::BandedBlockBandedMatrix, ::Type{T}, axes::NTuple{2,AbstractUnitRange{
189222
@inline similar(A::BandedBlockBandedMatrix, ::Type{T}, axes::Tuple{BlockedUnitRange,AbstractUnitRange{Int}}) where T =
190223
BandedBlockBandedMatrix{T}(undef, axes, blockbandwidths(A), subblockbandwidths(A))
191224
@inline similar(A::BandedBlockBandedMatrix, ::Type{T}, axes::Tuple{AbstractUnitRange{Int},BlockedUnitRange}) where T =
192-
BandedBlockBandedMatrix{T}(undef, axes, blockbandwidths(A), subblockbandwidths(A))
225+
BandedBlockBandedMatrix{T}(undef, axes, blockbandwidths(A), subblockbandwidths(A))
193226
@inline similar(A::BandedBlockBandedMatrix, ::Type{T}, axes::Tuple{BlockedUnitRange,BlockedUnitRange}) where T =
194227
BandedBlockBandedMatrix{T}(undef, axes, blockbandwidths(A), subblockbandwidths(A))
195228

@@ -225,10 +258,10 @@ end
225258
bandedblockbandedcolumns(L::AbstractColumnMajor) = BandedBlockBandedColumnMajor()
226259
bandedblockbandedcolumns(_) = BandedBlockBandedColumns{UnknownLayout}()
227260

228-
MemoryLayout(::Type{<:BandedBlockBandedMatrix{<:Any,BLOCKS}}) where BLOCKS =
261+
MemoryLayout(::Type{<:BandedBlockBandedMatrix{<:Any,BLOCKS}}) where BLOCKS =
229262
bandedblockbandedcolumns(MemoryLayout(BLOCKS))
230263
bandedblockbandedbroadcaststyle(_) = BandedBlockBandedStyle()
231-
BroadcastStyle(::Type{<:BandedBlockBandedMatrix{<:Any,BLOCKS}}) where BLOCKS =
264+
BroadcastStyle(::Type{<:BandedBlockBandedMatrix{<:Any,BLOCKS}}) where BLOCKS =
232265
bandedblockbandedbroadcaststyle(BroadcastStyle(BLOCKS))
233266

234267
isbandedblockbanded(_) = false
@@ -431,7 +464,7 @@ isbanded(A::SubArray{<:Any,2,<:BandedBlockBandedMatrix}) = MemoryLayout(typeof(A
431464
isbandedblockbanded(A::SubArray{<:Any,2,<:BandedBlockBandedMatrix}) = MemoryLayout(typeof(A)) == BandedBlockBandedColumnMajor()
432465

433466

434-
subblockbandwidths(V::SubArray{<:Any,2,<:Any,<:Tuple{<:BlockSlice{BlockRange1},<:BlockSlice{BlockRange1}}}) =
467+
subblockbandwidths(V::SubArray{<:Any,2,<:Any,<:Tuple{<:BlockSlice{BlockRange1},<:BlockSlice{BlockRange1}}}) =
435468
subblockbandwidths(parent(V))
436469

437470
function blockbandwidths(V::SubArray{<:Any,2,<:Any,<:Tuple{<:BlockSlice{BlockRange1},<:BlockSlice{Block1}}})

src/BlockSkylineMatrix.jl

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,47 @@ const BlockBandedMatrix{T} = BlockSkylineMatrix{T, Vector{T}, BlockBandedSizes}
136136
_BlockSkylineMatrix(Vector{T}(undef, bb_numentries(block_sizes)), block_sizes)
137137

138138
"""
139-
BlockSkylineMatrix{T,LL,UU}(undef, (rows, cols), (l::LL, u::UU))
139+
BlockSkylineMatrix{T,LL,UU}(M::Union{UndefInitializer,UniformScaling,AbstractMatrix},
140+
rows, cols, (l::LL, u::UU))
140141
141-
returns an undef `sum(rows)`×`sum(cols)` block-banded matrix `A`
142-
of type `T` with block-bandwidths `(l,u)` and where `A[Block(K,J)]`
143-
is a `Matrix{T}` of size `rows[K]`×`cols[J]`.
142+
returns a `sum(rows)`×`sum(cols)` block-banded matrix `A` of type `T`
143+
with block-bandwidths `(l,u)` and where `A[Block(K,J)]` is a
144+
`Matrix{T}` of size `rows[K]`×`cols[J]`.
144145
145146
`(l,u)` may be integers for constant bandwidths or integer vectors of
146147
lengths `rows` and `cols`, respectively, for ragged bands.
148+
149+
# Examples
150+
151+
```jldoctest
152+
julia> BlockSkylineMatrix(I, [2,3,4], [1,2,3], ([2,0,1],[1,1,1]))
153+
3×3-blocked 9×6 BlockSkylineMatrix{Bool,Array{Bool,1},BlockBandedMatrices.BlockSkylineSizes{Tuple{BlockArrays.BlockedUnitRange{Array{Int64,1}},BlockArrays.BlockedUnitRange{Array{Int64,1}}},Array{Int64,1},Array{Int64,1},BandedMatrices.BandedMatrix{Int64,Array{Int64,2},Base.OneTo{Int64}},Array{Int64,1}}}:
154+
1 │ 0 0 │ ⋅ ⋅ ⋅
155+
0 │ 1 0 │ ⋅ ⋅ ⋅
156+
───┼────────┼─────────
157+
0 │ 0 1 │ 0 0 0
158+
0 │ 0 0 │ 1 0 0
159+
0 │ 0 0 │ 0 1 0
160+
───┼────────┼─────────
161+
0 │ ⋅ ⋅ │ 0 0 1
162+
0 │ ⋅ ⋅ │ 0 0 0
163+
0 │ ⋅ ⋅ │ 0 0 0
164+
0 │ ⋅ ⋅ │ 0 0 0
165+
166+
julia> BlockSkylineMatrix(Ones(9,6), [2,3,4], [1,2,3], ([2,0,1],[1,1,1]))
167+
3×3-blocked 9×6 BlockSkylineMatrix{Float64,Array{Float64,1},BlockBandedMatrices.BlockSkylineSizes{Tuple{BlockArrays.BlockedUnitRange{Array{Int64,1}},BlockArrays.BlockedUnitRange{Array{Int64,1}}},Array{Int64,1},Array{Int64,1},BandedMatrices.BandedMatrix{Int64,Array{Int64,2},Base.OneTo{Int64}},Array{Int64,1}}}:
168+
1.0 │ 1.0 1.0 │ ⋅ ⋅ ⋅
169+
1.0 │ 1.0 1.0 │ ⋅ ⋅ ⋅
170+
─────┼────────────┼───────────────
171+
1.0 │ 1.0 1.0 │ 1.0 1.0 1.0
172+
1.0 │ 1.0 1.0 │ 1.0 1.0 1.0
173+
1.0 │ 1.0 1.0 │ 1.0 1.0 1.0
174+
─────┼────────────┼───────────────
175+
1.0 │ ⋅ ⋅ │ 1.0 1.0 1.0
176+
1.0 │ ⋅ ⋅ │ 1.0 1.0 1.0
177+
1.0 │ ⋅ ⋅ │ 1.0 1.0 1.0
178+
1.0 │ ⋅ ⋅ │ 1.0 1.0 1.0
179+
```
147180
"""
148181
BlockSkylineMatrix
149182

0 commit comments

Comments
 (0)