Skip to content

Commit e442939

Browse files
committed
Prettier summary for Array{<:FixedPoint} using showarg
1 parent bc5506a commit e442939

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/FixedPointNumbers.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,15 @@ end
113113
const _log2_10 = 3.321928094887362
114114
showcompact(io::IO, x::FixedPoint{T,f}) where {T,f} = show(io, round(convert(Float64,x), ceil(Int,f/_log2_10)))
115115

116+
if VERSION >= v"0.7.0-DEV.1790"
117+
function Base.showarg(io::IO, a::Array{T}, toplevel) where {T<:FixedPoint}
118+
toplevel || print(io, "::")
119+
print(io, "Array{")
120+
showtype(io, T)
121+
print(io, ",$(ndims(a))}")
122+
toplevel && print(io, " with eltype ", T)
123+
end
124+
end
116125

117126
include("fixed.jl")
118127
include("normed.jl")

test/normed.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,9 @@ end
304304
# Overflow with Float16
305305
@test N0f16(Float16(1.0)) === N0f16(1.0)
306306
@test Float16(1.0) % N0f16 === N0f16(1.0)
307+
308+
if VERSION >= v"0.7.0-DEV.1790"
309+
a = N0f8[0.2, 0.4]
310+
@test summary(a) == "2-element Array{N0f8,1} with eltype FixedPointNumbers.Normed{UInt8,8}"
311+
@test summary(view(a, 1:2)) == "2-element view(::Array{N0f8,1}, 1:2) with eltype FixedPointNumbers.Normed{UInt8,8}"
312+
end

0 commit comments

Comments
 (0)