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
285300 chain = sample (gauss (x), PG (10 ), 10 )
286301 chain = sample (gauss (x), SMC (), 10 )
287302
288- @model gauss2 (x, :: Type{TV} = Vector{Float64}) where {TV} = begin
303+ @model function gauss2 (:: Type{TV} = Vector{Float64}; x ) where {TV}
289304 priors = TV (undef, 2 )
290305 priors[1 ] ~ InverseGamma (2 ,3 ) # s
291306 priors[2 ] ~ Normal (0 , sqrt (priors[1 ])) # m
@@ -295,10 +310,11 @@ end
295310 priors
296311 end
297312
298- chain = sample (gauss2 (x), PG (10 ), 10 )
299- chain = sample (gauss2 (x= x, TV= Vector{Float64}), PG (10 ), 10 )
300- chain = sample (gauss2 (x), SMC (), 10 )
301- chain = sample (gauss2 (x= x, TV= Vector{Float64}), SMC (), 10 )
313+ chain = sample (gauss2 (x = x), PG (10 ), 10 )
314+ chain = sample (gauss2 (x = x), SMC (), 10 )
315+
316+ chain = sample (gauss2 (Vector{Float64}; x = x), PG (10 ), 10 )
317+ chain = sample (gauss2 (Vector{Float64}; x = x), SMC (), 10 )
302318 end
303319 @testset " new interface" begin
304320 obs = [0 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ]
513529 setchunksize (N)
514530 alg = HMC (0.01 , 5 )
515531 x = randn (1000 )
516- @model vdemo1 (:: Type{T} = Float64) where {T} = begin
532+ @model function vdemo1 (:: Type{T} = Float64) where {T}
517533 x = Vector {T} (undef, N)
518534 for i = 1 : N
519535 x[i] ~ Normal (0 , sqrt (4 ))
522538
523539 t_loop = @elapsed res = sample (vdemo1 (), alg, 250 )
524540 t_loop = @elapsed res = sample (vdemo1 (Float64), alg, 250 )
525- t_loop = @elapsed res = sample (vdemo1 (T= Float64), alg, 250 )
541+
542+ vdemo1kw (; T) = vdemo1 (T)
543+ t_loop = @elapsed res = sample (vdemo1kw (T = Float64), alg, 250 )
526544
527545 @model vdemo2 (:: Type{T} = Float64) where {T <: Real } = begin
528546 x = Vector {T} (undef, N)
531549
532550 t_vec = @elapsed res = sample (vdemo2 (), alg, 250 )
533551 t_vec = @elapsed res = sample (vdemo2 (Float64), alg, 250 )
534- t_vec = @elapsed res = sample (vdemo2 (T= Float64), alg, 250 )
552+
553+ vdemo2kw (; T) = vdemo2 (T)
554+ t_vec = @elapsed res = sample (vdemo2kw (T = Float64), alg, 250 )
535555
536556 @model vdemo3 (:: Type{TV} = Vector{Float64}) where {TV <: AbstractVector } = begin
537557 x = TV (undef, N)
540560
541561 sample (vdemo3 (), alg, 250 )
542562 sample (vdemo3 (Vector{Float64}), alg, 250 )
543- sample (vdemo3 (TV= Vector{Float64}), alg, 250 )
563+
564+ vdemo3kw (; T) = vdemo3 (T)
565+ sample (vdemo3kw (T = Vector{Float64}), alg, 250 )
544566 end
545567 @testset " var name splitting" begin
546568 var_expr = :(x)
0 commit comments