How to print array contents in v0.7 (Base.showarray in v0.7)


In v0.6 there is showarray, but it seems that it is changed in v0.7, how should I print some self-made type that implemented Array interface in v0.7?

julia> struct A{T, N} <: AbstractArray{T, N} end

julia>, ::MIME"text/plain", v::A) = print(io, "hello")

julia> A{Float64, 2}()


And for more details:


Thank you, but I mean in v0.6 if I implement getindex and size. I don’t need to rewrite a show function to print the array and I can use showarray to print the array without header.

struct MyArray{T, N} <: AbstractArray{T, N}
    data::Array{T, N}

import Base: getindex, size

size(x::MyArray) = size(
getindex(x::MyArray, index...) = getindex(, index...)

I just don’t want to rewrite how to print an multi-dimensional array…


What’s the problem on 0.7? I get this with your code:

julia> MyArray([1])
1-element MyArray{Int64,1}:

julia> MyArray([1 2])
1Ă—2 MyArray{Int64,2}:
 1  2


Yeah, but I don’t want the header, there was a keyword for Base.showarray to print only the content of the array without the header…


OK, so you didn’t tell us the whole story. Base.showarray was an internal function which isn’t supposed to be used from outside Base. You can have a look at Base.print_array on 0.7, but its name could change again in the future.


Ah… I see, thanks! But is it possible to print without header using exported functions?


I don’t think so. You could just remove the summary line manually. Maybe there should be an IOContext option to omit it.


This is what I went with in Rotations.jl:

(the !isa(X, RotMatrix) case is probably not interesting to you, but the rest is. Note that this still uses undocumented functionality from Base, just different undocumented functionality.


Sorry, I didn’t get what will the keyword :compat do here? And how do you keep your v0.6 version compatible? I notice that summary do not have summary(io, x) but only have summary(x) in v0.6? And it seems that Compat does not contain this function…


It’s :compact, not :compat. The 0.6 version is above this (this is in the else clause of a @static if VERSION < v"0.7-" statement).

I notice that summary do not have summary(io, x)

Yep, that looks like a mistake in the old code.


Thanks, this is quite helpful!


You can just use print(array) if you want very compact output, or witedlm if you want some delimited format.


Thanks, it is similar to showarray indeed. I’m just not familiar with IO part, will it print the header, if the io is re-direct to something similar to REPL? I would like my custom array have a custom header but with similar behavior with built-in Array, so my user won’t learn much.


Have you tried to simply define a custom summary method?


Oh, I see, I tried this, but it works fine in v0.6 but it won’t print my custom header in v0.7:

struct MyArray{T, N} <: AbstractArray{T, N}
    data::Array{T, N}

import Base: size, getindex

size(x::MyArray) = size(
getindex(x::MyArray, index...) = getindex(, index...)

import Base: show, summary

show(io::IO, x::MyArray) = show(io,

@static if VERSION < v"0.7-"
    summary(x::MyArray) = "hello"
    summary(io::IO, x::MyArray) = "hello"

in v0.6:

julia> MyArray(rand(2, 2))
 0.296337  0.719684
 0.231015  0.764015


julia> MyArray(rand(2, 2))
 0.18533   0.65715 
 0.376326  0.629767

summary(io::IO, x::MyArray) = "hello"

should be

summary(io::IO, x::MyArray) = print(io, "hello")
julia> MyArray(rand(2, 2))
 0.527634  0.101987
 0.452496  0.404595