@@ -382,34 +382,13 @@ module Issue537 end
382
382
@test demo2 ()() == 42
383
383
end
384
384
385
- @testset " @submodel is deprecated" begin
386
- @model inner () = x ~ Normal ()
387
- @model outer () = @submodel x = inner ()
388
- @test_logs (
389
- (
390
- :warn ,
391
- " `@submodel model` and `@submodel prefix=... model` are deprecated; see `to_submodel` for the up-to-date syntax." ,
392
- ),
393
- outer ()()
394
- )
395
-
396
- @model outer_with_prefix () = @submodel prefix = " sub" x = inner ()
397
- @test_logs (
398
- (
399
- :warn ,
400
- " `@submodel model` and `@submodel prefix=... model` are deprecated; see `to_submodel` for the up-to-date syntax." ,
401
- ),
402
- outer_with_prefix ()()
403
- )
404
- end
405
-
406
- @testset " submodel" begin
385
+ @testset " to_submodel" begin
407
386
# No prefix, 1 level.
408
387
@model function demo1 (x)
409
388
return x ~ Normal ()
410
389
end
411
390
@model function demo2 (x, y)
412
- @submodel demo1 (x)
391
+ _ignore ~ to_submodel ( demo1 (x), false )
413
392
return y ~ Uniform ()
414
393
end
415
394
# No observation.
@@ -441,7 +420,7 @@ module Issue537 end
441
420
442
421
# Check values makes sense.
443
422
@model function demo3 (x, y)
444
- @submodel demo1 (x)
423
+ _ignore ~ to_submodel ( demo1 (x), false )
445
424
return y ~ Normal (x)
446
425
end
447
426
m = demo3 (1000.0 , missing )
@@ -453,12 +432,10 @@ module Issue537 end
453
432
x ~ Normal ()
454
433
return x
455
434
end
456
-
457
435
@model function demo_useval (x, y)
458
- @submodel prefix = " sub1" x1 = demo_return (x)
459
- @submodel prefix = " sub2" x2 = demo_return (y)
460
-
461
- return z ~ Normal (x1 + x2 + 100 , 1.0 )
436
+ sub1 ~ to_submodel (demo_return (x))
437
+ sub2 ~ to_submodel (demo_return (y))
438
+ return z ~ Normal (sub1 + sub2 + 100 , 1.0 )
462
439
end
463
440
m = demo_useval (missing , missing )
464
441
vi = VarInfo (m)
@@ -472,21 +449,18 @@ module Issue537 end
472
449
@model function AR1 (num_steps, α, μ, σ, :: Type{TV} = Vector{Float64}) where {TV}
473
450
η ~ MvNormal (zeros (num_steps), I)
474
451
δ = sqrt (1 - α^ 2 )
475
-
476
452
x = TV (undef, num_steps)
477
453
x[1 ] = η[1 ]
478
454
@inbounds for t in 2 : num_steps
479
455
x[t] = @. α * x[t - 1 ] + δ * η[t]
480
456
end
481
-
482
457
return @. μ + σ * x
483
458
end
484
459
485
460
@model function demo (y)
486
461
α ~ Uniform ()
487
462
μ ~ Normal ()
488
463
σ ~ truncated (Normal (), 0 , Inf )
489
-
490
464
num_steps = length (y[1 ])
491
465
num_obs = length (y)
492
466
@inbounds for i in 1 : num_obs
@@ -613,14 +587,11 @@ module Issue537 end
613
587
@model demo () = x ~ Normal ()
614
588
retval, svi = DynamicPPL. evaluate!! (demo (), SimpleVarInfo (), SamplingContext ())
615
589
616
- # Return-value when using `@submodel `
590
+ # Return-value when using `to_submodel `
617
591
@model inner () = x ~ Normal ()
618
- # Without assignment.
619
- @model outer () = @submodel inner ()
620
- @test outer ()() isa Real
621
-
622
- # With assignment.
623
- @model outer () = @submodel x = inner ()
592
+ @model function outer ()
593
+ return _ignore ~ to_submodel (inner ())
594
+ end
624
595
@test outer ()() isa Real
625
596
626
597
# Edge-cases.
@@ -720,8 +691,7 @@ module Issue537 end
720
691
return (; x, y)
721
692
end
722
693
@model function demo_tracked_submodel ()
723
- @submodel (x, y) = demo_tracked ()
724
- return (; x, y)
694
+ return vals ~ to_submodel (demo_tracked (), false )
725
695
end
726
696
for model in [demo_tracked (), demo_tracked_submodel ()]
727
697
# Make sure it's runnable and `y` is present in the return-value.
0 commit comments