-
Notifications
You must be signed in to change notification settings - Fork 33
Improve consistency in printing #189
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
Conversation
FYI julia> Float32[1/3 0.2]
1×2 Array{Float32,2}:
0.333333 0.2
julia> Float32[1/3, 0.2]
2-element Array{Float32,1}:
0.33333334
0.2
julia> AbstractFloat[Float16(1/3) Float32(1/3)]
1×2 Array{AbstractFloat,2}:
0.3333 0.333333
julia> AbstractFloat[Float16(1/3), Float32(1/3)]
2-element Array{AbstractFloat,1}:
Float16(0.3333)
0.33333334f0
|
Before julia> @benchmark FixedPointNumbers.showtype(io, N0f8) # Julia v1.4.2
BenchmarkTools.Trial:
memory estimate: 192 bytes
allocs estimate: 4
--------------
minimum time: 266.134 ns (0.00% GC)
median time: 276.998 ns (0.00% GC)
mean time: 341.150 ns (2.18% GC)
maximum time: 7.560 μs (92.47% GC)
--------------
samples: 10000
evals/sample: 313
julia> @benchmark FixedPointNumbers.showtype(io, N0f8) # Julia v1.6.0-DEV
BenchmarkTools.Trial:
memory estimate: 336 bytes
allocs estimate: 6
--------------
minimum time: 441.414 ns (0.00% GC)
median time: 466.667 ns (0.00% GC)
mean time: 573.091 ns (11.50% GC)
maximum time: 242.056 μs (99.73% GC)
--------------
samples: 10000
evals/sample: 198 After julia> @benchmark FixedPointNumbers.showtype(io, N0f8) # Julia v1.4.2
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 94.312 ns (0.00% GC)
median time: 136.266 ns (0.00% GC)
mean time: 130.076 ns (0.00% GC)
maximum time: 33.543 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 932
julia> @benchmark FixedPointNumbers.showtype(io, N0f8) # Julia v1.6.0-DEV
BenchmarkTools.Trial:
memory estimate: 0 bytes
allocs estimate: 0
--------------
minimum time: 139.721 ns (0.00% GC)
median time: 142.276 ns (0.00% GC)
mean time: 156.099 ns (0.00% GC)
maximum time: 63.378 μs (0.00% GC)
--------------
samples: 10000
evals/sample: 861 It's still slow but this PR (and upcoming changes in ColorTypes) can reduce the number of times where the type aliases are printed. Therefore, I will not optimize |
Codecov Report
@@ Coverage Diff @@
## master #189 +/- ##
==========================================
- Coverage 89.80% 89.74% -0.06%
==========================================
Files 6 6
Lines 461 478 +17
==========================================
+ Hits 414 429 +15
- Misses 47 49 +2
Continue to review full report at Codecov.
|
323db62
to
38cc0ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice change! Approved, small tweaks are optional.
src/FixedPointNumbers.jl
Outdated
function show(io::IO, x::FixedPoint{T,f}) where {T,f} | ||
compact = get(io, :compact, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compact = get(io, :compact, false) | |
compact = get(io, :compact, false)::Bool |
There is no way for inference to know this, so it makes sense to help it.
It's not necessary for the :typeinfo
access below because the only way you use it is with ===
and that's a builtin so there's only one "method."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, in Base
, the default value for :typeinfo
seems to be set as Any
, not nothing
. So, I'll change it to Any
.
print(io, "Array{") | ||
showtype(io, X) | ||
print(io, ",$(ndims(a))}") | ||
toplevel && hasalias(X) && print(io, " with eltype ", X) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting to make this conditional on hasalias
. Seems sensible.
I'll make sure that v0.8.4 doesn't have any fatal side effects on the downstream packages, then I'll merge this. Edit: |
Fixes #188
Before (Julia v1.4.2)
After (Julia v1.4.2)