Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove selector stuff from VarInfo tests and link/invlink #780

Merged
merged 33 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4dc2a72
Remove selector stuff from varinfo tests
mhauru Jan 16, 2025
9b492a3
Implement link and invlink for varnames rather than samplers
mhauru Jan 16, 2025
b508f08
Replace set_retained_vns_del_by_spl! with set_retained_vns_del!
mhauru Jan 16, 2025
b8880d1
Make linking tests more extensive
mhauru Jan 16, 2025
99a8490
Remove sampler indexing from link methods (but not invlink)
mhauru Jan 22, 2025
4a79b1f
Remove indexing by samplers from invlink
mhauru Jan 22, 2025
26a1901
Merge remote-tracking branch 'origin/master' into mhauru/remove-selec…
mhauru Jan 22, 2025
090608b
Work towards removing sampler indexing with StaticTransformation
mhauru Jan 22, 2025
4749853
Fix invlink/link for TypedVarInfo and StaticTransformation
mhauru Jan 23, 2025
e960679
Fix a test in models.jl
mhauru Jan 23, 2025
d507a53
Move some functions to utils.jl, add tests and docstrings
mhauru Jan 23, 2025
41150b5
Fix a docstring typo
mhauru Jan 23, 2025
836fb13
Merge branch 'release-0.35' into mhauru/remove-selectors-linking
mhauru Jan 23, 2025
45d1f13
Various simplification to link/invlink
mhauru Jan 23, 2025
98915c2
Improve a docstring
mhauru Jan 23, 2025
f05068d
Style improvements
mhauru Jan 23, 2025
bc4c420
Fix broken link/invlink dispatch cascade for VectorVarInfo
mhauru Jan 23, 2025
71980ba
Fix some more broken dispatch cascades
mhauru Jan 23, 2025
45562a9
Apply suggestions from code review
mhauru Jan 24, 2025
db5b835
Remove comments that messed with docstrings
mhauru Jan 24, 2025
f99effe
Apply suggestions from code review
mhauru Jan 28, 2025
56194cd
Fix issues surfaced in code review
mhauru Jan 28, 2025
c187c49
Simplify link/invlink arguments
mhauru Jan 28, 2025
86b25c5
Fix a bug in unflatten VarNamedVector
mhauru Jan 28, 2025
2a6c1bc
Rename VarNameCollection -> VarNameTuple
mhauru Jan 28, 2025
853f47e
Remove test of a removed varname_namedtuple method
mhauru Jan 28, 2025
ed80328
Apply suggestions from code review
mhauru Jan 29, 2025
d996d0c
Respond to review feedback
mhauru Jan 29, 2025
2083148
Remove _default_sampler and a dead argument of maybe_invlink_before_eval
mhauru Jan 29, 2025
39fa647
Fix a typo in a comment
mhauru Jan 29, 2025
9df364f
Merge remote-tracking branch 'origin/release-0.35' into mhauru/remove…
mhauru Jan 30, 2025
2c73de5
Add HISTORY entry, fix one set_retained_vns_del! method
mhauru Jan 30, 2025
49604e1
Merge remote-tracking branch 'origin/release-0.35' into mhauru/remove…
mhauru Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 111 additions & 33 deletions src/abstract_varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,9 @@

"""
link!!([t::AbstractTransformation, ]vi::AbstractVarInfo, model::Model)
link!!([t::AbstractTransformation, ]vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
link!!([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::VarName, model::Model)
link!!([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::Tuple{N,VarName}, model::Model)
link!!([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::AbstractVector{<:VarName}, model::Model)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mightttt have mentioned this before, but I still would really prefer if we didn't define a single-VarName method.

  • There are many settings in DynamicPPL / Turing where we have some variable vn which might be a VarName or an iterable of VarNames depending on the context, and it's difficult to guess which one is happening when it gets passed to a function that can take either.
  • Another general reason to not declare convenience methods is that complexity grows in a multiplicative sense. If we have M types of AbstractTransformation and N types of AbstractVarInfo, then for every possible type that we let the vns parameter be, we are essentially declaring M*N more methods, for which we need to make sure that they all exist, behave correctly, and don't generate any method ambiguities (the act of resolving method ambiguities itself leads to code duplication).
    (But at least it's better than allowing a new optional parameter, for which complexity grows exponentially, cf. our situation with evaluate!!.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this now, even though I would like to have the single-VarName version. The reason I've removed it is that the dispatch on link/invlink is already too complicated, which indeed causes method ambiguities. I think if the dispatch got cleaned up otherwise we could reintroduce the single-VarName version, which we should be able to do with just a single method without ambiguities (because no other method would accept a single VarName). However, for now it's not worth the code complexity, given that it's not really needed anywhere.

For the first point of being able to see the type at the call site, I see what you mean, but I think this is something you have to largely give up in a dynamically typed language like Julia, and I think the ergonomy of the single-VarName method would outweigh it.

Copy link
Member

@penelopeysm penelopeysm Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is something you have to largely give up in a dynamically typed language like Julia

Maybe not very surprising, but I don't agree with this 🙈

Dynamic typing means that it's not possible to unambiguously determine the type of something (using type inference algorithms, or in practice, LSP), but often it's possible to make limited inferences from the known function signatures. In a dynamically typed language, it's not possible to verify these inferences at compile time, but IMO it doesn't follow from this that we should make it harder for ourselves to make such inferences.

The most frequently cited benefit of dynamic typing is the ease of prototyping. However, I think this primarily applies to the end users of the language, i.e. people who end up using Turing. If this was a case of providing nice APIs for end users, I'd be totally on board with extra convenience methods, but I think the (inv)?link(!!)? functions are pretty much entirely for internal use. I believe (and I hope it's not a controversial opinion!) that it's easier to maintain, reason about, and guarantee the correctness of software that is statically typed, and although we can't do that in Julia, I do think that any step we can take in that direction is a net positive, and our lives will be easier if we are more disciplined about our internal APIs 😉

Anyway, I just wanted to write it out because I suspect that me pushing back against multiple dispatch 'overuse' (quotes because others may not agree that it's overuse!) might be a continuing trend in PRs. I do recognise it's not my personal codebase and I'll always be happy to compromise on the outcome, in the sense that if you say you really want a convenience method I'll just say 'ehh, whatever', but I think it's unlikely that I'll really change my mind on the underlying principle. So I write it out once and I'll spare all of you this next time 😄 Maybe I will bookmark it and copy paste the link whenever people ask me about it hahah

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Btw just on this PR I'm happy with how it stands with dispatch so feel free to resolve this convo!)

Transform the variables in `vi` to their linked space, using the transformation `t`,
mutating `vi` if possible.
Expand All @@ -548,37 +550,67 @@

See also: [`default_transformation`](@ref), [`invlink!!`](@ref).
"""
link!!(vi::AbstractVarInfo, model::Model) = link!!(vi, SampleFromPrior(), model)
# Use `default_transformation` to decide which transformation to use if none is specified.
mhauru marked this conversation as resolved.
Show resolved Hide resolved
function link!!(vi::AbstractVarInfo, model::Model)
return link!!(default_transformation(model, vi), vi, model)
end
function link!!(vi::AbstractVarInfo, vns, model::Model)
mhauru marked this conversation as resolved.
Show resolved Hide resolved
return link!!(default_transformation(model, vi), vi, vns, model)
end
# If no variable names are provided, link all variables.
mhauru marked this conversation as resolved.
Show resolved Hide resolved
function link!!(t::AbstractTransformation, vi::AbstractVarInfo, model::Model)
return link!!(t, vi, SampleFromPrior(), model)
vns = collect(keys(vi))
# In case e.g. vns = Any[].
# TODO(mhauru) Could we rather fix akeys` so that it would always return VarName[]?
mhauru marked this conversation as resolved.
Show resolved Hide resolved
if !(eltype(vns) <: VarName)
vns = collect(VarName, vns)
end
return link!!(t, vi, vns, model)
end
function link!!(vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
# Use `default_transformation` to decide which transformation to use if none is specified.
return link!!(default_transformation(model, vi), vi, spl, model)
# Wrap a single VarName in a singleton tuple.
mhauru marked this conversation as resolved.
Show resolved Hide resolved
function link!!(t::AbstractTransformation, vi::AbstractVarInfo, vn::VarName, model::Model)
return link!!(t, vi, (vn,), model)
end

"""
link([t::AbstractTransformation, ]vi::AbstractVarInfo, model::Model)
link([t::AbstractTransformation, ]vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
link([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::VarName, model::Model)
link([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::Tuple{N,VarName}, model::Model)
link([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::AbstractVector{<:VarName}, model::Model)

Transform the variables in `vi` to their linked space without mutating `vi`, using the transformation `t`.

If `t` is not provided, `default_transformation(model, vi)` will be used.

See also: [`default_transformation`](@ref), [`invlink`](@ref).
"""
link(vi::AbstractVarInfo, model::Model) = link(vi, SampleFromPrior(), model)
# Use `default_transformation` to decide which transformation to use if none is specified.
mhauru marked this conversation as resolved.
Show resolved Hide resolved
function link(vi::AbstractVarInfo, model::Model)
return link(default_transformation(model, vi), vi, model)
end
function link(vi::AbstractVarInfo, vns, model::Model)
return link(default_transformation(model, vi), vi, vns, model)
end
# If no variable names are provided, link all variables.
function link(t::AbstractTransformation, vi::AbstractVarInfo, model::Model)
return link(t, deepcopy(vi), SampleFromPrior(), model)
vns = collect(keys(vi))
# In case e.g. vns = Any[].
# TODO(mhauru) Could we rather fix akeys` so that it would always return VarName[]?
mhauru marked this conversation as resolved.
Show resolved Hide resolved
if !(eltype(vns) <: VarName)
vns = collect(VarName, vns)
end
return link(t, vi, vns, model)
end
function link(vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
# Use `default_transformation` to decide which transformation to use if none is specified.
return link(default_transformation(model, vi), deepcopy(vi), spl, model)
# Wrap a single VarName in a singleton tuple.
mhauru marked this conversation as resolved.
Show resolved Hide resolved
function link(t::AbstractTransformation, vi::AbstractVarInfo, vn::VarName, model::Model)
return link(t, vi, (vn,), model)

Check warning on line 606 in src/abstract_varinfo.jl

View check run for this annotation

Codecov / codecov/patch

src/abstract_varinfo.jl#L605-L606

Added lines #L605 - L606 were not covered by tests
end

"""
invlink!!([t::AbstractTransformation, ]vi::AbstractVarInfo, model::Model)
invlink!!([t::AbstractTransformation, ]vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
invlink!!([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::VarName, model::Model)
invlink!!([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::Tuple{N,VarName}, model::Model)
invlink!!([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::AbstractVector{<:VarName}, model::Model)

Transform the variables in `vi` to their constrained space, using the (inverse of)
transformation `t`, mutating `vi` if possible.
Expand All @@ -587,49 +619,81 @@

See also: [`default_transformation`](@ref), [`link!!`](@ref).
"""
invlink!!(vi::AbstractVarInfo, model::Model) = invlink!!(vi, SampleFromPrior(), model)
# Use `default_transformation` to decide which transformation to use if none is specified.
mhauru marked this conversation as resolved.
Show resolved Hide resolved
function invlink!!(vi::AbstractVarInfo, model::Model)
return invlink!!(default_transformation(model, vi), vi, model)
end
function invlink!!(vi::AbstractVarInfo, vns, model::Model)
return invlink!!(default_transformation(model, vi), vi, vns, model)
end
# If no variable names are provided, invlink!! all variables.
function invlink!!(t::AbstractTransformation, vi::AbstractVarInfo, model::Model)
return invlink!!(t, vi, SampleFromPrior(), model)
vns = collect(keys(vi))
# In case e.g. vns = Any[].
if !(eltype(vns) <: VarName)
vns = collect(VarName, vns)
end
return invlink!!(t, vi, vns, model)
end
function invlink!!(vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
# Here we extract the `transformation` from `vi` rather than using the default one.
return invlink!!(transformation(vi), vi, spl, model)
# Wrap a single VarName in a singleton tuple.
function invlink!!(
t::AbstractTransformation, vi::AbstractVarInfo, vn::VarName, model::Model
)
return invlink!!(t, vi, (vn,), model)
end

# Vector-based ones.
function link!!(
t::StaticTransformation{<:Bijectors.Transform},
vi::AbstractVarInfo,
spl::AbstractSampler,
model::Model,
vns::VarNameCollection,
::Model,
)
# TODO(mhauru) The behavior of this before the removal of indexing with samplers was a
# bit mixed. For TypedVarInfo you could transform only a subset of the variables, but
# for UntypedVarInfo and SimpleVarInfo it was silently assumed that all variables were
# being set. Unsure if we should support this or not, but at least it now errors
# loudly.
all_vns = Set(keys(vi))
if Set(vns) != all_vns
msg = "StaticTransforming only a subset of variables is not supported."
mhauru marked this conversation as resolved.
Show resolved Hide resolved
throw(ArgumentError(msg))

Check warning on line 660 in src/abstract_varinfo.jl

View check run for this annotation

Codecov / codecov/patch

src/abstract_varinfo.jl#L659-L660

Added lines #L659 - L660 were not covered by tests
end
b = inverse(t.bijector)
x = vi[spl]
x = vi[:]
y, logjac = with_logabsdet_jacobian(b, x)

lp_new = getlogp(vi) - logjac
vi_new = setlogp!!(unflatten(vi, spl, y), lp_new)
vi_new = setlogp!!(unflatten(vi, y), lp_new)
return settrans!!(vi_new, t)
end

function invlink!!(
t::StaticTransformation{<:Bijectors.Transform},
vi::AbstractVarInfo,
spl::AbstractSampler,
model::Model,
vns::VarNameCollection,
::Model,
)
# TODO(mhauru) See comment in link!! above.
all_vns = Set(keys(vi))
if Set(vns) != all_vns
msg = "StaticTransforming only a subset of variables is not supported."
mhauru marked this conversation as resolved.
Show resolved Hide resolved
throw(ArgumentError(msg))

Check warning on line 681 in src/abstract_varinfo.jl

View check run for this annotation

Codecov / codecov/patch

src/abstract_varinfo.jl#L680-L681

Added lines #L680 - L681 were not covered by tests
end
b = t.bijector
y = vi[spl]
y = vi[:]
x, logjac = with_logabsdet_jacobian(b, y)

lp_new = getlogp(vi) + logjac
vi_new = setlogp!!(unflatten(vi, spl, x), lp_new)
vi_new = setlogp!!(unflatten(vi, x), lp_new)
return settrans!!(vi_new, NoTransformation())
end

"""
invlink([t::AbstractTransformation, ]vi::AbstractVarInfo, model::Model)
invlink([t::AbstractTransformation, ]vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
invlink([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::VarName, model::Model)
invlink([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::Tuple{N,VarName}, model::Model)
invlink([t::AbstractTransformation, ]vi::AbstractVarInfo, vn::AbstractVector{<:VarName}, model::Model)

Transform the variables in `vi` to their constrained space without mutating `vi`, using the (inverse of)
transformation `t`.
Expand All @@ -638,12 +702,25 @@

See also: [`default_transformation`](@ref), [`link`](@ref).
"""
invlink(vi::AbstractVarInfo, model::Model) = invlink(vi, SampleFromPrior(), model)
# Use `default_transformation` to decide which transformation to use if none is specified.
mhauru marked this conversation as resolved.
Show resolved Hide resolved
function invlink(vi::AbstractVarInfo, model::Model)
return invlink(default_transformation(model, vi), vi, model)
end
function invlink(vi::AbstractVarInfo, vns, model::Model)
return invlink(default_transformation(model, vi), vi, vns, model)
end
# If no variable names are provided, invlink all variables.
function invlink(t::AbstractTransformation, vi::AbstractVarInfo, model::Model)
return invlink(t, vi, SampleFromPrior(), model)
vns = collect(keys(vi))
# In case e.g. vns = Any[].
if !(eltype(vns) <: VarName)
vns = collect(VarName, vns)
end
return invlink(t, vi, vns, model)
end
function invlink(vi::AbstractVarInfo, spl::AbstractSampler, model::Model)
return invlink(transformation(vi), vi, spl, model)
# Wrap a single VarName in a singleton tuple.
function invlink(t::AbstractTransformation, vi::AbstractVarInfo, vn::VarName, model::Model)
return invlink(t, vi, (vn,), model)

Check warning on line 723 in src/abstract_varinfo.jl

View check run for this annotation

Codecov / codecov/patch

src/abstract_varinfo.jl#L722-L723

Added lines #L722 - L723 were not covered by tests
end

"""
Expand Down Expand Up @@ -715,9 +792,10 @@
return vi
end
function maybe_invlink_before_eval!!(
t::StaticTransformation, vi::AbstractVarInfo, context::AbstractContext, model::Model
t::StaticTransformation, vi::AbstractVarInfo, ::AbstractContext, model::Model
)
return invlink!!(t, vi, _default_sampler(context), model)
# TODO(mhauru) Why does this function need the context argument?
return invlink!!(t, vi, model)
end

function _default_sampler(context::AbstractContext)
mhauru marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
4 changes: 2 additions & 2 deletions src/simple_varinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ Distributions.loglikelihood(model::Model, θ) = loglikelihood(model, SimpleVarIn
function link!!(
t::StaticTransformation{<:Bijectors.NamedTransform},
vi::SimpleVarInfo{<:NamedTuple},
spl::AbstractSampler,
::VarNameCollection,
model::Model,
)
# TODO: Make sure that `spl` is respected.
Expand All @@ -695,7 +695,7 @@ end
function invlink!!(
t::StaticTransformation{<:Bijectors.NamedTransform},
vi::SimpleVarInfo{<:NamedTuple},
spl::AbstractSampler,
::VarNameCollection,
model::Model,
)
# TODO: Make sure that `spl` is respected.
Expand Down
28 changes: 14 additions & 14 deletions src/threadsafe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,41 +82,41 @@
islinked(vi::ThreadSafeVarInfo, spl::AbstractSampler) = islinked(vi.varinfo, spl)

function link!!(
t::AbstractTransformation, vi::ThreadSafeVarInfo, spl::AbstractSampler, model::Model
t::AbstractTransformation, vi::ThreadSafeVarInfo, vns::VarNameCollection, model::Model
)
return Accessors.@set vi.varinfo = link!!(t, vi.varinfo, spl, model)
return Accessors.@set vi.varinfo = link!!(t, vi.varinfo, vns, model)

Check warning on line 87 in src/threadsafe.jl

View check run for this annotation

Codecov / codecov/patch

src/threadsafe.jl#L87

Added line #L87 was not covered by tests
end

function invlink!!(
t::AbstractTransformation, vi::ThreadSafeVarInfo, spl::AbstractSampler, model::Model
t::AbstractTransformation, vi::ThreadSafeVarInfo, vns::VarNameCollection, model::Model
)
return Accessors.@set vi.varinfo = invlink!!(t, vi.varinfo, spl, model)
return Accessors.@set vi.varinfo = invlink!!(t, vi.varinfo, vns, model)

Check warning on line 93 in src/threadsafe.jl

View check run for this annotation

Codecov / codecov/patch

src/threadsafe.jl#L93

Added line #L93 was not covered by tests
end

function link(
t::AbstractTransformation, vi::ThreadSafeVarInfo, spl::AbstractSampler, model::Model
t::AbstractTransformation, vi::ThreadSafeVarInfo, vns::VarNameCollection, model::Model
)
return Accessors.@set vi.varinfo = link(t, vi.varinfo, spl, model)
return Accessors.@set vi.varinfo = link(t, vi.varinfo, vns, model)

Check warning on line 99 in src/threadsafe.jl

View check run for this annotation

Codecov / codecov/patch

src/threadsafe.jl#L99

Added line #L99 was not covered by tests
end

function invlink(
t::AbstractTransformation, vi::ThreadSafeVarInfo, spl::AbstractSampler, model::Model
t::AbstractTransformation, vi::ThreadSafeVarInfo, vns::VarNameCollection, model::Model
)
return Accessors.@set vi.varinfo = invlink(t, vi.varinfo, spl, model)
return Accessors.@set vi.varinfo = invlink(t, vi.varinfo, vns, model)

Check warning on line 105 in src/threadsafe.jl

View check run for this annotation

Codecov / codecov/patch

src/threadsafe.jl#L105

Added line #L105 was not covered by tests
end

# Need to define explicitly for `DynamicTransformation` to avoid method ambiguity.
# NOTE: We also can't just defer to the wrapped varinfo, because we need to ensure
# consistency between `vi.logps` field and `getlogp(vi.varinfo)`, which accumulates
# to define `getlogp(vi)`.
function link!!(
t::DynamicTransformation, vi::ThreadSafeVarInfo, spl::AbstractSampler, model::Model
t::DynamicTransformation, vi::ThreadSafeVarInfo, ::VarNameCollection, model::Model
)
return settrans!!(last(evaluate!!(model, vi, DynamicTransformationContext{false}())), t)
end

function invlink!!(
::DynamicTransformation, vi::ThreadSafeVarInfo, spl::AbstractSampler, model::Model
::DynamicTransformation, vi::ThreadSafeVarInfo, ::VarNameCollection, model::Model
)
return settrans!!(
last(evaluate!!(model, vi, DynamicTransformationContext{true}())),
Expand All @@ -125,15 +125,15 @@
end

function link(
t::DynamicTransformation, vi::ThreadSafeVarInfo, spl::AbstractSampler, model::Model
t::DynamicTransformation, vi::ThreadSafeVarInfo, vns::VarNameCollection, model::Model
)
return link!!(t, deepcopy(vi), spl, model)
return link!!(t, deepcopy(vi), vns, model)
end

function invlink(
t::DynamicTransformation, vi::ThreadSafeVarInfo, spl::AbstractSampler, model::Model
t::DynamicTransformation, vi::ThreadSafeVarInfo, vns::VarNameCollection, model::Model
)
return invlink!!(t, deepcopy(vi), spl, model)
return invlink!!(t, deepcopy(vi), vns, model)
end

function maybe_invlink_before_eval!!(
Expand Down
14 changes: 8 additions & 6 deletions src/transforming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ function dot_tilde_assume(
return r, lp, vi
end

VarNameCollection = Union{NTuple{N,VarName} where N,AbstractVector{<:VarName},NamedTuple}
mhauru marked this conversation as resolved.
Show resolved Hide resolved

function link!!(
t::DynamicTransformation, vi::AbstractVarInfo, spl::AbstractSampler, model::Model
t::DynamicTransformation, vi::AbstractVarInfo, ::VarNameCollection, model::Model
)
return settrans!!(last(evaluate!!(model, vi, DynamicTransformationContext{false}())), t)
end

function invlink!!(
::DynamicTransformation, vi::AbstractVarInfo, spl::AbstractSampler, model::Model
::DynamicTransformation, vi::AbstractVarInfo, ::VarNameCollection, model::Model
)
return settrans!!(
last(evaluate!!(model, vi, DynamicTransformationContext{true}())),
Expand All @@ -107,13 +109,13 @@ function invlink!!(
end

function link(
t::DynamicTransformation, vi::AbstractVarInfo, spl::AbstractSampler, model::Model
t::DynamicTransformation, vi::AbstractVarInfo, vns::VarNameCollection, model::Model
)
return link!!(t, deepcopy(vi), spl, model)
return link!!(t, deepcopy(vi), vns, model)
end

function invlink(
t::DynamicTransformation, vi::AbstractVarInfo, spl::AbstractSampler, model::Model
t::DynamicTransformation, vi::AbstractVarInfo, vns::VarNameCollection, model::Model
)
return invlink!!(t, deepcopy(vi), spl, model)
return invlink!!(t, deepcopy(vi), vns, model)
end
Loading
Loading