Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BlockBandedMatrices"
uuid = "ffab5731-97b5-5995-9138-79e8c1846df0"
version = "0.13.7"
version = "0.13.8"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
8 changes: 7 additions & 1 deletion src/BandedBlockBandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,10 +514,16 @@ function getindex(A::BandedBlockBandedMatrix{T}, KR::BlockRange{1}, JR::BlockRan
_BandedBlockBandedMatrix(A.data[:,JR], axes(axes(A,1)[KR],1), (l-sh, u+sh), subblockbandwidths(A))
end

@inline function bandwidths(V::SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice1,BlockSlice1}}) where T
@inline bandwidths(V::SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice1,BlockSlice1}}) where T = _block_bandwidths(MemoryLayout(parent(V)), V)

@inline function _blockbanded_block_bandwidths(V)
inblockbands(V) && return subblockbandwidths(parent(V))
(-720,-720)
end
@inline _block_bandwidths(_, V) = _blockbanded_block_bandwidths(V)
@inline _block_bandwidths(::DiagonalLayout, V) = _blockbanded_block_bandwidths(V)
# a block of a banded matrix is banded with the bandwidths shifted by the offset of the block from the diagonal
@inline _block_bandwidths(::AbstractBandedLayout, V) = min.(size(V) .- 1, bandwidths(parent(V)) .+ (-1,1) .* bandshift(V))

function bandwidths(V::SubArray{T,2,<:AbstractMatrix,<:Tuple{BlockSlice{<:BlockIndexRange1},BlockSlice{<:BlockIndexRange1}}}) where T
B = parentblock(V)
Expand Down
8 changes: 8 additions & 0 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ Base.size(F::FiniteDifference) = (F.n,F.n)
@test Q isa BandedMatrix
@test blockrowsupport(Q,Block(1)) == Block.(2:2)

@test bandwidths(view(B, Block(2), Block(1))) == (1,0)
@test all(B[Block(K,J)] == Matrix(B)[a[Block(K)], a[Block(J)]] for K=1:5, J=1:5)

# blocks of a banded matrix with blocked axes, including blocks where the bandwidths are shifted
B = _BandedMatrix(BlockedArray(randn(5,6), (Base.OneTo(5), blockedrange(1:3))), blockedrange(1:2), 2, 2)
@test bandwidths(view(B, Block(2), Block(3))) == (1,0)
@test all(B[Block(K,J)] == Matrix(B)[axes(B,1)[Block(K)], axes(B,2)[Block(J)]] for K=1:2, J=1:3)

@testset "constant blocks" begin
a = blockedrange(Fill(2,5))
Q = Eye((a,))[:,Block(2)]
Expand Down
Loading