diff --git a/R/data.R b/R/data.R index a1e4ab7c..a9438bc0 100644 --- a/R/data.R +++ b/R/data.R @@ -20,16 +20,16 @@ #' The `list` to `array` conversion is intended to make it easier to prepare #' the data for certain Stan declarations involving arrays: #' -#' * `vector[J] v[K]` (or equivalently `array[K] vector[J] v ` as of Stan 2.27) +#' * `array[K] vector[J] v` (or equivalently `array[K] vector[J] v ` as of Stan 2.27) #' can be constructed in \R as a list with `K` elements where each element a #' vector of length `J` -#' * `matrix[I,J] v[K]` (or equivalently `array[K] matrix[I,J] m ` as of Stan +#' * `array[K] matrix[I,J] v` (or equivalently `array[K] matrix[I,J] m ` as of Stan #' 2.27 ) can be constructed in \R as a list with `K` elements where each element #' an `IxJ` matrix #' #' These can also be passed in from \R as arrays instead of lists but the list #' option is provided for convenience. Unfortunately for arrays with more than -#' one dimension, e.g., `vector[J] v[K,L]` (or equivalently +#' one dimension, e.g., `array[K,L] vector[J] v` (or equivalently #' `array[K,L] vector[J] v ` as of Stan 2.27) it is not possible to use an \R #' list and an array must be used instead. For this example the array in \R #' should have dimensions `KxLxJ`. @@ -49,7 +49,7 @@ #' #' #' # demonstrating list to array conversion -#' # suppose x is declared as `vector[3] x[2]` (or equivalently `array[2] vector[3] x`) +#' # suppose x is declared as `array[2] vector[3] x` (or equivalently `array[2] vector[3] x`) #' # we can use a list of length 2 where each element is a vector of length 3 #' data <- list(x = list(1:3, 4:6)) #' file <- tempfile(fileext = ".json") diff --git a/R/example.R b/R/example.R index bb9b371d..f322185f 100644 --- a/R/example.R +++ b/R/example.R @@ -124,7 +124,7 @@ print_example_program <- #' stan_program <- " #' data { #' int N; -#' int y[N]; +#' array[N] int y; #' } #' parameters { #' real theta; diff --git a/R/model.R b/R/model.R index 96cb99ca..14871b91 100644 --- a/R/model.R +++ b/R/model.R @@ -932,7 +932,7 @@ CmdStanModel$set("public", name = "check_syntax", value = check_syntax) #' file <- write_stan_file(" #' data { #' int N; -#' int y[N]; +#' array[N] int y; #' } #' parameters { #' real lambda; diff --git a/man/model-method-format.Rd b/man/model-method-format.Rd index 1d7ed11b..57944b58 100644 --- a/man/model-method-format.Rd +++ b/man/model-method-format.Rd @@ -49,7 +49,7 @@ model directly back to the file or prints it for inspection. file <- write_stan_file(" data { int N; - int y[N]; + array[N] int y; } parameters { real lambda; diff --git a/man/write_stan_file.Rd b/man/write_stan_file.Rd index cdb5cbc7..d172cf70 100644 --- a/man/write_stan_file.Rd +++ b/man/write_stan_file.Rd @@ -51,7 +51,7 @@ should ensure thread-safety in the rare cases when it is needed. stan_program <- " data { int N; - int y[N]; + array[N] int y; } parameters { real theta; diff --git a/man/write_stan_json.Rd b/man/write_stan_json.Rd index cc41c598..c76d4db5 100644 --- a/man/write_stan_json.Rd +++ b/man/write_stan_json.Rd @@ -32,17 +32,17 @@ file: The \code{list} to \code{array} conversion is intended to make it easier to prepare the data for certain Stan declarations involving arrays: \itemize{ -\item \verb{vector[J] v[K]} (or equivalently \verb{array[K] vector[J] v } as of Stan 2.27) +\item \verb{array[K] vector[J] v} (or equivalently \verb{array[K] vector[J] v } as of Stan 2.27) can be constructed in \R as a list with \code{K} elements where each element a vector of length \code{J} -\item \verb{matrix[I,J] v[K]} (or equivalently \verb{array[K] matrix[I,J] m } as of Stan +\item \verb{array[K] matrix[I,J] v} (or equivalently \verb{array[K] matrix[I,J] m } as of Stan 2.27 ) can be constructed in \R as a list with \code{K} elements where each element an \code{IxJ} matrix } These can also be passed in from \R as arrays instead of lists but the list option is provided for convenience. Unfortunately for arrays with more than -one dimension, e.g., \verb{vector[J] v[K,L]} (or equivalently +one dimension, e.g., \verb{array[K,L] vector[J] v} (or equivalently \verb{array[K,L] vector[J] v } as of Stan 2.27) it is not possible to use an \R list and an array must be used instead. For this example the array in \R should have dimensions \code{KxLxJ}. @@ -62,7 +62,7 @@ cat(readLines(file), sep = "\n") # demonstrating list to array conversion -# suppose x is declared as `vector[3] x[2]` (or equivalently `array[2] vector[3] x`) +# suppose x is declared as `array[2] vector[3] x` (or equivalently `array[2] vector[3] x`) # we can use a list of length 2 where each element is a vector of length 3 data <- list(x = list(1:3, 4:6)) file <- tempfile(fileext = ".json") diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R index bae7b49e..01fa7291 100644 --- a/tests/testthat/test-data.R +++ b/tests/testthat/test-data.R @@ -339,7 +339,7 @@ test_that("process_data() corrrectly casts integers and floating point numbers", stan_file <- write_stan_file(" data { - int k[3,3]; + array[3,3] int k; } ") mod <- cmdstan_model(stan_file, compile = FALSE) diff --git a/tests/testthat/test-example.R b/tests/testthat/test-example.R index 842a3075..8d14d5d0 100644 --- a/tests/testthat/test-example.R +++ b/tests/testthat/test-example.R @@ -23,7 +23,7 @@ test_that("cmdstanr_example works", { stan_program <- " data { int N; - int y[N]; + array[N] int y; } parameters { real theta; diff --git a/tests/testthat/test-fit-shared.R b/tests/testthat/test-fit-shared.R index a7ed1078..193a9664 100644 --- a/tests/testthat/test-fit-shared.R +++ b/tests/testthat/test-fit-shared.R @@ -308,7 +308,7 @@ test_that("sig_figs works with all methods", { m <- "data { int N; int K; - int y[N]; + array[N] int y; matrix[N, K] X; } parameters { diff --git a/tests/testthat/test-model-sample_mpi.R b/tests/testthat/test-model-sample_mpi.R index 6b348f2e..1ea0f9a6 100644 --- a/tests/testthat/test-model-sample_mpi.R +++ b/tests/testthat/test-model-sample_mpi.R @@ -4,15 +4,15 @@ test_that("sample_mpi() works", { skip_if(!mpi_toolchain_present()) mpi_file <- write_stan_file(" functions { - vector test(vector beta, vector theta, real[] x, int[] y) { + vector test(vector beta, vector theta, array[] real x, array[] int y) { return theta; } } transformed data { vector[4] a; - vector[5] b[4] = {[1,1,1,1,1]', [2,2,2,2,2]', [3,3,3,3,3]', [4,4,4,4,4]'}; - real x[4,4]; - int y[4,4]; + array[4] vector[5] b = {[1,1,1,1,1]', [2,2,2,2,2]', [3,3,3,3,3]', [4,4,4,4,4]'}; + array[4,4] real x; + array[4,4] int y; } parameters { real beta;