-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename parse_indexing() to varname()
- Loading branch information
Showing
2 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Distributions | ||
using ForwardDiff: Dual | ||
using Turing | ||
using Turing: varname | ||
using Base.Test | ||
|
||
# Symbol | ||
v_sym = string(:x) | ||
@test v_sym == "x" | ||
|
||
# Array | ||
i = 1 | ||
v_arr = eval(varname(:(x[i]))) | ||
@test v_arr == "x[1]" | ||
|
||
# Matrix | ||
i, j = 1, 2 | ||
v_mat = eval(varname(:(x[i,j]))) | ||
@test v_mat== "x[1,2]" | ||
|
||
@model mat_name_test begin | ||
p = Array{Dual}((2, 2)) | ||
for i in 1:2, j in 1:2 | ||
p[i,j] ~ Normal(0, 1) | ||
end | ||
p | ||
end | ||
chain = sample(mat_name_test, HMC(1000, 0.75, 2)) | ||
@test_approx_eq_eps mean(mean(chain[:p])) 0 0.25 | ||
|
||
# Multi array | ||
i, j = 1, 2 | ||
v_arrarr = eval(varname(:(x[i][j]))) | ||
@test v_arrarr == "x[1][2]" | ||
|
||
@model marr_name_test begin | ||
p = Array{Array{Dual}}(2) | ||
p[1] = Array{Dual}(2) | ||
p[2] = Array{Dual}(2) | ||
for i in 1:2, j in 1:2 | ||
p[i][j] ~ Normal(0, 1) | ||
end | ||
p | ||
end | ||
chain = sample(marr_name_test, HMC(1000, 0.75, 2)) | ||
@test_approx_eq_eps mean(mean(mean(chain[:p]))) 0 0.25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters