Skip to content

Commit dde1164

Browse files
committed
fix test/code mismatch and add docs
1 parent 0f90699 commit dde1164

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

R/cpp_opts.R

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# running and parsing exe info --------------------------------
44
# run <model> info command
5+
#' @example `.cmdstan/bin`
56
run_info_cli <- function(exe_file) {
67
withr::with_path(
78
c(
@@ -76,6 +77,7 @@ model_compile_info <- function(exe_file, version) {
7677
}
7778

7879
# convert to compile flags --------------------
80+
# from list(flag1=TRUE, flag2=FALSE) to "FLAG1=TRUE\nFLAG2=FALSE"
7981
cpp_options_to_compile_flags <- function(cpp_options) {
8082
if (length(cpp_options) == 0) {
8183
return(NULL)
@@ -94,7 +96,8 @@ cpp_options_to_compile_flags <- function(cpp_options) {
9496

9597

9698
# check options overall for validity ---------------------------------
97-
99+
# takes list of options as input and returns list of options
100+
# returns list with names standardized to lowercase
98101
validate_cpp_options <- function(cpp_options) {
99102
if (is.null(cpp_options) || length(cpp_options) == 0) return(list())
100103

@@ -129,7 +132,9 @@ validate_cpp_options <- function(cpp_options) {
129132
}
130133

131134
# check specific options for validity ---------------------------------
132-
135+
# no type checking for opencl_ids
136+
# cpp_options must be a list
137+
# opencl_ids returned unchanged
133138
assert_valid_opencl <- function(opencl_ids, cpp_options) {
134139
if (is.null(cpp_options[["stan_opencl"]])
135140
&& !is.null(opencl_ids)) {
@@ -140,6 +145,7 @@ assert_valid_opencl <- function(opencl_ids, cpp_options) {
140145
invisible(opencl_ids)
141146
}
142147

148+
# cpp_options must be a list
143149
assert_valid_threads <- function(threads, cpp_options, multiple_chains = FALSE) {
144150
threads_arg <- if (multiple_chains) "threads_per_chain" else "threads"
145151
checkmate::assert_integerish(threads, .var.name = threads_arg,
@@ -164,7 +170,11 @@ assert_valid_threads <- function(threads, cpp_options, multiple_chains = FALSE)
164170
invisible(threads)
165171
}
166172

167-
# compare exe info and cpp options to one another
173+
# For two functions below
174+
# both styles are lists which should have flag names in lower case as names of the list
175+
# cpp_options style means is NULL or empty string
176+
# exe_info style means off is FALSE
177+
168178
exe_info_style_cpp_options <- function(cpp_options) {
169179
if(is.null(cpp_options)) cpp_options <- list()
170180
names(cpp_options) <- tolower(names(cpp_options))

tests/testthat/test-opencl.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ test_that("all methods error when opencl_ids is used with non OpenCL model", {
88
mod <- cmdstan_model(stan_file = stan_file)
99
expect_error(
1010
mod$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0), chains = 1),
11-
"'opencl_ids' is set but the model was not compiled with for use with OpenCL.",
11+
"'opencl_ids' is set but the model was not compiled for use with OpenCL.",
1212
fixed = TRUE
1313
)
1414
expect_error(
1515
mod$optimize(data = testing_data("bernoulli"), opencl_ids = c(0, 0)),
16-
"'opencl_ids' is set but the model was not compiled with for use with OpenCL.",
16+
"'opencl_ids' is set but the model was not compiled for use with OpenCL.",
1717
fixed = TRUE
1818
)
1919
expect_error(
2020
mod$variational(data = testing_data("bernoulli"), opencl_ids = c(0, 0)),
21-
"'opencl_ids' is set but the model was not compiled with for use with OpenCL.",
21+
"'opencl_ids' is set but the model was not compiled for use with OpenCL.",
2222
fixed = TRUE
2323
)
2424
stan_file_gq <- testing_stan_file("bernoulli_ppc")
2525
mod_gq <- cmdstan_model(stan_file = stan_file_gq)
2626
expect_error(
2727
mod_gq$generate_quantities(fitted_params = fit, data = testing_data("bernoulli"), opencl_ids = c(0, 0)),
28-
"'opencl_ids' is set but the model was not compiled with for use with OpenCL.",
28+
"'opencl_ids' is set but the model was not compiled for use with OpenCL.",
2929
fixed = TRUE
3030
)
3131
})

0 commit comments

Comments
 (0)