Skip to content

Commit 9f392a7

Browse files
committed
added InteractiveUtils.jl as a dep + model_typed and
`model_warntype` for the checking of the model's evaluator
1 parent 18af48a commit 9f392a7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
1414
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
1515
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1616
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
17+
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1718
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1819
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
1920
LogDensityProblemsAD = "996a588d-648d-4e1f-a8f0-a84b347e47b1"

src/debug_utils.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using ..DynamicPPL: broadcast_safe, AbstractContext, childcontext
55

66
using Random: Random
77
using Accessors: Accessors
8+
using InteractiveUtils: InteractiveUtils
89

910
using DocStringExtensions
1011
using Distributions
@@ -678,4 +679,36 @@ function has_static_constraints(
678679
return all_the_same(transforms)
679680
end
680681

682+
"""
683+
model_warntype(model[, varinfo, context])
684+
685+
Check the type stability of the model's evaluator, warning about any potential issues.
686+
687+
This simply calls `@code_warntype` on the model's evaluator, filling in internal arguments where needed.
688+
"""
689+
function model_warntype(model::Model, varinfo::AbstractVarInfo=VarInfo(model), context::AbstractContext=DefaultContext())
690+
args, kwargs = DynamicPPL.make_evaluate_args_and_kwargs(model, varinfo, context)
691+
return if isempty(kwargs)
692+
InteractiveUtils.@code_warntype model.f(args...)
693+
else
694+
InteractiveUtils.@code_warntype model.f(args...; kwargs...)
695+
end
696+
end
697+
698+
"""
699+
model_typed(model[, varinfo, context])
700+
701+
Return the type inference for the model's evaluator.
702+
703+
This simply calls `@code_typed` on the model's evaluator, filling in internal arguments where needed.
704+
"""
705+
function model_typed(model::Model, varinfo::AbstractVarInfo=VarInfo(model), context::AbstractContext=DefaultContext())
706+
args, kwargs = DynamicPPL.make_evaluate_args_and_kwargs(model, varinfo, context)
707+
return if isempty(kwargs)
708+
InteractiveUtils.@code_typed model.f(args...)
709+
else
710+
InteractiveUtils.@code_typed model.f(args...; kwargs...)
711+
end
712+
end
713+
681714
end

0 commit comments

Comments
 (0)