Skip to content

Commit b29374e

Browse files
authored
Merge pull request #843 from stan-dev/fix-old-array-syntax
Compatibility fixes for cmdstan 2.33+
2 parents 5e2551c + 1caa732 commit b29374e

19 files changed

+61
-188
lines changed

R/example.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ print_example_program <-
124124
#' stan_program <- "
125125
#' data {
126126
#' int<lower=0> N;
127-
#' int<lower=0,upper=1> y[N];
127+
#' array[N] int<lower=0,upper=1> y;
128128
#' }
129129
#' parameters {
130130
#' real<lower=0,upper=1> theta;

R/fit.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ CmdStanFit$set("public", name = "return_codes", value = return_codes)
11581158
#' mcmc_program <- write_stan_file(
11591159
#' 'data {
11601160
#' int<lower=0> N;
1161-
#' int<lower=0,upper=1> y[N];
1161+
#' array[N] int<lower=0,upper=1> y;
11621162
#' }
11631163
#' parameters {
11641164
#' real<lower=0,upper=1> theta;
@@ -1169,7 +1169,7 @@ CmdStanFit$set("public", name = "return_codes", value = return_codes)
11691169
#' }
11701170
#' }
11711171
#' generated quantities {
1172-
#' int y_rep[N];
1172+
#' array[N] int y_rep;
11731173
#' profile("gq") {
11741174
#' y_rep = bernoulli_rng(rep_vector(theta, N));
11751175
#' }

R/model.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ CmdStanModel$set("public", name = "variables", value = variables)
806806
#' file <- write_stan_file("
807807
#' data {
808808
#' int N;
809-
#' int y[N];
809+
#' array[N] int y;
810810
#' }
811811
#' parameters {
812812
#' // should have <lower=0> but omitting to demonstrate pedantic mode
@@ -932,7 +932,7 @@ CmdStanModel$set("public", name = "check_syntax", value = check_syntax)
932932
#' file <- write_stan_file("
933933
#' data {
934934
#' int N;
935-
#' int y[N];
935+
#' array[N] int y;
936936
#' }
937937
#' parameters {
938938
#' real lambda;
@@ -1659,7 +1659,7 @@ CmdStanModel$set("public", name = "variational", value = variational)
16591659
#' mcmc_program <- write_stan_file(
16601660
#' "data {
16611661
#' int<lower=0> N;
1662-
#' int<lower=0,upper=1> y[N];
1662+
#' array[N] int<lower=0,upper=1> y;
16631663
#' }
16641664
#' parameters {
16651665
#' real<lower=0,upper=1> theta;
@@ -1678,13 +1678,13 @@ CmdStanModel$set("public", name = "variational", value = variational)
16781678
#' gq_program <- write_stan_file(
16791679
#' "data {
16801680
#' int<lower=0> N;
1681-
#' int<lower=0,upper=1> y[N];
1681+
#' array[N] int<lower=0,upper=1> y;
16821682
#' }
16831683
#' parameters {
16841684
#' real<lower=0,upper=1> theta;
16851685
#' }
16861686
#' generated quantities {
1687-
#' int y_rep[N] = bernoulli_rng(rep_vector(theta, N));
1687+
#' array[N] int y_rep = bernoulli_rng(rep_vector(theta, N));
16881688
#' }"
16891689
#' )
16901690
#'

R/utils.R

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,20 @@ get_standalone_hpp <- function(stan_file, stancflags) {
816816

817817
get_function_name <- function(fun_start, fun_end, model_lines) {
818818
fun_string <- paste(model_lines[(fun_start+1):fun_end], collapse = " ")
819-
fun_name <- gsub("auto ", "", fun_string, fixed = TRUE)
819+
types <- c(
820+
"auto",
821+
"int",
822+
"double",
823+
"Eigen::Matrix<(.*)>",
824+
"std::vector<(.*)>"
825+
)
826+
pattern <- paste0(
827+
# Only match if the type occurs at start of string
828+
"^(\\s*)?(",
829+
paste0(types, collapse="|"),
830+
# Only match if type followed by a function name and opening bracket
831+
")\\s*(?=\\w*\\()")
832+
fun_name <- gsub(pattern, "", fun_string, perl = TRUE)
820833
sub("\\(.*", "", fun_name, perl = TRUE)
821834
}
822835

@@ -864,7 +877,9 @@ get_plain_rtn <- function(fun_start, fun_end, model_lines) {
864877
# that instantiates an RNG
865878
prep_fun_cpp <- function(fun_start, fun_end, model_lines) {
866879
fun_body <- paste(model_lines[fun_start:fun_end], collapse = " ")
867-
fun_body <- gsub("auto", get_plain_rtn(fun_start, fun_end, model_lines), fun_body)
880+
if (cmdstan_version() < "2.33") {
881+
fun_body <- gsub("auto", get_plain_rtn(fun_start, fun_end, model_lines), fun_body)
882+
}
868883
fun_body <- gsub("// [[stan::function]]", "// [[Rcpp::export]]\n", fun_body, fixed = TRUE)
869884
fun_body <- gsub("std::ostream\\*\\s*pstream__\\s*=\\s*nullptr", "", fun_body)
870885
fun_body <- gsub("boost::ecuyer1988&\\s*base_rng__", "SEXP base_rng_ptr", fun_body)

_pkgdown.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ articles:
7272
- cmdstanr-internals
7373
- posterior
7474
- r-markdown
75-
- deprecations
7675
- profiling
7776
- articles-online-only/opencl
7877

man/CmdStanGQ.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/fit-method-profiles.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/model-method-check_syntax.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/model-method-format.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/model-method-generate-quantities.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)