Permalink
Browse files

have showcompact() show all digits when output is not limited

make show and repr correctly reproduce array element types, and
  the types of all elements

we still don't have a good repr() for sparse matrices or >2d
  • Loading branch information...
1 parent c8b0e61 commit 9979dfddfd671aa582768a8cc99677a426daac6d @JeffBezanson JeffBezanson committed Feb 23, 2014
Showing with 63 additions and 15 deletions.
  1. +4 −1 base/grisu.jl
  2. +1 −1 base/repl.jl
  3. +56 −11 base/show.jl
  4. +2 −2 base/sparse/sparsematrix.jl
View
@@ -118,7 +118,10 @@ show(io::IO, x::Float16) = _show(io, x, PRECISION, 4, true)
print(io::IO, x::Float32) = _show(io, x, SHORTEST_SINGLE, 0, false)
print(io::IO, x::Float16) = _show(io, x, PRECISION, 4, false)
-showcompact(io::IO, x::FloatingPoint) = _show(io, x, PRECISION, 6, false)
+showcompact(io::IO, x::Float64) =
+ (Base._limit_output::Bool) ? _show(io, x, PRECISION, 6, false) : _show(io, x, SHORTEST, 0, false)
+showcompact(io::IO, x::Float32) =
+ (Base._limit_output::Bool) ? _show(io, x, PRECISION, 6, false) : _show(io, x, SHORTEST_SINGLE, 0, false)
showcompact(io::IO, x::Float16) = _show(io, x, PRECISION, 4, false)
# normal:
View
@@ -18,7 +18,7 @@ function writemime(io::IO, ::MIME"text/plain", v::AbstractVector)
print(io, summary(v))
if !isempty(v)
println(io, ":")
- print_matrix(io, v)
+ with_output_limit(()->print_matrix(io, v))
end
end
end
View
@@ -118,7 +118,7 @@ function show(io::IO, l::LambdaStaticData)
print(io, ")")
end
-function show_delim_array(io::IO, itr::AbstractArray, op, delim, cl, delim_one)
+function show_delim_array(io::IO, itr::AbstractArray, op, delim, cl, delim_one, compact=false)
print(io, op)
newline = true
first = true
@@ -133,7 +133,7 @@ function show_delim_array(io::IO, itr::AbstractArray, op, delim, cl, delim_one)
x = itr[i]
multiline = isa(x,AbstractArray) && ndims(x)>1 && length(x)>0
newline && multiline && println(io)
- show(io, x)
+ compact ? showcompact(io, x) : show(io, x)
end
i += 1
if i > l
@@ -935,6 +935,35 @@ whos(pat::Regex) = whos(current_module(), pat)
# for internal use in showing arrays.
_limit_output = false
+function print_matrix_repr(io, X::AbstractArray)
+ e = eltype(X)
+ types = !isleaftype(e)
+ prefix = string(e)*"["
+ ind = " "^length(prefix)
+ print(io, prefix)
+ for i=1:size(X,1)
+ i > 1 && print(io, ind)
+ for j=1:size(X,2)
+ j > 1 && print(io, " ")
+ if !isassigned(X,i,j)
+ print(io, undef_ref_str)
+ else
+ el = X[i,j]
+ if types
+ show(io, el)
+ else
+ showcompact(io, el)
+ end
+ end
+ end
+ if i < size(X,1)
+ println(io)
+ else
+ print(io, "]")
+ end
+ end
+end
+
# NOTE: this is a possible, so-far-unexported function, providing control of
# array output. Not sure I want to do it this way.
showarray(X::AbstractArray; kw...) = showarray(STDOUT, X; kw...)
@@ -954,13 +983,21 @@ function showarray(io::IO, X::AbstractArray;
if !limit
rows = cols = typemax(Int)
end
- punct = repr ? ("[", " ", "]") : (" ", " ", "")
- if ndims(X)<=2
- print_matrix(io, X, rows, cols, punct...)
+ if repr
+ if ndims(X)<=2
+ print_matrix_repr(io, X)
+ else
+ show_nd(io, X, limit, print_matrix_repr, false)
+ end
else
- show_nd(io, X, limit,
- (io,slice)->print_matrix(io,slice,rows,cols,punct...),
- !repr)
+ punct = (" ", " ", "")
+ if ndims(X)<=2
+ print_matrix(io, X, rows, cols, punct...)
+ else
+ show_nd(io, X, limit,
+ (io,slice)->print_matrix(io,slice,rows,cols,punct...),
+ !repr)
+ end
end
end
end
@@ -1003,13 +1040,21 @@ function showlimited(io::IO, x)
end
function show_vector(io::IO, v, opn, cls)
+ e = eltype(v)
+ compact = false
+ if e !== Any
+ if isleaftype(e)
+ compact = true
+ end
+ print(io, e)
+ end
if _limit_output && length(v) > 20
- show_delim_array(io, sub(v,1:10), opn, ",", "", false)
+ show_delim_array(io, sub(v,1:10), opn, ",", "", false, compact)
print(io, " \u2026 ")
n = length(v)
- show_delim_array(io, sub(v,(n-9):n), "", ",", cls, false)
+ show_delim_array(io, sub(v,(n-9):n), "", ",", cls, false, compact)
else
- show_delim_array(io, v, opn, ",", cls, false)
+ show_delim_array(io, v, opn, ",", cls, false, compact)
end
end
@@ -27,8 +27,8 @@ function show(io::IO, S::SparseMatrixCSC)
sep = "\n\t"
for col = 1:S.n, k = S.colptr[col] : (S.colptr[col+1]-1)
if k < half_screen_rows || k > nfilled(S)-half_screen_rows
- print(io, sep, '[', rpad(S.rowval[k], pad), ", ", lpad(col, pad), "] = ",
- sprint(showcompact, S.nzval[k]))
+ print(io, sep, '[', rpad(S.rowval[k], pad), ", ", lpad(col, pad), "] = ")
+ showcompact(io, S.nzval[k])
elseif k == half_screen_rows
print(io, sep, '\u22ee')
end

0 comments on commit 9979dfd

Please sign in to comment.