Skip to content

Commit fe74053

Browse files
authored
Support Diagonal(::AbstractBlockVector) (#151)
* Support Diagonal(::AbstractBlockVector) * Update blockarrayinterface.jl * fix tests * Update test_blockarrayinterface.jl
1 parent ec072b0 commit fe74053

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockArrays"
22
uuid = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
3-
version = "0.14.1"
3+
version = "0.14.2"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/BlockArrays.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ include("blockarray.jl")
4848
include("pseudo_blockarray.jl")
4949
include("views.jl")
5050
include("blocks.jl")
51-
include("blockarrayinterface.jl")
51+
5252
include("blockbroadcast.jl")
5353
include("blocklinalg.jl")
5454
include("blockproduct.jl")
5555
include("show.jl")
5656
include("blockreduce.jl")
5757
include("blockdeque.jl")
58+
include("blockarrayinterface.jl")
5859

5960
@deprecate getblock(A::AbstractBlockArray{T,N}, I::Vararg{Integer, N}) where {T,N} view(A, Block(I))
6061
@deprecate getblock!(X, A::AbstractBlockArray{T,N}, I::Vararg{Integer, N}) where {T,N} copyto!(X, view(A, Block(I)))

src/blockarrayinterface.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ axes(A::HermOrSym{<:Any,<:AbstractBlockMatrix}) = _sym_axes(A)
1111
axes(A::HermOrSym{<:Any,<:SubArray{<:Any,2,<:AbstractBlockMatrix}}) = _sym_axes(A)
1212
axes(A::AbstractTriangular{<:Any,<:AbstractBlockMatrix}) = axes(parent(A))
1313
axes(A::AbstractTriangular{<:Any,<:SubArray{<:Any,2,<:AbstractBlockMatrix}}) = axes(parent(A))
14+
function axes(D::Diagonal{<:Any,<:AbstractBlockVector})
15+
a = axes(parent(D),1)
16+
(a,a)
17+
end
18+
ArrayLayouts.diagonallayout(lay::AbstractBlockLayout) = DiagonalLayout{typeof(lay)}()
1419

1520
blocksize(A::AbstractTriangular) = blocksize(parent(A))
1621
blocksize(A::AbstractTriangular, i::Int) = blocksize(parent(A), i)

test/test_blockarrayinterface.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BlockArrays, LinearAlgebra, FillArrays, Base64, Test
22

3+
# avoid fast-paths for view
34
bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
45

56
@testset "Array block interface" begin
@@ -103,6 +104,13 @@ end
103104
@test A[Block(1,2)] == [0 0]
104105
@test_throws BlockBoundsError A[Block(1,3)]
105106
@test A == [1 2 0 0; 0 0 1 2]
107+
108+
N = 3
109+
D = Diagonal(mortar(Fill.(-(0:N)-(0:N).^2, 1:2:2N+1)))
110+
@test axes(D) isa NTuple{2,BlockedUnitRange}
111+
@test blockisequal(axes(D,1), axes(parent(D),1))
112+
@test D == Diagonal(Vector(parent(D)))
113+
@test MemoryLayout(D) isa BlockArrays.DiagonalLayout{<:BlockArrays.BlockLayout}
106114
end
107115

108116
@testset "non-standard block axes" begin

0 commit comments

Comments
 (0)