Skip to content

Commit e828f4a

Browse files
authored
ensure that Array returns an Array (#283)
1 parent e679494 commit e828f4a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/blockarray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ Base.dataids(arr::BlockArray) = (dataids(arr.blocks)..., dataids(arr.axes)...)
420420
function _replace_in_print_matrix_inds(block_arr, i...)
421421
J = findblockindex.(axes(block_arr), i)
422422
blind = map(block, J)
423-
bl = block_arr[blind...]
423+
bl = @view block_arr[blind...]
424424
inds = map(blockindex, J)
425425
bl, inds
426426
end
@@ -453,11 +453,11 @@ end
453453
@generated function Base.Array(block_array::BlockArray{T, N, R}) where {T,N,R}
454454
# TODO: This will fail for empty block array
455455
return quote
456-
arr = similar(block_array.blocks[1], size(block_array)...)
456+
arr = Array{eltype(T)}(undef, size(block_array))
457457
@nloops $N i i->blockaxes(block_array,i) begin
458458
block_index = @ntuple $N i
459459
indices = getindex.(axes(block_array), block_index)
460-
arr[indices...] = block_array[block_index...]
460+
arr[indices...] = @view block_array[block_index...]
461461
end
462462

463463
return arr

test/test_blockarrays.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ end
7474
@test A == BlockArray(A, 1:3) == BlockArray{Int}(A, 1:3) ==
7575
BlockArray(A, (blockedrange(1:3),)) == BlockArray{Int}(A, (blockedrange(1:3),)) ==
7676
BlockArray{Float64}(A, 1:3)
77+
78+
#test that Array(::BlockArray) always returns an Array
79+
S = spzeros(2,1)
80+
B = mortar(fill(S,2,2))
81+
A = Array(B)
82+
@test A isa Matrix
7783
end
7884

7985
@testset "PseudoBlockArray constructors" begin

0 commit comments

Comments
 (0)