Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ read_csv_metadata <- function(csv_file) {
dense_inv_metric <- TRUE
} else if (inv_metric_next) {
inv_metric_split <- strsplit(gsub("# ", "", line), ",")
numeric_inv_metric_split <- rapply(inv_metric_split, as.numeric)
numeric_inv_metric_split <- suppressWarnings(rapply(inv_metric_split, as.numeric))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the model has no parameters but fixed_param is FALSE this would produce warnings. Simplest thing to do is just suppress.

if (inv_metric_rows == -1 && dense_inv_metric) {
inv_metric_rows <- length(inv_metric_split[[1]])
inv_metric_rows_to_read <- inv_metric_rows
Expand Down Expand Up @@ -786,6 +786,7 @@ read_csv_metadata <- function(csv_file) {
}
}
if (csv_file_info$method != "diagnose" &&
!isTRUE(csv_file_info$algorithm == "fixed_param") &&
length(csv_file_info$sampler_diagnostics) == 0 &&
length(csv_file_info$variables) == 0) {
stop("Supplied CSV file does not contain any variable names or data!", call. = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ sample <- function(data = NULL,
}
}

if (cmdstan_version() >= "2.27.0" && !fixed_param) {
if (cmdstan_version() >= "2.27.0" && cmdstan_version() < "2.36.0" && !fixed_param) {
if (self$has_stan_file() && file.exists(self$stan_file())) {
if (!is.null(self$variables()) && length(self$variables()$parameters) == 0) {
stop("Model contains no parameters. Please use 'fixed_param = TRUE'.", call. = FALSE)
Expand Down
13 changes: 12 additions & 1 deletion tests/testthat/test-model-sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ test_that("seed works for multi chain sampling", {
expect_false(all(chain_tdata_1 == chain_tdata_2))
})

test_that("fixed_param is set when the model has no parameters", {
test_that("Correct behavior if fixed_param not set when the model has no parameters", {
code <- "
model {}
generated quantities {
Expand All @@ -316,10 +316,21 @@ test_that("fixed_param is set when the model has no parameters", {
"
stan_file <- write_stan_file(code)
m <- cmdstan_model(stan_file)
fake_cmdstan_version("2.35.0")
expect_error(
m$sample(),
"Model contains no parameters. Please use 'fixed_param = TRUE'."
)

reset_cmdstan_version()
if (cmdstan_version() >= "2.36.0") {
# as of 2.36.0 we don't need fixed_param if no parameters
expect_no_error(
utils::capture.output(
fit <- m$sample(iter_warmup = 10, iter_sampling = 10, diagnostics = NULL)
)
)
}
})

test_that("sig_figs warning if version less than 2.25", {
Expand Down
Loading