@@ -27,44 +27,44 @@ function wrong_dist_errormsg(l)
27
27
end
28
28
29
29
"""
30
- @isassumption(data_vars, missing_vars, ex )
30
+ @isassumption(model, expr )
31
31
32
- Let `ex ` be `x[1]`. This macro returns `true` in any of the following cases:
32
+ Let `expr ` be `x[1]`. `vn` is an assumption in the following cases:
33
33
1. `x` was not among the input data to the model,
34
34
2. `x` was among the input data to the model but with a value `missing`, or
35
35
3. `x` was among the input data to the model with a value other than missing,
36
36
but `x[1] === missing`.
37
- When `ex ` is not a variable (e.g. , a literal), the function returns `false` as well .
37
+ When `expr ` is not an expression or symbol (i.e. , a literal), this expands to `false`.
38
38
"""
39
- macro isassumption (data_vars, missing_vars, ex)
40
- :false
41
- end
42
- macro isassumption (model, ex:: Union{Symbol, Expr} )
43
- sym = gensym (:sym )
44
- lhs = gensym (:lhs )
45
- return esc (quote
46
- # Extract symbol
47
- $ sym = Val ($ (vsym (ex)))
39
+ macro isassumption (model, expr:: Union{Symbol, Expr} )
40
+ # Note: never put a return in this... don't forget it's a macro!
41
+ vn = gensym (:vn )
42
+
43
+ return quote
44
+ $ vn = @varname ($ expr)
45
+
48
46
# This branch should compile nicely in all cases except for partial missing data
49
- # For example, when `ex ` is `x[i]` and `x isa Vector{Union{Missing, Float64}}`
50
- if ! DynamicPPL. inargnames ($ sym , $ model) || DynamicPPL. inmissings ($ sym , $ model)
47
+ # For example, when `expr ` is `x[i]` and `x isa Vector{Union{Missing, Float64}}`
48
+ if ! DynamicPPL. inargnames ($ vn , $ model) || DynamicPPL. inmissings ($ vn , $ model)
51
49
true
52
50
else
53
- if DynamicPPL. inargnames ($ sym , $ model)
51
+ if DynamicPPL. inargnames ($ vn , $ model)
54
52
# Evaluate the lhs
55
- $ lhs = $ ex
56
- if $ lhs === missing
57
- true
58
- else
59
- false
60
- end
53
+ $ expr === missing
61
54
else
62
55
throw (" This point should not be reached. Please report this error." )
63
56
end
64
57
end
65
- end )
58
+ end |> esc
66
59
end
67
60
61
+ macro isassumption (model, expr)
62
+ # failsafe: a literal is never an assumption
63
+ false
64
+ end
65
+
66
+
67
+
68
68
# ################
69
69
# Main Compiler #
70
70
# ################
@@ -301,7 +301,7 @@ function generate_tilde(left, right, model_info)
301
301
inds = gensym (:inds )
302
302
isassumption = gensym (:isassumption )
303
303
assert_ex = :(DynamicPPL. assert_dist ($ temp_right, msg = $ (wrong_dist_errormsg (@__LINE__ ))))
304
-
304
+
305
305
if left isa Symbol || left isa Expr
306
306
ex = quote
307
307
$ temp_right = $ right
0 commit comments