Skip to content

Commit

Permalink
test: Update Stan syntax
Browse files Browse the repository at this point in the history
Update Stan code, adjust code using deprecated syntax.
  • Loading branch information
riddell-stan committed Dec 13, 2023
1 parent d7cd565 commit 04224da
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 33 deletions.
2 changes: 1 addition & 1 deletion tests/test_eight_schools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
array[J] real eta;
}
transformed parameters {
real theta[J];
array[J] real theta;
for (j in 1:J)
theta[j] = mu + tau * eta[j];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fit_basic_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
model {
for (k in 1:K)
for (d in 1:D)
beta[k,d] ~ normal(if_else(d==2, 5, 0), 0.000001);
beta[k,d] ~ normal(d==2 ? 5 : 0, 0.000001);
}
"""
K, D = 3, 4
Expand Down
21 changes: 10 additions & 11 deletions tests/test_fit_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,36 @@
array[L, M] real B;
vector[N] c;
matrix[O, P] D;
matrix[R, S] E[Q];
array[Q] matrix[R, S] E;
}
model {
for (k in 1:K) {
for (k in 1 : K) {
a[k] ~ std_normal();
}
for (l in 1:L) {
for (m in 1:M) {
for (l in 1 : L) {
for (m in 1 : M) {
B[l, m] ~ std_normal();
}
}
for (n in 1:N) {
for (n in 1 : N) {
c[n] ~ std_normal();
}
for (o in 1:O) {
for (p in 1:P) {
for (o in 1 : O) {
for (p in 1 : P) {
D[o, p] ~ std_normal();
}
}
for (q in 1:Q) {
for (r in 1:R) {
for (s in 1:S) {
for (q in 1 : Q) {
for (r in 1 : R) {
for (s in 1 : S) {
E[q, r, s] ~ std_normal();
}
}
}
}
"""
num_samples = 100
Expand Down
20 changes: 0 additions & 20 deletions tests/test_stanc_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,3 @@ def test_stanc_unused_warning() -> None:
with contextlib.redirect_stderr(buffer):
stan.build(program_code=program_code)
assert "The parameter y was declared but was not used in the density" in buffer.getvalue()


def test_stanc_assignment_warning() -> None:
"""Test that stanc warning is shown to user."""
# stanc prints warning:
# assignment operator <- is deprecated in the Stan language; use = instead.
program_code = """
parameters {
real y;
}
model {
real x;
x <- 5;
y ~ normal(0,1);
}
"""
buffer = io.StringIO()
with contextlib.redirect_stderr(buffer):
stan.build(program_code=program_code)
assert "operator <- is deprecated in the Stan language and will be removed" in buffer.getvalue(), buffer.getvalue()

0 comments on commit 04224da

Please sign in to comment.