Skip to content

Commit 43e8eee

Browse files
committed
Remove another eval and run .~ also on Julia 1.0
1 parent f04950d commit 43e8eee

File tree

1 file changed

+52
-55
lines changed

1 file changed

+52
-55
lines changed

test/compiler.jl

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -381,78 +381,75 @@ priors = 0 # See "new grammar" test.
381381
sample(vdemo7(), alg, 1000)
382382
end
383383

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
393392

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)
397396

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
403402

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)
406405

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)
411410

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))
417415
end
416+
end
418417

419-
t_loop = @elapsed res = sample(vdemo3(), alg, 1000)
418+
t_loop = @elapsed res = sample(vdemo3(), alg, 1000)
420419

421-
# Test for vectorize UnivariateDistribution
422-
@model vdemo4() = begin
420+
# Test for vectorize UnivariateDistribution
421+
@model vdemo4() = begin
423422
x = Vector{Real}(undef, N)
424-
x .~ Normal(0, 2)
425-
end
423+
(.~)(x, Normal(0, 2))
424+
end
426425

427-
t_vec = @elapsed res = sample(vdemo4(), alg, 1000)
426+
t_vec = @elapsed res = sample(vdemo4(), alg, 1000)
428427

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
432431

433-
t_mv = @elapsed res = sample(vdemo5(), alg, 1000)
432+
t_mv = @elapsed res = sample(vdemo5(), alg, 1000)
434433

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")
439438

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
445444

446-
sample(vdemo6(), alg, 1000)
445+
sample(vdemo6(), alg, 1000)
447446

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])
454450
end
455-
""" |> Meta.parse |> eval
451+
452+
sample(vdemo7(), alg, 1000)
456453
end
457454

458455
@testset "Type parameters" begin

0 commit comments

Comments
 (0)