@@ -381,78 +381,75 @@ priors = 0 # See "new grammar" test.
381
381
sample (vdemo7 (), alg, 1000 )
382
382
end
383
383
384
- if VERSION >= v " 1.1"
385
- """
386
- @testset "vectorization .~" begin
387
- @model vdemo1(x) = begin
388
- s ~ InverseGamma(2,3)
389
- m ~ Normal(0, sqrt(s))
390
- x .~ Normal(m, sqrt(s))
391
- return s, m
392
- end
384
+ # Notation is ugly since `x .~ Normal(μ, σ)` cannot be parsed in Julia 1.0
385
+ @testset " vectorization .~" begin
386
+ @model vdemo1 (x) = begin
387
+ s ~ InverseGamma (2 ,3 )
388
+ m ~ Normal (0 , sqrt (s))
389
+ (.~ )(x, Normal (m, sqrt (s)))
390
+ return s, m
391
+ end
393
392
394
- alg = HMC(0.01, 5)
395
- x = randn(100)
396
- res = sample(vdemo1(x), alg, 250)
393
+ alg = HMC (0.01 , 5 )
394
+ x = randn (100 )
395
+ res = sample (vdemo1 (x), alg, 250 )
397
396
398
- D = 2
399
- @model vdemo2(x) = begin
400
- μ ~ MvNormal(zeros(D), ones(D))
401
- x .~ MvNormal(μ, ones(D))
402
- end
397
+ D = 2
398
+ @model vdemo2 (x) = begin
399
+ μ ~ MvNormal (zeros (D), ones (D))
400
+ ( .~ )(x, MvNormal (μ, ones (D) ))
401
+ end
403
402
404
- alg = HMC(0.01, 5)
405
- res = sample(vdemo2(randn(D,100)), alg, 250)
403
+ alg = HMC (0.01 , 5 )
404
+ res = sample (vdemo2 (randn (D,100 )), alg, 250 )
406
405
407
- # Vector assumptions
408
- N = 10
409
- setchunksize(N)
410
- alg = HMC(0.2, 4)
406
+ # Vector assumptions
407
+ N = 10
408
+ setchunksize (N)
409
+ alg = HMC (0.2 , 4 )
411
410
412
- @model vdemo3() = begin
413
- x = Vector{Real}(undef, N)
414
- for i = 1:N
415
- x[i] ~ Normal(0, sqrt(4))
416
- end
411
+ @model vdemo3 () = begin
412
+ x = Vector {Real} (undef, N)
413
+ for i = 1 : N
414
+ x[i] ~ Normal (0 , sqrt (4 ))
417
415
end
416
+ end
418
417
419
- t_loop = @elapsed res = sample(vdemo3(), alg, 1000)
418
+ t_loop = @elapsed res = sample (vdemo3 (), alg, 1000 )
420
419
421
- # Test for vectorize UnivariateDistribution
422
- @model vdemo4() = begin
420
+ # Test for vectorize UnivariateDistribution
421
+ @model vdemo4 () = begin
423
422
x = Vector {Real} (undef, N)
424
- x .~ Normal(0, 2)
425
- end
423
+ ( .~ )(x, Normal (0 , 2 ) )
424
+ end
426
425
427
- t_vec = @elapsed res = sample(vdemo4(), alg, 1000)
426
+ t_vec = @elapsed res = sample (vdemo4 (), alg, 1000 )
428
427
429
- @model vdemo5() = begin
430
- x ~ MvNormal(zeros(N), 2 * ones(N))
431
- end
428
+ @model vdemo5 () = begin
429
+ x ~ MvNormal (zeros (N), 2 * ones (N))
430
+ end
432
431
433
- t_mv = @elapsed res = sample(vdemo5(), alg, 1000)
432
+ t_mv = @elapsed res = sample (vdemo5 (), alg, 1000 )
434
433
435
- println("Time for")
436
- println(" Loop : \$ t_loop")
437
- println(" Vec : \$ t_vec")
438
- println(" Mv : \$ t_mv")
434
+ println (" Time for" )
435
+ println (" Loop : \$ t_loop" )
436
+ println (" Vec : \$ t_vec" )
437
+ println (" Mv : \$ t_mv" )
439
438
440
- # Transformed test
441
- @model vdemo6() = begin
442
- x = Vector{Real}(undef, N)
443
- x .~ InverseGamma(2, 3)
444
- end
439
+ # Transformed test
440
+ @model vdemo6 () = begin
441
+ x = Vector {Real} (undef, N)
442
+ ( .~ )(x, InverseGamma (2 , 3 ) )
443
+ end
445
444
446
- sample(vdemo6(), alg, 1000)
445
+ sample (vdemo6 (), alg, 1000 )
447
446
448
- @model vdemo7() = begin
449
- x = Array{Real}(undef, N, N)
450
- x .~ [InverseGamma(2, 3) for i in 1:N]
451
- end
452
-
453
- sample(vdemo7(), alg, 1000)
447
+ @model vdemo7 () = begin
448
+ x = Array {Real} (undef, N, N)
449
+ (.~ )(x, [InverseGamma (2 , 3 ) for i in 1 : N])
454
450
end
455
- """ |> Meta. parse |> eval
451
+
452
+ sample (vdemo7 (), alg, 1000 )
456
453
end
457
454
458
455
@testset " Type parameters" begin
0 commit comments