Skip to content

Commit

Permalink
Update tests, fix windows error
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jun 8, 2024
1 parent 8ea0d4a commit 6019efe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
4 changes: 2 additions & 2 deletions R/args.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 0 additions & 13 deletions tests/testthat/resources/stan/issue_975.stan

This file was deleted.

10 changes: 0 additions & 10 deletions tests/testthat/test-init-issue975.R

This file was deleted.

25 changes: 25 additions & 0 deletions tests/testthat/test-model-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -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<lower=0>[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))
})

0 comments on commit 6019efe

Please sign in to comment.