Skip to content

Commit 5344b37

Browse files
authored
Support block banded cholesky (#130)
* Support block banded cholesky * Update test_linalg.jl * v0.11.7
1 parent a77af6f commit 5344b37

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

Project.toml

Lines changed: 5 additions & 5 deletions
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.11.6"
3+
version = "0.11.7"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -13,11 +13,11 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1313
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1414

1515
[compat]
16-
ArrayLayouts = "0.8.2"
17-
BandedMatrices = "0.16.8, 0.17"
18-
BlockArrays = "0.16.16"
16+
ArrayLayouts = "0.8.7"
17+
BandedMatrices = "0.17"
18+
BlockArrays = "0.16.18"
1919
FillArrays = "0.13"
20-
MatrixFactorizations = "0.8.5, 0.9"
20+
MatrixFactorizations = "0.9"
2121
julia = "1.6"
2222

2323
[extras]

src/BlockBandedMatrices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import BlockArrays: blocksize, blockcheckbounds, BlockedUnitRange, blockisequal,
3333
Block, BlockSlice, unblock, block, blockindex,
3434
_blocklengths2blocklasts, BlockIndexRange, sizes_from_blocks, BlockSlice1,
3535
blockcolsupport, blockrowsupport, blockcolstart, blockcolstop, blockrowstart, blockrowstop,
36-
AbstractBlockLayout, BlockLayout, blocks, hasmatchingblocks, BlockStyle, BlockSlices
36+
AbstractBlockLayout, BlockLayout, blocks, hasmatchingblocks, BlockStyle, BlockSlices, _blockkron
3737

3838
import BandedMatrices: isbanded, bandwidths, bandwidth, banded_getindex, colrange,
3939
inbands_setindex!, inbands_getindex, banded_setindex!,

src/interfaceimpl.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,17 @@ end
164164

165165
# ambiguity
166166
sub_materialize(::AbstractBandedLayout, V, ::Tuple{BlockedUnitRange,Base.OneTo{Int}}) = BandedMatrix(V)
167-
sub_materialize(::AbstractBandedLayout, V, ::Tuple{Base.OneTo{Int},BlockedUnitRange}) = BandedMatrix(V)
167+
sub_materialize(::AbstractBandedLayout, V, ::Tuple{Base.OneTo{Int},BlockedUnitRange}) = BandedMatrix(V)
168+
169+
170+
171+
#####
172+
# BlockKron
173+
#####
174+
175+
isblockbanded(K::BlockKron) = isbanded(first(K.args))
176+
isbandedblockbanded(K::BlockKron) = all(isbanded, K.args)
177+
blockbandwidths(K::BlockKron) = bandwidths(first(K.args))
178+
subblockbandwidths(K::BlockKron) = bandwidths(last(K.args))
179+
180+
_blockkron(::Tuple{Vararg{AbstractBandedLayout}}, A) = BandedBlockBandedMatrix(BlockKron(A...))

src/linalg.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,11 @@ strides(V::SubBlockSkylineMatrix{T,LL,UU,BlockIndexRange1,BlockIndexRange1}) whe
145145
(1,parent(V).block_sizes.block_strides[Int(parentindices(V)[2].block.block)])
146146

147147
MemoryLayout(V::SubBlockSkylineMatrix{T,LL,UU,BlockIndexRange1,BlockIndexRange1}) where {T,LL,UU} = ColumnMajor()
148+
149+
150+
151+
###
152+
# cholesky
153+
##
154+
155+
ArrayLayouts._cholesky(::AbstractBandedBlockBandedLayout, axes, A::Symmetric, piv::ArrayLayouts.CNoPivot=ArrayLayouts.CNoPivot(); check::Bool = true) = cholesky!(Symmetric(BlockBandedMatrix(parent(A)), Symbol(A.uplo)), piv; check = check)

test/test_linalg.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,13 @@ end
175175
B.data .= randn.()
176176
@test A*B Matrix(A)*Matrix(B)
177177
end
178+
179+
180+
@testset "Cholesky" begin
181+
n = 5
182+
= SymTridiagonal(fill(2.0,n), -ones(n-1))
183+
Δ = blockkron(D²,I(n)) + blockkron(I(n),D²)
184+
@test Δ isa BandedBlockBandedMatrix
185+
@test cholesky(Symmetric(Δ)).U cholesky(Matrix(Δ)).U
186+
@test cholesky(Symmetric(Δ,:L)).U cholesky(Matrix(Δ)).U
187+
end

0 commit comments

Comments
 (0)