Skip to content

Commit f9de574

Browse files
committed
simplifying flat_params by leaf verification
1 parent c97630d commit f9de574

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/parameter_inspection.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function params(m, ::Val{true})
3030
return NamedTuple{fields}(Tuple([params(getfield(m, field)) for field in fields]))
3131
end
3232

33-
isamodel(::Any) = false
34-
isamodel(::Model) = true
33+
isnotaleaf(::Any) = false
34+
isnotaleaf(m::Model) = length(propertynames(m)) > 0
3535

3636
"""
3737
flat_params(m::Model)
@@ -53,13 +53,10 @@ not a hard requirement.
5353
parallel = true,)
5454
5555
"""
56-
flat_params(m; prefix="") = flat_params(m, Val(isamodel(m)); prefix=prefix)
56+
flat_params(m; prefix="") = flat_params(m, Val(isnotaleaf(m)); prefix=prefix)
5757
flat_params(m, ::Val{false}; prefix="") = NamedTuple{(Symbol(prefix),), Tuple{Any}}((m,))
5858
function flat_params(m, ::Val{true}; prefix="")
5959
fields = propertynames(m)
60-
if isempty(fields)
61-
return NamedTuple{(Symbol(prefix),)}((m,))
62-
end
6360
prefix = prefix == "" ? "" : prefix * "__"
6461
merge([flat_params(getproperty(m, field); prefix="$(prefix)$(field)") for field in fields]...)
6562
end

0 commit comments

Comments
 (0)