Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support general backends for BlockArray #76

Merged
merged 17 commits into from
Mar 14, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify show
dlfivefifty committed Mar 9, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 24dc0f0e5d5ad003597fc4b47ff7370b096562f4
6 changes: 6 additions & 0 deletions src/abstractblockarray.jl
Original file line number Diff line number Diff line change
@@ -23,6 +23,12 @@ const AbstractBlockVecOrMat{T} = Union{AbstractBlockMatrix{T}, AbstractBlockVect

block2string(b, s) = string(join(map(string,b), '×'), "-blocked ", Base.dims2string(s))
Base.summary(a::AbstractBlockArray) = string(block2string(nblocks(a), size(a)), " ", typeof(a))
_show_typeof(io, a) = show(io, typeof(a))
function Base.summary(io::IO, a::AbstractBlockArray)
print(io, block2string(nblocks(a), size(a)))
print(io, ' ')
_show_typeof(io, a)
end
Base.similar(block_array::AbstractBlockArray{T}) where {T} = similar(block_array, T)
Base.IndexStyle(::Type{<:AbstractBlockArray}) = IndexCartesian()

9 changes: 9 additions & 0 deletions src/show.jl
Original file line number Diff line number Diff line change
@@ -79,3 +79,12 @@ Base.print_matrix_row(io::IO,
X::AbstractBlockVecOrMat, A::Vector,
i::Integer, cols::AbstractVector, sep::AbstractString) =
_blockarray_print_matrix_row(io, X, A, i, cols, sep)

function _show_typeof(io::IO, a::BlockArray{T,N,Array{Array{T,N},N},BlockSizes{2,Vector{Int}}}) where {T,N}
Base.show_type_name(io, typeof(a).name)
print(io, '{')
show(io, T)
print(io, ',')
show(io, N)
print(io, '}')
end
4 changes: 2 additions & 2 deletions test/test_blockarrays.jl
Original file line number Diff line number Diff line change
@@ -278,10 +278,10 @@ end

replstrmime(x) = stringmime("text/plain", x)
@testset "replstring" begin
@test replstrmime(BlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])) == "4×4 BlockArray{Int64,2,Array{Array{Int64,2},2},BlockSizes{2,Array{Int64,1}}}:\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
@test replstrmime(BlockArray(collect(reshape(1:16, 4, 4)), [1,3], [2,2])) == "2×2-blocked 4×4 BlockArray{Int64,2}:\n 1 5 │ 9 13\n ──────┼────────\n 2 6 │ 10 14\n 3 7 │ 11 15\n 4 8 │ 12 16"
design = zeros(Int16,6,9);
A = BlockArray(design,[6],[4,5])
@test replstrmime(A) == "6×9 BlockArray{Int16,2,Array{Array{Int16,2},2},BlockSizes{2,Array{Int64,1}}}:\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
@test replstrmime(A) == "1×2-blocked 6×9 BlockArray{Int16,2}:\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0\n 0 0 0 0 │ 0 0 0 0 0"
end

@testset "AbstractVector{Int} blocks" begin