Skip to content

Commit 0f78935

Browse files
authored
BlockDiagonal (#48)
* BlockDiagonal * Update Project.toml * bandedata for PseudoBlockMatrix * Update Project.toml * Update test_misc.jl
1 parent d16aa22 commit 0f78935

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1919
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2020

2121
[compat]
22-
BandedMatrices = "0.12, 0.13"
22+
BandedMatrices = "0.13"
2323
BlockArrays = "0.10"
24-
FillArrays = "0.7, 0.8"
25-
LazyArrays = "0.12"
26-
MatrixFactorizations = "0.1, 0.2"
24+
FillArrays = "0.8"
25+
LazyArrays = "0.13"
26+
MatrixFactorizations = "0.2"
2727
julia = "1"

src/interfaceimpl.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ function blockbandwidths(P::PseudoBlockMatrix{<:Any,<:Diagonal})
1212
cumulsizes(bs)[1] == cumulsizes(bs)[2] || throw(DimensionMismatch())
1313
(0,0)
1414
end
15+
16+
bandeddata(P::PseudoBlockMatrix) = bandeddata(P.blocks)
1517
bandwidths(P::PseudoBlockMatrix) = bandwidths(P.blocks)
1618

1719
BroadcastStyle(::Type{<:SubArray{<:Any,2,<:PseudoBlockMatrix{<:Any,<:Diagonal},
@@ -38,6 +40,19 @@ BroadcastStyle(::Type{<:SubKron{<:Any,<:Any,B,Block1,Block1}}) where B =
3840
subblockbandwidths(parent(V))
3941

4042

43+
const BlockDiagonal{T,VT<:Matrix{T}} = BlockMatrix{T,<:Diagonal{VT}}
44+
45+
BlockDiagonal(A) = mortar(Diagonal(A))
46+
47+
function sizes_from_blocks(A::Diagonal, _)
48+
# for k = 1:length(A.du)
49+
# size(A.du[k],1) == sz[1][k] || throw(ArgumentError("block sizes of upper diagonal inconsisent with diagonal"))
50+
# size(A.du[k],2) == sz[2][k+1] || throw(ArgumentError("block sizes of upper diagonal inconsisent with diagonal"))
51+
# size(A.dl[k],1) == sz[1][k+1] || throw(ArgumentError("block sizes of lower diagonal inconsisent with diagonal"))
52+
# size(A.dl[k],2) == sz[2][k] || throw(ArgumentError("block sizes of lower diagonal inconsisent with diagonal"))
53+
# end
54+
BlockSizes(size.(A.diag, 1), size.(A.diag,2))
55+
end
4156

4257

4358
# Block Tridiagonal
@@ -83,6 +98,13 @@ for op in (:-, :+)
8398
end
8499
end
85100

101+
function replace_in_print_matrix(A::BlockDiagonal, i::Integer, j::Integer, s::AbstractString)
102+
bi = global2blockindex(A.block_sizes, (i, j))
103+
I,J = bi.I
104+
i,j = bi.α
105+
J-I == 0 ? s : Base.replace_with_centered_mark(s)
106+
end
107+
86108
function replace_in_print_matrix(A::BlockTridiagonal, i::Integer, j::Integer, s::AbstractString)
87109
bi = global2blockindex(A.block_sizes, (i, j))
88110
I,J = bi.I

test/test_misc.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using LazyArrays, BlockBandedMatrices, BandedMatrices, BlockArrays, LinearAlgebra, Test
22
import Base: getindex, size
3-
import BandedMatrices: bandwidths, AbstractBandedMatrix, BandedStyle
3+
import BandedMatrices: bandwidths, AbstractBandedMatrix, BandedStyle, bandeddata, BandedColumns
44
import BlockArrays: blocksizes, BlockSizes
5+
import LazyArrays: DenseColumnMajor, DiagonalLayout
56

67
struct FiniteDifference{T} <: AbstractBandedMatrix{T}
78
n::Int
@@ -68,10 +69,15 @@ size(F::FiniteDifference) = (F.n,F.n)
6869

6970
PD = PseudoBlockArray(D, blocksizes(D_xx).block_sizes)
7071
@test blockbandwidths(PD) == bandwidths(PD) == (0,0)
72+
@test MemoryLayout(typeof(PD)) isa DiagonalLayout{DenseColumnMajor}
73+
@test bandeddata(PD) == bandeddata(D)
7174

7275
V = view(PD, Block(1,1))
7376
@test bandwidths(V) == (0,0)
7477
@test Broadcast.BroadcastStyle(typeof(V)) == BandedStyle()
78+
@test MemoryLayout(typeof(V)) isa BandedColumns{DenseColumnMajor}
79+
@test bandeddata(V) == bandeddata(PD)[:,1:n]
80+
@test BandedMatrix(V) == V
7581

7682
@test D_xx + D isa BandedBlockBandedMatrix
7783
@test blockbandwidths(D_xx + D) == blockbandwidths(D_xx)

0 commit comments

Comments
 (0)