Skip to content

Commit 159d05f

Browse files
committed
tests pass
1 parent 0fc3234 commit 159d05f

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ BlockBandedMatricesSparseArraysExt = "SparseArrays"
1919
[compat]
2020
Aqua = "0.8"
2121
ArrayLayouts = "1"
22-
BandedMatrices = "1"
22+
BandedMatrices = "1.9.4"
2323
BlockArrays = "1"
2424
Documenter = "1"
2525
FillArrays = "1"

src/BandedBlockBandedMatrix.jl

+21-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct BandedBlockBandedMatrix{T, BLOCKS, RAXIS<:AbstractUnitRange{Int}} <: Abst
3939
end
4040
end
4141

42-
const DefaultBandedBlockBandedMatrix{T} = BandedBlockBandedMatrix{T, BlockedMatrix{T, Matrix{T}, NTuple{2,DefaultBlockAxis}}, DefaultBlockAxis}
42+
const DefaultBandedBlockBandedMatrix{T} = BandedBlockBandedMatrix{T, <:BlockedMatrix{T, Matrix{T}}}
4343

4444
@inline _BandedBlockBandedMatrix(data::AbstractMatrix, axes::NTuple{2,AbstractUnitRange{Int}}, lu::NTuple{2,Int}, λμ::NTuple{2,Int}) =
4545
_BandedBlockBandedMatrix(BlockedArray(data,(blockedrange(Fill(sum(λμ)+1,sum(lu)+1)),axes[2])), axes[1], lu, λμ)
@@ -340,14 +340,30 @@ Base.size(arr::BandedBlockBandedMatrix) =
340340
_BandedMatrix(view(A.data, Block(K-J+u+1, J)), length(axes(A,1)[Block(K)]), subblockbandwidths(A)...)
341341
end
342342

343+
@inline inbands_viewblock(A::BandedBlockBandedMatrix, K::Block{1}, J::Block{1}) = inbands_viewblock(A, Block(Int(K), Int(J)))
344+
345+
emptyview(A::BlockedMatrix, J) = view(A.blocks, 1:0, axes(A,2)[J])
346+
function emptyview(A, J)
347+
V = view(A, Block(1), J)
348+
view(V, 1:0, 1:size(V,2))
349+
end
350+
351+
@inline function outbands_viewblock(A::BandedBlockBandedMatrix, KJ::Block{2})
352+
l,u = blockbandwidths(A)
353+
K,J = KJ.n
354+
# Need to make an empty banded matrix in a type-stable way
355+
_BandedMatrix(emptyview(A.data, Block(J)), length(axes(A,1)[Block(K)]), -720,-720)
356+
end
357+
358+
359+
343360
@inline function viewblock(A::BandedBlockBandedMatrix, KJ::Block{2})
344-
@boundscheck checkbounds(A, KJ)
361+
@boundscheck blockcheckbounds(A, KJ)
345362
K,J = KJ.n
346363
if -A.u K-J A.l
347364
inbands_viewblock(A, KJ)
348365
else
349-
dat = view(A.data, Block(1,1))
350-
_BandedMatrix(dat, length(axes(A,1)[Block(K)]), size(dat,1)-1,0)
366+
outbands_viewblock(A, KJ)
351367
end
352368
end
353369

@@ -363,7 +379,7 @@ end
363379
@boundscheck checkbounds(A, i, j)
364380
BI,BJ = findblockindex.(axes(A), (i,j))
365381
if -A.l Int(block(BJ)-block(BI)) A.u
366-
V = view(A, block(BI),block(BJ))
382+
V = inbands_viewblock(A, block(BI),block(BJ))
367383
@inbounds V[blockindex(BI),blockindex(BJ)] = convert(T, v)::T
368384
elseif !iszero(v)
369385
throw(BandError(A))

0 commit comments

Comments
 (0)