Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
torfjelde committed Oct 7, 2023
1 parent 1e4d9f1 commit bf4fcc6
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -917,23 +917,19 @@ end

function _link(varinfo::TypedVarInfo, spl::AbstractSampler)
varinfo = deepcopy(varinfo)
md = _link_metadata_namedtuple!(varinfo, varinfo.metadata, _getvns(varinfo, spl), Val(getspace(spl)))
md = _link_metadata_namedtuple!(
varinfo, varinfo.metadata, _getvns(varinfo, spl), Val(getspace(spl))
)
return VarInfo(md, Base.Ref(getlogp(varinfo)), Ref(get_num_produce(varinfo)))
end

@generated function _link_metadata_namedtuple!(
varinfo::VarInfo,
metadata::NamedTuple{names},
vns::NamedTuple,
::Val{space}
varinfo::VarInfo, metadata::NamedTuple{names}, vns::NamedTuple, ::Val{space}
) where {names,space}
vals = Expr(:tuple)
for f in names
if inspace(f, space) || length(space) == 0
push!(
vals.args,
:(_link_metadata!(varinfo, metadata.$f, vns.$f))
)
push!(vals.args, :(_link_metadata!(varinfo, metadata.$f, vns.$f)))
else
push!(vals.args, :(metadata.$f))
end
Expand Down Expand Up @@ -1005,23 +1001,19 @@ end

function _invlink(varinfo::TypedVarInfo, spl::AbstractSampler)
varinfo = deepcopy(varinfo)
md = _invlink_metadata_namedtuple!(varinfo, varinfo.metadata, _getvns(varinfo, spl), Val(getspace(spl)))
md = _invlink_metadata_namedtuple!(
varinfo, varinfo.metadata, _getvns(varinfo, spl), Val(getspace(spl))
)
return VarInfo(md, Base.Ref(getlogp(varinfo)), Ref(get_num_produce(varinfo)))
end

@generated function _invlink_metadata_namedtuple!(
varinfo::VarInfo,
metadata::NamedTuple{names},
vns::NamedTuple,
::Val{space}
varinfo::VarInfo, metadata::NamedTuple{names}, vns::NamedTuple, ::Val{space}
) where {names,space}
vals = Expr(:tuple)
for f in names
if inspace(f, space) || length(space) == 0
push!(
vals.args,
:(_invlink_metadata!(varinfo, metadata.$f, vns.$f))
)
push!(vals.args, :(_invlink_metadata!(varinfo, metadata.$f, vns.$f)))
else
push!(vals.args, :(metadata.$f))
end
Expand Down

0 comments on commit bf4fcc6

Please sign in to comment.