Skip to content

Support block banded cholesky #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2022
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
10 changes: 5 additions & 5 deletions 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.11.6"
version = "0.11.7"

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

[compat]
ArrayLayouts = "0.8.2"
BandedMatrices = "0.16.8, 0.17"
BlockArrays = "0.16.16"
ArrayLayouts = "0.8.7"
BandedMatrices = "0.17"
BlockArrays = "0.16.18"
FillArrays = "0.13"
MatrixFactorizations = "0.8.5, 0.9"
MatrixFactorizations = "0.9"
julia = "1.6"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion src/BlockBandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import BlockArrays: blocksize, blockcheckbounds, BlockedUnitRange, blockisequal,
Block, BlockSlice, unblock, block, blockindex,
_blocklengths2blocklasts, BlockIndexRange, sizes_from_blocks, BlockSlice1,
blockcolsupport, blockrowsupport, blockcolstart, blockcolstop, blockrowstart, blockrowstop,
AbstractBlockLayout, BlockLayout, blocks, hasmatchingblocks, BlockStyle, BlockSlices
AbstractBlockLayout, BlockLayout, blocks, hasmatchingblocks, BlockStyle, BlockSlices, _blockkron

import BandedMatrices: isbanded, bandwidths, bandwidth, banded_getindex, colrange,
inbands_setindex!, inbands_getindex, banded_setindex!,
Expand Down
15 changes: 14 additions & 1 deletion src/interfaceimpl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,17 @@ end

# ambiguity
sub_materialize(::AbstractBandedLayout, V, ::Tuple{BlockedUnitRange,Base.OneTo{Int}}) = BandedMatrix(V)
sub_materialize(::AbstractBandedLayout, V, ::Tuple{Base.OneTo{Int},BlockedUnitRange}) = BandedMatrix(V)
sub_materialize(::AbstractBandedLayout, V, ::Tuple{Base.OneTo{Int},BlockedUnitRange}) = BandedMatrix(V)



#####
# BlockKron
#####

isblockbanded(K::BlockKron) = isbanded(first(K.args))
isbandedblockbanded(K::BlockKron) = all(isbanded, K.args)
blockbandwidths(K::BlockKron) = bandwidths(first(K.args))
subblockbandwidths(K::BlockKron) = bandwidths(last(K.args))

_blockkron(::Tuple{Vararg{AbstractBandedLayout}}, A) = BandedBlockBandedMatrix(BlockKron(A...))
8 changes: 8 additions & 0 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,11 @@ strides(V::SubBlockSkylineMatrix{T,LL,UU,BlockIndexRange1,BlockIndexRange1}) whe
(1,parent(V).block_sizes.block_strides[Int(parentindices(V)[2].block.block)])

MemoryLayout(V::SubBlockSkylineMatrix{T,LL,UU,BlockIndexRange1,BlockIndexRange1}) where {T,LL,UU} = ColumnMajor()



###
# cholesky
##

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)
10 changes: 10 additions & 0 deletions test/test_linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,13 @@ end
B.data .= randn.()
@test A*B ≈ Matrix(A)*Matrix(B)
end


@testset "Cholesky" begin
n = 5
D² = SymTridiagonal(fill(2.0,n), -ones(n-1))
Δ = blockkron(D²,I(n)) + blockkron(I(n),D²)
@test Δ isa BandedBlockBandedMatrix
@test cholesky(Symmetric(Δ)).U ≈ cholesky(Matrix(Δ)).U
@test cholesky(Symmetric(Δ,:L)).U ≈ cholesky(Matrix(Δ)).U
end