827
827
function link!! (vi:: AbstractVarInfo , vns:: VarNameTuple , model:: Model )
828
828
return link!! (default_transformation (model, vi), vi, vns, model)
829
829
end
830
+ function link!! (t:: DynamicTransformation , vi:: AbstractVarInfo , model:: Model )
831
+ # Note that in practice this method is only called for SimpleVarInfo, because VarInfo
832
+ # has a dedicated implementation
833
+ ctx = DynamicTransformationContext {false} ()
834
+ model = contextualize (model, setleafcontext (model. context, ctx))
835
+ vi = last (evaluate!! (model, vi))
836
+ return settrans!! (vi, t)
837
+ end
838
+ function link!! (
839
+ t:: StaticTransformation{<:Bijectors.Transform} , vi:: AbstractVarInfo , :: Model
840
+ )
841
+ b = inverse (t. bijector)
842
+ x = vi[:]
843
+ y, logjac = with_logabsdet_jacobian (b, x)
844
+ # Set parameters and add the logjac term.
845
+ vi = unflatten (vi, y)
846
+ if hasacc (vi, Val (:LogJacobian ))
847
+ vi = acclogjac!! (vi, logjac)
848
+ end
849
+ return settrans!! (vi, t)
850
+ end
830
851
831
852
"""
832
853
link([t::AbstractTransformation, ]vi::AbstractVarInfo, model::Model)
846
867
function link (vi:: AbstractVarInfo , vns:: VarNameTuple , model:: Model )
847
868
return link (default_transformation (model, vi), vi, vns, model)
848
869
end
870
+ function link (t:: DynamicTransformation , vi:: AbstractVarInfo , model:: Model )
871
+ return link!! (t, deepcopy (vi), model)
872
+ end
849
873
850
874
"""
851
875
invlink!!([t::AbstractTransformation, ]vi::AbstractVarInfo, model::Model)
@@ -866,23 +890,14 @@ end
866
890
function invlink!! (vi:: AbstractVarInfo , vns:: VarNameTuple , model:: Model )
867
891
return invlink!! (default_transformation (model, vi), vi, vns, model)
868
892
end
869
-
870
- # Vector-based ones.
871
- function link!! (
872
- t:: StaticTransformation{<:Bijectors.Transform} , vi:: AbstractVarInfo , :: Model
873
- )
874
- b = inverse (t. bijector)
875
- x = vi[:]
876
- y, logjac = with_logabsdet_jacobian (b, x)
877
-
878
- # Set parameters and add the logjac term.
879
- vi = unflatten (vi, y)
880
- if hasacc (vi, Val (:LogJacobian ))
881
- vi = acclogjac!! (vi, logjac)
882
- end
883
- return settrans!! (vi, t)
893
+ function invlink!! (:: DynamicTransformation , vi:: AbstractVarInfo , model:: Model )
894
+ # Note that in practice this method is only called for SimpleVarInfo, because VarInfo
895
+ # has a dedicated implementation
896
+ ctx = DynamicTransformationContext {true} ()
897
+ model = contextualize (model, setleafcontext (model. context, ctx))
898
+ vi = last (evaluate!! (model, vi))
899
+ return settrans!! (vi, NoTransformation ())
884
900
end
885
-
886
901
function invlink!! (
887
902
t:: StaticTransformation{<:Bijectors.Transform} , vi:: AbstractVarInfo , :: Model
888
903
)
919
934
function invlink (vi:: AbstractVarInfo , vns:: VarNameTuple , model:: Model )
920
935
return invlink (default_transformation (model, vi), vi, vns, model)
921
936
end
937
+ function invlink (t:: DynamicTransformation , vi:: AbstractVarInfo , model:: Model )
938
+ return invlink!! (t, deepcopy (vi), model)
939
+ end
922
940
923
941
"""
924
942
maybe_invlink_before_eval!!([t::Transformation,] vi, model)
0 commit comments