From 6019efe25fcd98c3901393ab47f826afc2493dcd Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Sat, 8 Jun 2024 16:09:51 +0300 Subject: [PATCH] Update tests, fix windows error --- R/args.R | 4 ++-- tests/testthat/resources/stan/issue_975.stan | 13 ---------- tests/testthat/test-init-issue975.R | 10 -------- tests/testthat/test-model-init.R | 25 ++++++++++++++++++++ 4 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 tests/testthat/resources/stan/issue_975.stan delete mode 100644 tests/testthat/test-init-issue975.R diff --git a/R/args.R b/R/args.R index 2c585cef..6373eb07 100644 --- a/R/args.R +++ b/R/args.R @@ -1317,13 +1317,13 @@ process_init_approx <- function(init, num_procs, model_variables = NULL, # Calculate unique draws based on 'lw' using base R functions unique_draws = length(unique(draws_df$lw)) if (num_procs > unique_draws) { - if (inherits(init, " CmdStanPathfinder ")) { + if (inherits(init, "CmdStanPathfinder")) { algo_name = " Pathfinder " extra_msg = " Try running Pathfinder with psis_resample=FALSE." } else if (inherits(init, "CmdStanVB")) { algo_name = " CmdStanVB " extra_msg = "" - } else if (inherits(init, " CmdStanLaplace ")) { + } else if (inherits(init, "CmdStanLaplace")) { algo_name = " CmdStanLaplace " extra_msg = "" } else { diff --git a/tests/testthat/resources/stan/issue_975.stan b/tests/testthat/resources/stan/issue_975.stan deleted file mode 100644 index c826ebf3..00000000 --- a/tests/testthat/resources/stan/issue_975.stan +++ /dev/null @@ -1,13 +0,0 @@ -data { - int N; - vector[N] y; -} - -parameters { - matrix[N, 1] mu; - vector[N] sigma; -} - -model { - target += normal_lupdf(y | mu[:, 1] , sigma); -} diff --git a/tests/testthat/test-init-issue975.R b/tests/testthat/test-init-issue975.R deleted file mode 100644 index fb316699..00000000 --- a/tests/testthat/test-init-issue975.R +++ /dev/null @@ -1,10 +0,0 @@ -context("fitted-inits") -set_cmdstan_path() - - -test_that("Sample method works as init", { - mod <- testing_model("issue_975") - data <- list(N = 100, y = rnorm(100)) - pf <- mod$pathfinder(data = data) - expect_no_error(fit <- mod$sample(data = data, init = pf)) -}) diff --git a/tests/testthat/test-model-init.R b/tests/testthat/test-model-init.R index 0092a16f..c5be9e62 100644 --- a/tests/testthat/test-model-init.R +++ b/tests/testthat/test-model-init.R @@ -310,3 +310,28 @@ test_that("Initial values for single-element containers treated correctly", { ) ) }) + +test_that("Pathfinder inits do not drop dimensions", { + modcode <- " + data { + int N; + vector[N] y; + } + + parameters { + matrix[N, 1] mu; + matrix[1, N] mu_2; + vector[N] sigma; + } + + model { + target += normal_lupdf(y | mu[:, 1], sigma); + target += normal_lupdf(y | mu_2[1], sigma); + } + " + mod <- cmdstan_model(write_stan_file(modcode), force_recompile = TRUE) + data <- list(N = 100, y = rnorm(100)) + pf <- mod$pathfinder(data = data, psis_resample = FALSE) + expect_no_error(fit <- mod$sample(data = data, init = pf, chains = 1, + iter_warmup = 100, iter_sampling = 100)) +}) \ No newline at end of file