-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2147 from stan-dev/bugfix/issue-2146-compound-dec…
…lare-define-matrix Fixes #2146. Bugfix/issue 2146 compound declare define matrix
- Loading branch information
Showing
8 changed files
with
605 additions
and
343 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
152 changes: 120 additions & 32 deletions
152
src/test/test-models/good/declare-define-var-double.stan
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 |
---|---|---|
@@ -1,67 +1,155 @@ | ||
functions { | ||
real foo() { | ||
real lf1 = 1; // real_d <- int_d | ||
real lf2 = 2.0; // real_d <- real_d | ||
real lf3[5]; | ||
real lf4[5] = lf3; | ||
real foo(real a1) { | ||
int lf0 = 2; | ||
real lf1 = a1; | ||
real lf2 = lf1; | ||
real lf3[lf0]; | ||
real lf4[lf0] = lf3; | ||
print("foo, lf1: ", lf1); | ||
print("foo, lf2: ", lf1); | ||
print("foo, lf4: ", lf4); | ||
lf1 = lf3[1] + lf4[1]; | ||
return lf1; | ||
} | ||
} | ||
data { | ||
int<lower=0> N; | ||
int<lower=0,upper=1> y[N]; | ||
real d[3,3]; | ||
} | ||
transformed data { | ||
real td1 = 1; // real_d <- int_d | ||
int td0 = 3; | ||
real td1 = 123; // real_d <- int_d | ||
real td2 = 2.0; // real_d <- real_d | ||
real td3 = td0; | ||
real td4 = td3; | ||
real td_a1[3]; | ||
real td_a2[3] = td_a1; // real_arr_d <- real_arr_d | ||
td1 = 2; | ||
|
||
// local variables | ||
real td5 = td_a2[1]; | ||
real td_a3[3, 3] = d; | ||
real td_a4[3] = td_a3[2]; | ||
print("td1: ",td1); | ||
print("td2: ",td2); | ||
print("td3: ",td3); | ||
print("td4: ",td4); | ||
print("td5: ",td5); | ||
print("td_a2: ",td_a2); | ||
print("td_a4: ",td_a4); | ||
{ | ||
real ltd1 = 1; // real_d <- int_d | ||
real ltd2 = 2.0; // real_d <- real_d | ||
real ltd3[4]; | ||
real ltd4[4] = ltd3; | ||
ltd1 = 5; | ||
real ltd3 = td1; | ||
real ltd4[td0]; | ||
real ltd5[td0] = ltd4; | ||
print("ltd1: ",ltd1); | ||
print("ltd2: ",ltd2); | ||
print("ltd3: ",ltd3); | ||
print("ltd5: ",ltd5); | ||
} | ||
} | ||
parameters { | ||
real<lower=0,upper=1> theta; | ||
} | ||
transformed parameters { | ||
// block variables | ||
real d_tp1 = 1.0; | ||
real d_tp2 = td1; | ||
real d_tp3 = td0; | ||
real d_tp4 = d[1,2]; | ||
real d_tp_a1[3] = td_a4; | ||
real d_tp_a2[3] = td_a3[1]; | ||
real d_tp_a3[3, 3] = d; | ||
|
||
real p_tp2 = d_tp1; | ||
real p_tp4 = d_tp_a1[1]; | ||
real p_tp_a1[3] = d_tp_a1; | ||
real p_tp_a2[3] = d_tp_a3[3]; | ||
|
||
|
||
real tp1 = 1; // real_p <- int_d | ||
real tp2 = 2.0; // real_p <- real_d | ||
real tp3 = tp2; // real_p <- real_p | ||
real tp4[5]; | ||
real tp5[5] = tp4; | ||
tp3 = tp1 + tp2; | ||
real tp4[td0]; | ||
real tp5[td0] = tp4; | ||
|
||
// local variables | ||
print("d_tp1 = ", d_tp1); | ||
print("d_tp2 = ", d_tp2, " should be td1 = ", td1, " which should be 123"); | ||
print("d_tp3 = ", d_tp3); | ||
print("d_tp4 = ", d_tp4); | ||
print("d_tp_a1 = ", d_tp_a1); | ||
print("d_tp_a2 = ", d_tp_a2); | ||
print("d_tp_a3 = ", d_tp_a3); | ||
|
||
print("p_tp2 = ", p_tp2); | ||
print("p_tp4 = ", p_tp4); | ||
print("p_tp_a1 = ", p_tp_a1); | ||
print("p_tp_a2 = ", p_tp_a2); | ||
|
||
print("tp1: ",tp1); | ||
print("tp2: ",tp2); | ||
print("tp3: ",tp3); | ||
print("tp5: ",tp5); | ||
tp1 = foo(tp3); | ||
print("tp1: ",tp1); | ||
{ | ||
real lp1 = 1; // real_p <- int_d | ||
real lp2 = 2.0; // real_p <- real_d | ||
real lp1 = td0; // real_p <- int_d | ||
real lp2 = 9.0; // real_p <- real_d | ||
real lp3 = tp2; // real_p <- real_p | ||
real lp4[6]; | ||
real lp5[6] = lp4; | ||
lp3 = lp1 + lp2; | ||
real lp4[td0]; | ||
real lp5[td0] = lp4; | ||
print("lp1: ",lp1); | ||
print("lp2: ",lp2); | ||
print("lp3: ",lp3); | ||
print("lp5: ",lp5); | ||
} | ||
} | ||
model { | ||
// local variables | ||
real lm1 = 1; // real_p <- int_d | ||
real lm2 = 2.0; // real_p <- real_d | ||
real lm3 = tp2; // real_p <- real_p | ||
lm3 = lm1 + lm2; | ||
theta ~ beta(1,1); | ||
for (n in 1:N) | ||
y[n] ~ bernoulli(theta); | ||
} | ||
generated quantities { | ||
real gq1 = 1; // real_d <- int_d | ||
real gq2 = 2.0; // real_d <- real_d | ||
real gq3[7]; | ||
real gq4[7] = gq3; | ||
gq2 = 5.0; | ||
real gq_d_tp1 = 1.0; | ||
real gq_d_tp2 = td1; | ||
real gq_d_tp3 = td0; | ||
real gq_d_tp4 = d[1,2]; | ||
real gq_d_tp_a1[3] = td_a4; | ||
real gq_d_tp_a2[3] = td_a3[1]; | ||
real gq_d_tp_a3[3, 3] = d; | ||
|
||
real gq_p_tp2 = d_tp1; | ||
real gq_p_tp4 = d_tp_a1[1]; | ||
real gq_p_tp_a1[3] = d_tp_a1; | ||
real gq_p_tp_a2[3] = d_tp_a3[3]; | ||
print("gq_d_tp1 = ", gq_d_tp1); | ||
print("gq_d_tp2 = ", gq_d_tp2, " should be td1 = ", td1, " which should be 123"); | ||
print("gq_d_tp3 = ", gq_d_tp3); | ||
print("gq_d_tp4 = ", gq_d_tp4); | ||
print("gq_d_tp_a1 = ", gq_d_tp_a1); | ||
print("gq_d_tp_a2 = ", gq_d_tp_a2); | ||
print("gq_d_tp_a3 = ", gq_d_tp_a3); | ||
|
||
print("gq_p_tp2 = ", gq_p_tp2); | ||
print("gq_p_tp4 = ", gq_p_tp4); | ||
print("gq_p_tp_a1 = ", gq_p_tp_a1); | ||
print("gq_p_tp_a2 = ", gq_p_tp_a2); | ||
{ | ||
real lgq1 = 1; // real_d <- int_d | ||
real lgq2 = 2.0; // real_d <- real_d | ||
real lgq3; | ||
real lgq4[8]; | ||
real lgq5[8] = lgq4; | ||
lgq3 = lgq1 + lgq2; | ||
real lqd2a = lgq2; | ||
real lgq3[td0]; | ||
real lgq3a = lgq3[1]; | ||
real lgq4[td0] = lgq3; | ||
real lgq5[3] = d[1]; | ||
print("lgq1: ",lgq1); | ||
print("lgq2: ",lgq2); | ||
print("lgq2a: ",lqd2a); | ||
print("lgq3: ",lgq3); | ||
print("lgq3a: ",lgq3a); | ||
print("lgq4: ",lgq4); | ||
print("lgq5: ",lgq5); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,29 +1,51 @@ | ||
functions { | ||
int foo() { | ||
int lf1 = 1; | ||
int lf1 = 3; | ||
print("foo ",lf1); | ||
return lf1; | ||
} | ||
} | ||
data { | ||
int n; | ||
int d[n,n]; | ||
} | ||
transformed data { | ||
int td1 = 1; | ||
int td_a1[5]; | ||
int td_a2[5] = td_a1; | ||
int td2 = td1; | ||
int td_a1[n] = d[1]; | ||
int td_a2[n] = td_a1; | ||
int td_a3[n,n] = d; | ||
int td_a4[n] = td_a3[n]; | ||
int td3 = td_a3[2,2]; | ||
print("td1 = ", td1); | ||
print("td2 = ", td2); | ||
print("td3 = ", td3); | ||
print("td_a3 = ", td_a3); | ||
print("transformed data td2 ",td2); | ||
print("transformed data td_a2 ",td_a2); | ||
print("transformed data td_a4 ",td_a4); | ||
|
||
} | ||
transformed parameters { | ||
real p1; | ||
{ | ||
int lp1 = 1; | ||
print("transformed param ",lp1); | ||
} | ||
} | ||
model { | ||
// local variables | ||
int lm1 = 1; | ||
int lm1 = 4; | ||
print("local int ",lm1); | ||
print(foo()); | ||
} | ||
generated quantities { | ||
int gq1 = 1; | ||
print("gq1 ",gq1); | ||
gq1 = 2; | ||
{ | ||
int lgq1 = 1; | ||
int lgq1 = 2; | ||
print("gq2 ",lgq1); | ||
lgq1 = 2; | ||
} | ||
} |
Oops, something went wrong.