Skip to content

Commit

Permalink
rstan: Fix the deprecated array syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbadr committed Sep 10, 2023
1 parent bf1daf2 commit 8417f36
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion rstan/rstan/R/misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ remove_empty_pars <- function(pars, model_dims) {
# following stan model code:
#
# transformed data { int n; n <- 0; }
# parameters { real y[n]; }
# parameters { array[n] real y; }
#
# Args:
# pars: a character vector of parameters names
Expand Down
2 changes: 1 addition & 1 deletion rstan/rstan/man/rstan.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
stanmodelcode <- "
data {
int<lower=0> N;
real y[N];
array[N] real y;
}
parameters {
Expand Down
4 changes: 2 additions & 2 deletions rstan/rstan/man/sflist2stanfit.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ data {
int<lower=1> N;
}
parameters {
real y1[N];
real y2[N];
array[N] real y1;
array[N] real y2;
}
model {
y1 ~ normal(0, 1);
Expand Down
6 changes: 3 additions & 3 deletions rstan/rstan/man/stan.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ stan(file, model_name = "anon_model", model_code = "", fit = NA,
}

Stan treats a vector of length 1 in R as a scalar. So technically
if, for example, \code{"real y[1];"} is defined in the data block, an array
if, for example, \code{"array[1] real y;"} is defined in the data block, an array
such as \code{"y = array(1.0, dim = 1)"} in R should be used. This
is also the case for specifying initial values since the same
underlying approach for reading data from R in Stan is used, in which
Expand Down Expand Up @@ -425,7 +425,7 @@ stan(file, model_name = "anon_model", model_code = "", fit = NA,
library(rstan)
scode <- "
parameters {
real y[2];
array[2] real y;
}
model {
y[1] ~ normal(0, 1);
Expand All @@ -447,7 +447,7 @@ e2 <- extract(fit2, permuted = FALSE)

excode <- '
transformed data {
real y[20];
array[20] real y;
y[1] = 0.5796; y[2] = 0.2276; y[3] = -0.2959;
y[4] = -0.3742; y[5] = 0.3885; y[6] = -2.1585;
y[7] = 0.7111; y[8] = 1.4424; y[9] = 2.5430;
Expand Down
2 changes: 1 addition & 1 deletion rstan/rstan/man/stanc.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Translate Stan model specification to C++ code
stanmodelcode <- "
data {
int<lower=0> N;
real y[N];
array[N] real y;
}
parameters {
Expand Down
4 changes: 2 additions & 2 deletions rstan/rstan/man/stanfit-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ summarizing results and various access methods also allow the underlying data
showClass("stanfit")
ecode <- '
parameters {
real<lower=0> y[2];
array[2] real<lower=0> y;
}
model {
y ~ exponential(1);
Expand Down Expand Up @@ -241,7 +241,7 @@ print(y1star) # y1start should equal to y1
#
excode <- '
transformed data {
real y[20];
array[20] real y;
y[1] <- 0.5796; y[2] <- 0.2276; y[3] <- -0.2959;
y[4] <- -0.3742; y[5] <- 0.3885; y[6] <- -2.1585;
y[7] <- 0.7111; y[8] <- 1.4424; y[9] <- 2.5430;
Expand Down
6 changes: 3 additions & 3 deletions rstan/rstan/man/stanfit-method-extract.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
\examples{\dontrun{
ex_model_code <- '
parameters {
real alpha[2,3];
real beta[2];
array[2, 3] real alpha;
array[2] real beta;
}
model {
for (i in 1:2) for (j in 1:3)
Expand Down Expand Up @@ -110,7 +110,7 @@ dimnames(fit_ss2)
#
excode <- '
transformed data {
real y[20];
array[20] real y;
y[1] <- 0.5796; y[2] <- 0.2276; y[3] <- -0.2959;
y[4] <- -0.3742; y[5] <- 0.3885; y[6] <- -2.1585;
y[7] <- 0.7111; y[8] <- 1.4424; y[9] <- 2.5430;
Expand Down
2 changes: 1 addition & 1 deletion rstan/rstan/man/stanfit-method-summary.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ array of MCMC draws as its input rather than a \code{stanfit} object.
\examples{\dontrun{
ecode <- '
parameters {
real<lower=0> y[2];
array[2] real<lower=0> y;
}
model {
y ~ exponential(1);
Expand Down
2 changes: 1 addition & 1 deletion rstan/rstan/man/stanfit-method-traceplot.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#
excode <- '
transformed data {
real y[20];
array[20] real y;
y[1] <- 0.5796; y[2] <- 0.2276; y[3] <- -0.2959;
y[4] <- -0.3742; y[5] <- 0.3885; y[6] <- -2.1585;
y[7] <- 0.7111; y[8] <- 1.4424; y[9] <- 2.5430;
Expand Down
4 changes: 2 additions & 2 deletions rstan/rstan/man/stanfit2array-method.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
\examples{\dontrun{
ex_model_code <- '
parameters {
real alpha[2,3];
real beta[2];
array[2, 3] real alpha;
array[2] real beta;
}
model {
for (i in 1:2) for (j in 1:3)
Expand Down
2 changes: 1 addition & 1 deletion rstan/rstan/tests/testthat/test-partial_inits.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("partial_inits works", {
stan_model_code <- "
data {
int<lower=0> N;
real y[N];
array[N] real y;
}
parameters {
Expand Down
6 changes: 3 additions & 3 deletions rstan/rstan/tests/testthat/test-stan_fun.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("Running stan() in parallel works", {
data {
int N;
} parameters {
real y[N];
array[N] real y;
} model {
y ~ normal(0, 1);
}
Expand Down Expand Up @@ -48,11 +48,11 @@ test_that("stan() arguments works", {
diag_fname2 <- "diag2.csv"
model_code <- "
parameters {
real y[2];
array[2] real y;
real alpha;
}
transformed parameters {
real y2[2, 2];
array[2, 2] real y2;
y2[1, 1] = y[1];
y2[1, 2] = -y[1];
y2[2, 1] = -y[2];
Expand Down
12 changes: 6 additions & 6 deletions rstan/rstan/tests/testthat/test-stanfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ test_that("outputing csv and extracting work", {
n = 0;
}
parameters {
real y[2];
real zeroleny[n];
array[2] real y;
array[n] real zeroleny;
}
transformed parameters {
real y2[2, 2];
array[2, 2] real y2;
y2[1, 1] = y[1];
y2[1, 2] = -y[1];
y2[2, 1] = -y[2];
Expand All @@ -22,7 +22,7 @@ test_that("outputing csv and extracting work", {
y ~ normal(0, 1);
}
generated quantities {
real y3[3, 2, 3];
array[3, 2, 3] real y3;
y3[1,1,1] = 1; y3[1,1,2] = 2; y3[1,1,3] = 3;
y3[1,2,1] = 4; y3[1,2,2] = 5; y3[1,2,3] = 6;
y3[2,1,1] = 7; y3[2,1,2] = 8; y3[2,1,3] = 9;
Expand Down Expand Up @@ -182,7 +182,7 @@ test_that("grad log is correct", {

code <- "
data {
real y[20];
array[20] real y;
}
parameters {
real mu;
Expand Down Expand Up @@ -241,7 +241,7 @@ test_that("Specifying arguments and data works", {
code <- "
data {
int N;
real y[N];
array[N] real y;
}
parameters {
real mu;
Expand Down

0 comments on commit 8417f36

Please sign in to comment.