Parameters.jl icon indicating copy to clipboard operation
Parameters.jl copied to clipboard

Improve show (e.g. show value with dual numbers)

Open briochemc opened this issue 7 years ago • 3 comments

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ɛ]

briochemc avatar Sep 10 '18 17:09 briochemc

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.

mauro3 avatar Sep 10 '18 18:09 mauro3

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

cstjean avatar Oct 16 '18 19:10 cstjean

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.

mauro3 avatar Jan 25 '19 10:01 mauro3