Skip to content

Support Symmetric(::BandedBlockBandedMatrix) #128

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
Apr 20, 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
4 changes: 2 additions & 2 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.4"
version = "0.11.5"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand All @@ -15,7 +15,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
[compat]
ArrayLayouts = "0.8.2"
BandedMatrices = "0.16.8, 0.17"
BlockArrays = "0.16.6"
BlockArrays = "0.16.14"
FillArrays = "0.13"
MatrixFactorizations = "0.8.5, 0.9"
julia = "1.6"
Expand Down
15 changes: 15 additions & 0 deletions src/AbstractBlockBandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ conjlayout(::Type{T}, ::BandedBlockBandedRows{Lay}) where {T<:Complex,Lay} = Ban
conjlayout(::Type{T}, ::BlockBandedColumns{Lay}) where {T<:Complex,Lay} = BlockBandedColumns{typeof(conjlayout(T,Lay))}()
conjlayout(::Type{T}, ::BlockBandedRows{Lay}) where {T<:Complex,Lay} = BlockBandedRows{typeof(conjlayout(T,Lay))}()

symmetriclayout(::AbstractBandedBlockBandedLayout) = BandedBlockBandedLayout()
hermitianlayout(_, ::AbstractBandedBlockBandedLayout) = BandedBlockBandedLayout()

function blockbandwidths(S::HermOrSym)
l, u = blockbandwidths(parent(S))
if S.uplo == 'U'
(u, u)
else
(l, l)
end
end
function subblockbandwidths(S::HermOrSym)
m = max(subblockbandwidths(parent(S))...)
(m,m)
end

# AbstractBandedMatrix must implement

Expand Down
2 changes: 1 addition & 1 deletion src/BlockBandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import ArrayLayouts: BlasMatLmulVec, MatLmulVec, MatLmulMat,
AbstractColumnMajor, DenseColumnMajor, ColumnMajor,
DiagonalLayout, MulAdd, mul, colsupport, rowsupport,
_qr, _factorize, _copyto!, zero!, layout_replace_in_print_matrix,
transposelayout, conjlayout
transposelayout, conjlayout, symmetriclayout, hermitianlayout

import BlockArrays: blocksize, blockcheckbounds, BlockedUnitRange, blockisequal, DefaultBlockAxis,
Block, BlockSlice, unblock, block, blockindex,
Expand Down
22 changes: 22 additions & 0 deletions test/test_bandedblockbanded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,28 @@ import ArrayLayouts: RangeCumsum
@test convert(AbstractArray{Float64}, A) == convert(AbstractMatrix{Float64}, A) == A
@test convert(AbstractArray{Int}, A) ≡ convert(AbstractMatrix{Int}, A) ≡ A
end

@testset "Symmetric" begin
l, u = 2, 1
λ, μ = 2, 1
N = M = 4
cols = rows = 1:N
data = reshape(collect(1:(λ+μ+1)*(l+u+1)*sum(cols)), ((λ + μ + 1) * (l + u + 1), sum(cols)))
A = _BandedBlockBandedMatrix(data, rows, cols, (l, u), (λ, μ))

@test blockbandwidths(Hermitian(A)) == blockbandwidths(Symmetric(A)) == (1,1)
@test blockbandwidths(Hermitian(A,:L)) == blockbandwidths(Symmetric(A,:L)) == (2,2)
@test subblockbandwidths(Hermitian(A)) == subblockbandwidths(Symmetric(A)) == (2,2)
@test subblockbandwidths(Hermitian(A,:L)) == subblockbandwidths(Symmetric(A,:L)) == (2,2)

@test BandedBlockBandedMatrix(Symmetric(A)) == Symmetric(Matrix(A))
@test BandedBlockBandedMatrix(Symmetric(A,:L)) == Symmetric(Matrix(A),:L)
@test BandedBlockBandedMatrix(Hermitian(A)) == Hermitian(Matrix(A))
@test BandedBlockBandedMatrix(Hermitian(A,:L)) == Hermitian(Matrix(A),:L)

@test Symmetric(A)[Block.(1:3),Block.(1:3)] isa BandedBlockBandedMatrix
@test Hermitian(A)[Block.(1:3),Block.(1:3)] isa BandedBlockBandedMatrix
end
end

if false # turned off since tests have check-bounds=yes
Expand Down
12 changes: 6 additions & 6 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ end
@testset "Block-BandedMatrix" begin
a = blockedrange(1:5)
B = _BandedMatrix(PseudoBlockArray(randn(5,length(a)),(Base.OneTo(5),a)), a, 3, 1)
@test blockcolsupport(B,Block(1)) == Block.(1:3)
@test blockcolsupport(B,Block(3)) == Block.(2:4)
@test blockrowsupport(B,Block(1)) == Block.(1:2)
@test blockrowsupport(B,Block(4)) == Block.(3:5)
@test blockcolsupport(B,1) == Block.(1:3)
@test blockcolsupport(B,3) == Block.(2:4)
@test blockrowsupport(B,1) == Block.(1:2)
@test blockrowsupport(B,4) == Block.(3:5)

Q = Eye((a,))[:,Block(2)]
@test Q isa BandedMatrix
@test blockcolsupport(Q,Block(1)) == Block.(2:2)
@test blockcolsupport(Q,1) == Block.(2:2)

Q = Eye((a,))[Block(2),:]
@test Q isa BandedMatrix
@test blockrowsupport(Q,Block(1)) == Block.(2:2)
@test blockrowsupport(Q,1) == Block.(2:2)

@testset "constant blocks" begin
a = blockedrange(Fill(2,5))
Expand Down