Skip to content

Commit cfc75eb

Browse files
committed
Return a BandedMatrix from a view of a BandedBlockBandedMatrix
1 parent 629276d commit cfc75eb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/BandedBlockBandedMatrix.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ BandedBlockBandedMatrix{T,B}(m::Union{AbstractMatrix, UniformScaling},
167167
BandedBlockBandedMatrix{T}(m::Union{AbstractMatrix, UniformScaling},
168168
axes::NTuple{2,AbstractUnitRange{Int}},
169169
lu::NTuple{2,Int}, λμ::NTuple{2,Int}) where T =
170-
DefaultBandedBlockBandedMatrix{T}(m, axes, lu, λμ)
170+
BandedBlockBandedMatrix{T,BlockedMatrix{T,Matrix{T},typeof(_bbb_data_axes(axes[2],lu,λμ))},typeof(axes[1])}(m, axes, lu, λμ)
171171

172172
BandedBlockBandedMatrix{T,B,R}(m::Union{AbstractMatrix, UniformScaling},
173173
rdims::AbstractVector{Int}, cdims::AbstractVector{Int},
@@ -334,6 +334,22 @@ zeroblock(A::BandedBlockBandedMatrix, K::Int, J::Int) =
334334
Base.size(arr::BandedBlockBandedMatrix) =
335335
@inbounds return map(length,axes(arr))
336336

337+
@inline function inbands_viewblock(A::BandedBlockBandedMatrix, KJ::Block{2})
338+
l,u = blockbandwidths(A)
339+
K,J = KJ.n
340+
_BandedMatrix(view(A.data, Block(K-J+u+1, J)), length(axes(A,1)[Block(K)]), subblockbandwidths(A)...)
341+
end
342+
343+
@inline function viewblock(A::BandedBlockBandedMatrix, KJ::Block{2})
344+
@boundscheck checkbounds(A, KJ)
345+
K,J = KJ.n
346+
if -A.u K-J A.l
347+
inbands_viewblock(A, KJ)
348+
else
349+
_BandedMatrix(view(A.data, Block(1,1)), blocklengths(A,1)[Block(K)], (-40320,-40320))
350+
end
351+
end
352+
337353

338354
@inline function getindex(A::BandedBlockBandedMatrix{T}, i::Int, j::Int) where T
339355
@boundscheck checkbounds(A, i, j)

src/BlockBandedMatrices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import BlockArrays: AbstractBlockLayout, AbstractBlockedUnitRange, Block, BlockI
2424
_blockkron, _blocklengths2blocklasts, block,
2525
blockcheckbounds, blockcolstart, blockcolstop, blockcolsupport, blockindex, blockisequal,
2626
blockrowstart, blockrowstop, blockrowsupport, blocks, blocksize, checksquareblocks,
27-
hasmatchingblocks, sizes_from_blocks
27+
hasmatchingblocks, sizes_from_blocks, viewblock
2828

2929
import FillArrays: Fill, Ones, Zeros
3030

0 commit comments

Comments
 (0)