Skip to content

Commit fe9eef5

Browse files
add show method
1 parent 30148c0 commit fe9eef5

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/interface.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,17 @@ macro def(expr)
281281
# resulting structs to be @doc... cannot if macro returns a block.)
282282
kwmethod = :($rule(; $(params...)) = $rule($(names...)))
283283
push!(lines, positional, kwmethod)
284-
return esc(expr)
284+
# return esc(expr)
285+
# end
286+
287+
return quote
288+
Base.@__doc__ $expr
289+
290+
function Base.show(io::IO, r::$rule)
291+
pairs = ["$n=$(getfield(r, n))" for n in [($names...)]]
292+
print(io, $rule,"(", join(pairs, ", "), ")")
293+
end
294+
end |> esc
285295
end
286296

287297
_def_typeof(val) = typeof(val)

src/rules.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,7 @@ function adjust(r::RMSProp; kw...)
148148
end
149149

150150
function Base.show(io::IO, o::RMSProp)
151-
print(io, "RMSProp(")
152-
join(io, [o.eta, o.rho, o.epsilon], ", ")
153-
print(io, "; centred = ", o.centred, ")")
151+
print(io, "RMSProp(eta=$(o.eta), rho=$(o.rho), epsilon=$(o.epsilon), centred=$(o.centred)")
154152
end
155153

156154

@@ -565,6 +563,11 @@ function apply!(o::AdamW, state, x::AbstractArray{T}, dx) where T
565563
return (mt, vt, βt .* β), dx′′
566564
end
567565

566+
function Base.show(io::IO, o::AdamW)
567+
print(io, "AdamW(eta=$(o.eta), beta=$(o.beta), lambda=$(o.lambda), epsilon=$(o.epsilon), couple=$(o.couple))")
568+
end
569+
570+
568571
"""
569572
AdaBelief(η = 0.001, β = (0.9, 0.999), ϵ = 1e-16)
570573
AdaBelief(; [eta, beta, epsilon])

0 commit comments

Comments
 (0)