135135 end
136136 f1_mm = testmodel1 (1. , 10. )
137137 @test f1_mm () == (1 , 10 )
138- f1_mm = testmodel1 (x1= 1. , x2= 10. )
138+
139+ # alternatives with keyword arguments
140+ testmodel1kw (; x1, x2) = testmodel1 (x1, x2)
141+ f1_mm = testmodel1kw (x1 = 1. , x2 = 10. )
142+ @test f1_mm () == (1 , 10 )
143+
144+ @model function testmodel2 (; x1, x2)
145+ s ~ InverseGamma (2 ,3 )
146+ m ~ Normal (0 ,sqrt (s))
147+
148+ x1 ~ Normal (m, sqrt (s))
149+ x2 ~ Normal (m, sqrt (s))
150+
151+ return x1, x2
152+ end
153+ f1_mm = testmodel2 (x1= 1. , x2= 10. )
139154 @test f1_mm () == (1 , 10 )
140155
141156 @info " Testing the compiler's ability to catch bad models..."
199214 x ~ Bernoulli (0.5 )
200215 return x
201216 end
202- @test_throws UndefKeywordError testmodel ()
217+ @test_throws MethodError testmodel ()
203218
204219 # Test missing initialization for vector observation turned parameter
205220 @model testmodel (x) = begin
266281 chain = sample (gauss (x), PG (10 ), 10 )
267282 chain = sample (gauss (x), SMC (), 10 )
268283
269- @model gauss2 (x, :: Type{TV} = Vector{Float64}) where {TV} = begin
284+ @model function gauss2 (:: Type{TV} = Vector{Float64}; x ) where {TV}
270285 priors = TV (undef, 2 )
271286 priors[1 ] ~ InverseGamma (2 ,3 ) # s
272287 priors[2 ] ~ Normal (0 , sqrt (priors[1 ])) # m
@@ -276,10 +291,11 @@ end
276291 priors
277292 end
278293
279- chain = sample (gauss2 (x), PG (10 ), 10 )
280- chain = sample (gauss2 (x= x, TV= Vector{Float64}), PG (10 ), 10 )
281- chain = sample (gauss2 (x), SMC (), 10 )
282- chain = sample (gauss2 (x= x, TV= Vector{Float64}), SMC (), 10 )
294+ chain = sample (gauss2 (x = x), PG (10 ), 10 )
295+ chain = sample (gauss2 (x = x), SMC (), 10 )
296+
297+ chain = sample (gauss2 (Vector{Float64}; x = x), PG (10 ), 10 )
298+ chain = sample (gauss2 (Vector{Float64}; x = x), SMC (), 10 )
283299 end
284300 @testset " new interface" begin
285301 obs = [0 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]
494510 setchunksize (N)
495511 alg = HMC (0.01 , 5 )
496512 x = randn (1000 )
497- @model vdemo1 (:: Type{T} = Float64) where {T} = begin
513+ @model function vdemo1 (:: Type{T} = Float64) where {T}
498514 x = Vector {T} (undef, N)
499515 for i = 1 : N
500516 x[i] ~ Normal (0 , sqrt (4 ))
503519
504520 t_loop = @elapsed res = sample (vdemo1 (), alg, 250 )
505521 t_loop = @elapsed res = sample (vdemo1 (Float64), alg, 250 )
506- t_loop = @elapsed res = sample (vdemo1 (T= Float64), alg, 250 )
522+
523+ vdemo1kw (; T) = vdemo1 (T)
524+ t_loop = @elapsed res = sample (vdemo1kw (T = Float64), alg, 250 )
507525
508526 @model vdemo2 (:: Type{T} = Float64) where {T <: Real } = begin
509527 x = Vector {T} (undef, N)
512530
513531 t_vec = @elapsed res = sample (vdemo2 (), alg, 250 )
514532 t_vec = @elapsed res = sample (vdemo2 (Float64), alg, 250 )
515- t_vec = @elapsed res = sample (vdemo2 (T= Float64), alg, 250 )
533+
534+ vdemo2kw (; T) = vdemo2 (T)
535+ t_vec = @elapsed res = sample (vdemo2kw (T = Float64), alg, 250 )
516536
517537 @model vdemo3 (:: Type{TV} = Vector{Float64}) where {TV <: AbstractVector } = begin
518538 x = TV (undef, N)
521541
522542 sample (vdemo3 (), alg, 250 )
523543 sample (vdemo3 (Vector{Float64}), alg, 250 )
524- sample (vdemo3 (TV= Vector{Float64}), alg, 250 )
544+
545+ vdemo3kw (; T) = vdemo3 (T)
546+ sample (vdemo3kw (T = Vector{Float64}), alg, 250 )
525547 end
526548 @testset " var name splitting" begin
527549 var_expr = :(x)
0 commit comments