Parameters.jl
Parameters.jl copied to clipboard
Improve show (e.g. show value with dual numbers)
Is it on purpose that values of complex or dual types are not shown? (But arrays of those element types are shown?) MWE (v0.7):
using Parameters, DualNumbers
@with_kw struct Para
a = 0.0
b = 0.0 + im
c = 0.0 + ε
d = zeros(2) .+ im
e = zeros(2) .+ ε
end
Para()
Output (added comments are mine):
julia> Para()
Para
a: Float64 0.0
b: Complex{Float64} # no value shown?
c: Dual{Float64} # no value shown?
d: Array{Complex{Float64}}((2,)) Complex{Float64}[0.0+1.0im, 0.0+1.0im]
e: Array{Dual{Float64}}((2,)) Dual{Float64}[0.0+1.0ɛ, 0.0+1.0ɛ]
That's not good. As a quick work-around you can use the @with_kw_noshow.
Related, I think the printing should leave away the types of the fields.
Yes, printing just the values without the types would be much nicer. With Unitful:
julia> AAA(a=1.0u"m/s", b=2)
AAA
a: Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))},Unitful.FreeUnits{(Unitful.Unit{:Meter,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}(0, 1//1), Unitful.Unit{:Second,Unitful.Dimensions{(Unitful.Dimension{:Time}(1//1),)}}(0, -1//1)),Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1), Unitful.Dimension{:Time}(-1//1))}}}
b: Int64 2
I just use dump for the printing (with maxdepth=1). A custom rolled printer would be great. Alternatively increasing maxdepth would yield:
julia> dump(Para(),maxdepth=2)
Para
a: Float64 0.0
b: Complex{Float64}
re: Float64 0.0
im: Float64 1.0
which isn't great either.