@@ -208,7 +208,6 @@ function generate_mainbody!(found, expr::Expr, args)
208
208
return Expr (expr. head, map (x -> generate_mainbody! (found, x, args), expr. args)... )
209
209
end
210
210
211
- # """ Unbreak code highlighting in Emacs julia-mode
212
211
213
212
214
213
"""
@@ -218,7 +217,7 @@ Generate an `observe` expression for data variables and `assume` expression for
218
217
variables.
219
218
"""
220
219
function generate_tilde (left, right, args)
221
- @gensym tmpright tmpleft
220
+ @gensym tmpright
222
221
top = [:($ tmpright = $ right),
223
222
:($ tmpright isa Union{$ Distribution,AbstractVector{<: $Distribution }}
224
223
|| throw (ArgumentError ($ DISTMSG)))]
@@ -227,48 +226,32 @@ function generate_tilde(left, right, args)
227
226
@gensym out vn inds
228
227
push! (top, :($ vn = $ (varname (left))), :($ inds = $ (vinds (left))))
229
228
230
- assumption = [
231
- :($ out = $ (DynamicPPL. tilde_assume)(_context, _sampler, $ tmpright, $ vn, $ inds,
232
- _varinfo)),
233
- :($ (DynamicPPL. acclogp!)(_varinfo, $ out[2 ])),
234
- :($ left = $ out[1 ])
235
- ]
236
-
237
229
# It can only be an observation if the LHS is an argument of the model
238
230
if vsym (left) in args
239
231
@gensym isassumption
240
232
return quote
241
233
$ (top... )
242
234
$ isassumption = $ (DynamicPPL. isassumption (left))
243
235
if $ isassumption
244
- $ (assumption... )
236
+ $ left = $ (DynamicPPL. tilde_assume)(
237
+ _context, _sampler, $ tmpright, $ vn, $ inds, _varinfo)
245
238
else
246
- $ tmpleft = $ left
247
- $ (DynamicPPL. acclogp!)(
248
- _varinfo,
249
- $ (DynamicPPL. tilde_observe)(_context, _sampler, $ tmpright, $ tmpleft,
250
- $ vn, $ inds, _varinfo)
251
- )
252
- $ tmpleft
239
+ $ (DynamicPPL. tilde_observe)(
240
+ _context, _sampler, $ tmpright, $ left, $ vn, $ inds, _varinfo)
253
241
end
254
242
end
255
243
end
256
244
257
245
return quote
258
246
$ (top... )
259
- $ (assumption ... )
247
+ $ left = $ (DynamicPPL . tilde_assume)(_context, _sampler, $ tmpright, $ vn, $ inds, _varinfo )
260
248
end
261
249
end
262
250
263
251
# If the LHS is a literal, it is always an observation
264
252
return quote
265
253
$ (top... )
266
- $ tmpleft = $ left
267
- $ (DynamicPPL. acclogp!)(
268
- _varinfo,
269
- $ (DynamicPPL. tilde_observe)(_context, _sampler, $ tmpright, $ tmpleft, _varinfo)
270
- )
271
- $ tmpleft
254
+ $ (DynamicPPL. tilde_observe)(_context, _sampler, $ tmpright, $ left, _varinfo)
272
255
end
273
256
end
274
257
278
261
Generate the expression that replaces `left .~ right` in the model body.
279
262
"""
280
263
function generate_dot_tilde (left, right, args)
281
- @gensym tmpright tmpleft
264
+ @gensym tmpright
282
265
top = [:($ tmpright = $ right),
283
266
:($ tmpright isa Union{$ Distribution,AbstractVector{<: $Distribution }}
284
267
|| throw (ArgumentError ($ DISTMSG)))]
@@ -287,49 +270,33 @@ function generate_dot_tilde(left, right, args)
287
270
@gensym out vn inds
288
271
push! (top, :($ vn = $ (varname (left))), :($ inds = $ (vinds (left))))
289
272
290
- assumption = [
291
- :($ out = $ (DynamicPPL. dot_tilde_assume)(_context, _sampler, $ tmpright, $ left,
292
- $ vn, $ inds, _varinfo)),
293
- :($ (DynamicPPL. acclogp!)(_varinfo, $ out[2 ])),
294
- :($ left .= $ out[1 ])
295
- ]
296
-
297
273
# It can only be an observation if the LHS is an argument of the model
298
274
if vsym (left) in args
299
275
@gensym isassumption
300
276
return quote
301
277
$ (top... )
302
278
$ isassumption = $ (DynamicPPL. isassumption (left))
303
279
if $ isassumption
304
- $ (assumption... )
280
+ $ left .= $ (DynamicPPL. dot_tilde_assume)(
281
+ _context, _sampler, $ tmpright, $ left, $ vn, $ inds, _varinfo)
305
282
else
306
- $ tmpleft = $ left
307
- $ (DynamicPPL. acclogp!)(
308
- _varinfo,
309
- $ (DynamicPPL. dot_tilde_observe)(_context, _sampler, $ tmpright,
310
- $ tmpleft, $ vn, $ inds, _varinfo)
311
- )
312
- $ tmpleft
283
+ $ (DynamicPPL. dot_tilde_observe)(
284
+ _context, _sampler, $ tmpright, $ left, $ vn, $ inds, _varinfo)
313
285
end
314
286
end
315
287
end
316
288
317
289
return quote
318
290
$ (top... )
319
- $ (assumption... )
291
+ $ left .= $ (DynamicPPL. dot_tilde_assume)(
292
+ _context, _sampler, $ tmpright, $ left, $ vn, $ inds, _varinfo)
320
293
end
321
294
end
322
295
323
296
# If the LHS is a literal, it is always an observation
324
297
return quote
325
298
$ (top... )
326
- $ tmpleft = $ left
327
- $ (DynamicPPL. acclogp!)(
328
- _varinfo,
329
- $ (DynamicPPL. dot_tilde_observe)(_context, _sampler, $ tmpright, $ tmpleft,
330
- _varinfo)
331
- )
332
- $ tmpleft
299
+ $ (DynamicPPL. dot_tilde_observe)(_context, _sampler, $ tmpright, $ left, _varinfo)
333
300
end
334
301
end
335
302
0 commit comments