Skip to content

Commit 7f71b9c

Browse files
authored
Support Symmetric(::BandedBlockBandedMatrix) (#128)
* Support Symmetric(::BandedBlockBandedMatrix) * Revert "Update test_misc.jl" This reverts commit 074293b. * Fix HermitianLayout
1 parent 074293b commit 7f71b9c

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

Project.toml

Lines changed: 2 additions & 2 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.4"
3+
version = "0.11.5"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -15,7 +15,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1515
[compat]
1616
ArrayLayouts = "0.8.2"
1717
BandedMatrices = "0.16.8, 0.17"
18-
BlockArrays = "0.16.6"
18+
BlockArrays = "0.16.14"
1919
FillArrays = "0.13"
2020
MatrixFactorizations = "0.8.5, 0.9"
2121
julia = "1.6"

src/AbstractBlockBandedMatrix.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ conjlayout(::Type{T}, ::BandedBlockBandedRows{Lay}) where {T<:Complex,Lay} = Ban
3939
conjlayout(::Type{T}, ::BlockBandedColumns{Lay}) where {T<:Complex,Lay} = BlockBandedColumns{typeof(conjlayout(T,Lay))}()
4040
conjlayout(::Type{T}, ::BlockBandedRows{Lay}) where {T<:Complex,Lay} = BlockBandedRows{typeof(conjlayout(T,Lay))}()
4141

42+
symmetriclayout(::AbstractBandedBlockBandedLayout) = BandedBlockBandedLayout()
43+
hermitianlayout(_, ::AbstractBandedBlockBandedLayout) = BandedBlockBandedLayout()
44+
45+
function blockbandwidths(S::HermOrSym)
46+
l, u = blockbandwidths(parent(S))
47+
if S.uplo == 'U'
48+
(u, u)
49+
else
50+
(l, l)
51+
end
52+
end
53+
function subblockbandwidths(S::HermOrSym)
54+
m = max(subblockbandwidths(parent(S))...)
55+
(m,m)
56+
end
4257

4358
# AbstractBandedMatrix must implement
4459

src/BlockBandedMatrices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import ArrayLayouts: BlasMatLmulVec, MatLmulVec, MatLmulMat,
2727
AbstractColumnMajor, DenseColumnMajor, ColumnMajor,
2828
DiagonalLayout, MulAdd, mul, colsupport, rowsupport,
2929
_qr, _factorize, _copyto!, zero!, layout_replace_in_print_matrix,
30-
transposelayout, conjlayout
30+
transposelayout, conjlayout, symmetriclayout, hermitianlayout
3131

3232
import BlockArrays: blocksize, blockcheckbounds, BlockedUnitRange, blockisequal, DefaultBlockAxis,
3333
Block, BlockSlice, unblock, block, blockindex,

test/test_bandedblockbanded.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,28 @@ import ArrayLayouts: RangeCumsum
516516
@test convert(AbstractArray{Float64}, A) == convert(AbstractMatrix{Float64}, A) == A
517517
@test convert(AbstractArray{Int}, A) convert(AbstractMatrix{Int}, A) A
518518
end
519+
520+
@testset "Symmetric" begin
521+
l, u = 2, 1
522+
λ, μ = 2, 1
523+
N = M = 4
524+
cols = rows = 1:N
525+
data = reshape(collect(1:+μ+1)*(l+u+1)*sum(cols)), ((λ + μ + 1) * (l + u + 1), sum(cols)))
526+
A = _BandedBlockBandedMatrix(data, rows, cols, (l, u), (λ, μ))
527+
528+
@test blockbandwidths(Hermitian(A)) == blockbandwidths(Symmetric(A)) == (1,1)
529+
@test blockbandwidths(Hermitian(A,:L)) == blockbandwidths(Symmetric(A,:L)) == (2,2)
530+
@test subblockbandwidths(Hermitian(A)) == subblockbandwidths(Symmetric(A)) == (2,2)
531+
@test subblockbandwidths(Hermitian(A,:L)) == subblockbandwidths(Symmetric(A,:L)) == (2,2)
532+
533+
@test BandedBlockBandedMatrix(Symmetric(A)) == Symmetric(Matrix(A))
534+
@test BandedBlockBandedMatrix(Symmetric(A,:L)) == Symmetric(Matrix(A),:L)
535+
@test BandedBlockBandedMatrix(Hermitian(A)) == Hermitian(Matrix(A))
536+
@test BandedBlockBandedMatrix(Hermitian(A,:L)) == Hermitian(Matrix(A),:L)
537+
538+
@test Symmetric(A)[Block.(1:3),Block.(1:3)] isa BandedBlockBandedMatrix
539+
@test Hermitian(A)[Block.(1:3),Block.(1:3)] isa BandedBlockBandedMatrix
540+
end
519541
end
520542

521543
if false # turned off since tests have check-bounds=yes

test/test_misc.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,18 @@ end
160160
@testset "Block-BandedMatrix" begin
161161
a = blockedrange(1:5)
162162
B = _BandedMatrix(PseudoBlockArray(randn(5,length(a)),(Base.OneTo(5),a)), a, 3, 1)
163-
@test blockcolsupport(B,Block(1)) == Block.(1:3)
164-
@test blockcolsupport(B,Block(3)) == Block.(2:4)
165-
@test blockrowsupport(B,Block(1)) == Block.(1:2)
166-
@test blockrowsupport(B,Block(4)) == Block.(3:5)
163+
@test blockcolsupport(B,1) == Block.(1:3)
164+
@test blockcolsupport(B,3) == Block.(2:4)
165+
@test blockrowsupport(B,1) == Block.(1:2)
166+
@test blockrowsupport(B,4) == Block.(3:5)
167167

168168
Q = Eye((a,))[:,Block(2)]
169169
@test Q isa BandedMatrix
170-
@test blockcolsupport(Q,Block(1)) == Block.(2:2)
170+
@test blockcolsupport(Q,1) == Block.(2:2)
171171

172172
Q = Eye((a,))[Block(2),:]
173173
@test Q isa BandedMatrix
174-
@test blockrowsupport(Q,Block(1)) == Block.(2:2)
174+
@test blockrowsupport(Q,1) == Block.(2:2)
175175

176176
@testset "constant blocks" begin
177177
a = blockedrange(Fill(2,5))

0 commit comments

Comments
 (0)