Skip to content

Commit 4a58c60

Browse files
committed
support mortar(::Matrix{Matrix})
1 parent 8e720a0 commit 4a58c60

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/blockarray.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ function _BlockArray(blocks::R, block_sizes::Vararg{AbstractVector{Int}, N}) whe
7676
return _BlockArray(blocks, BlockSizes(block_sizes...))
7777
end
7878

79+
function _BlockArray(blocks::R, block_sizes::BS) where {T, N, R<:AbstractArray{<:AbstractArray{V,N} where V,N}, BS<:AbstractBlockSizes{N}}
80+
_BlockArray(convert(AbstractArray{AbstractArray{mapreduce(eltype,promote_type,blocks),N},N}, blocks), block_sizes)
81+
end
82+
7983
const BlockMatrix{T, R <: AbstractMatrix{<:AbstractMatrix{T}}} = BlockArray{T, 2, R}
8084
const BlockVector{T, R <: AbstractVector{<:AbstractVector{T}}} = BlockArray{T, 1, R}
8185
const BlockVecOrMat{T, R} = Union{BlockMatrix{T, R}, BlockVector{T, R}}

test/test_blockarrays.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,4 +442,22 @@ end
442442
B = PseudoBlockArray(vcat(fill([1,2], N)...), BlockArrays.BlockSizes((1:2:2N+1,)))
443443
@test A == vcat(A.blocks...) == B
444444
@test A[Block(1)] == B[Block(1)] == [1,2]
445+
end
446+
447+
@testset "mixed blocks #92" begin
448+
A = BlockArray{Any}(undef_blocks, [1,2], [3,2])
449+
A.blocks[1,1] = fill(1.0,1,3)
450+
A.blocks[1,2] = fill(2,1,2)
451+
A.blocks[2,1] = fill(3//3,2,3)
452+
A.blocks[2,2] = fill(4.0f0,2,2)
453+
@test A[1,1] == 1.0
454+
@test A[2,1] == 1//1
455+
456+
B = Matrix{Matrix}(undef,2,2)
457+
B[1,1] = fill(1.0,1,3)
458+
B[1,2] = fill(2,1,2)
459+
B[2,1] = fill(3//3,2,3)
460+
B[2,2] = fill(4.0f0,2,2)
461+
@test mortar(B) == A
462+
@test mortar(B)[1,1] == 1.0
445463
end

0 commit comments

Comments
 (0)