Skip to content

Commit 478c345

Browse files
authored
blockcol/rowsupport for banded matrices (#117)
* blockcol/rowsupport for banded matrices * add sub_materialize
1 parent 86c5c61 commit 478c345

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockBandedMatrices"
22
uuid = "ffab5731-97b5-5995-9138-79e8c1846df0"
3-
version = "0.10.8"
3+
version = "0.10.9"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/interfaceimpl.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,24 @@ subblockbandwidths(::Zeros) = (-1,-1)
133133

134134
sublayout(::DiagonalLayout{L}, inds::Type{<:NTuple{2,BS}}) where {L,BS<:BlockSlice{<:BlockRange1}} = bandedblockbandedcolumns(sublayout(L(),Tuple{BS}))
135135
subblockbandwidths(::Diagonal) = (0,0)
136-
bandedblockbandeddata(D::Diagonal) = permutedims(D.diag)
136+
bandedblockbandeddata(D::Diagonal) = permutedims(D.diag)
137+
138+
###
139+
# Block-BandedMatrix
140+
###
141+
142+
function blockcolsupport(::AbstractBandedLayout, B, j)
143+
m,n = axes(B)
144+
cs = colsupport(B,n[Block.(j)])
145+
findblock(m,first(cs)):findblock(m,last(cs))
146+
end
147+
148+
function blockrowsupport(::AbstractBandedLayout, B, k)
149+
m,n = axes(B)
150+
rs = rowsupport(B,m[Block.(k)])
151+
findblock(n,first(rs)):findblock(n,last(rs))
152+
end
153+
154+
# ambiguity
155+
sub_materialize(::AbstractBandedLayout, V, ::Tuple{BlockedUnitRange,Base.OneTo{Int}}) = BandedMatrix(V)
156+
sub_materialize(::AbstractBandedLayout, V, ::Tuple{Base.OneTo{Int},BlockedUnitRange}) = BandedMatrix(V)

test/test_misc.jl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using ArrayLayouts, BlockBandedMatrices, BandedMatrices, BlockArrays, LinearAlgebra, Test
2-
import BlockBandedMatrices: AbstractBandedBlockBandedMatrix, block, blockindex
3-
import BandedMatrices: bandwidths, AbstractBandedMatrix, BandedStyle, bandeddata, BandedColumns
2+
import BlockBandedMatrices: AbstractBandedBlockBandedMatrix, block, blockindex, blockcolsupport, blockrowsupport
3+
import BandedMatrices: bandwidths, AbstractBandedMatrix, BandedStyle, bandeddata, BandedColumns, _BandedMatrix
44

55
struct MyBandedBlockBandedMatrix <: AbstractBandedBlockBandedMatrix{Float64}
66
A::BlockMatrix{Float64}
@@ -124,4 +124,21 @@ end
124124
@test blockbandwidths(D[Block.(1:2),Block.(2:3)]) == (1,-1)
125125
@test subblockbandwidths(D[Block.(1:2),Block.(2:3)]) == (0,0)
126126
end
127+
128+
@testset "Block-BandedMatrix" begin
129+
a = blockedrange(1:5)
130+
B = _BandedMatrix(PseudoBlockArray(randn(5,length(a)),(Base.OneTo(5),a)), a, 3, 1)
131+
@test blockcolsupport(B,1) == Block.(1:3)
132+
@test blockcolsupport(B,3) == Block.(2:4)
133+
@test blockrowsupport(B,1) == Block.(1:2)
134+
@test blockrowsupport(B,4) == Block.(3:5)
135+
136+
Q = Eye((a,))[:,Block(2)]
137+
@test Q isa BandedMatrix
138+
@test blockcolsupport(Q,1) == Block.(2:2)
139+
140+
Q = Eye((a,))[Block(2),:]
141+
@test Q isa BandedMatrix
142+
@test blockrowsupport(Q,1) == Block.(2:2)
143+
end
127144
end

0 commit comments

Comments
 (0)