Skip to content

Commit

Permalink
Update expect draws format in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrjohns committed Jan 10, 2024
1 parent f370d40 commit a15298b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tests/testthat/test-model-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,20 @@ test_that("unconstrain_draws returns correct values", {
mod <- cmdstan_model(write_stan_file(model_code),
compile_model_methods = TRUE,
force_recompile = TRUE)
fit <- mod$sample(data = list(N = 0), chains = 1)
fit <- mod$sample(data = list(N = 0), chains = 2)

x_draws <- fit$draws(format = "draws_df")$x

# Unconstrain all internal draws
unconstrained_internal_draws <- fit$unconstrain_draws()[[1]]
unconstrained_internal_draws <- fit$unconstrain_draws()
expect_equal(as.numeric(x_draws), as.numeric(unconstrained_internal_draws))

# Unconstrain external CmdStan CSV files
unconstrained_csv <- fit$unconstrain_draws(files = fit$output_files())[[1]]
unconstrained_csv <- fit$unconstrain_draws(files = fit$output_files())
expect_equal(as.numeric(x_draws), as.numeric(unconstrained_csv))

# Unconstrain existing draws object
unconstrained_draws <- fit$unconstrain_draws(draws = fit$draws())[[1]]
unconstrained_draws <- fit$unconstrain_draws(draws = fit$draws())
expect_equal(as.numeric(x_draws), as.numeric(unconstrained_draws))

# With a lower-bounded constraint, the parameter draws should be the
Expand All @@ -253,19 +253,19 @@ test_that("unconstrain_draws returns correct values", {
mod <- cmdstan_model(write_stan_file(model_code),
compile_model_methods = TRUE,
force_recompile = TRUE)
fit <- mod$sample(data = list(N = 0), chains = 1)
fit <- mod$sample(data = list(N = 0), chains = 2)

x_draws <- fit$draws(format = "draws_df")$x

unconstrained_internal_draws <- fit$unconstrain_draws()[[1]]
unconstrained_internal_draws <- fit$unconstrain_draws()
expect_equal(as.numeric(x_draws), exp(as.numeric(unconstrained_internal_draws)))

# Unconstrain external CmdStan CSV files
unconstrained_csv <- fit$unconstrain_draws(files = fit$output_files())[[1]]
unconstrained_csv <- fit$unconstrain_draws(files = fit$output_files())
expect_equal(as.numeric(x_draws), exp(as.numeric(unconstrained_csv)))

# Unconstrain existing draws object
unconstrained_draws <- fit$unconstrain_draws(draws = fit$draws())[[1]]
unconstrained_draws <- fit$unconstrain_draws(draws = fit$draws())
expect_equal(as.numeric(x_draws), exp(as.numeric(unconstrained_draws)))
})

Expand Down

0 comments on commit a15298b

Please sign in to comment.