Skip to content

Commit 3bc7311

Browse files
committed
Merge branch 'master' into avehtari-patch-1
2 parents 5dfd05b + 284a10c commit 3bc7311

15 files changed

Lines changed: 410 additions & 233 deletions

File tree

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ jobs:
6969
- name: Install cmdstan
7070
run: |
7171
cmdstanr::check_cmdstan_toolchain(fix = TRUE)
72-
if (Sys.getenv("CMDSTANR_USE_RTOOLS") == "TRUE") {
73-
cmdstanr::install_cmdstan(cores = 2, version = "2.35.0-rc2")
74-
} else {
75-
cmdstanr::install_cmdstan(cores = 2)
76-
}
72+
cmdstanr::install_cmdstan(cores = 2)
7773
shell: Rscript {0}
7874

7975
- name: Session info

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: cmdstanr
22
Title: R Interface to 'CmdStan'
3-
Version: 0.8.0.9000
4-
Date: 2024-05-18
3+
Version: 0.8.1.9000
4+
Date: 2024-06-06
55
Authors@R:
66
c(person(given = "Jonah", family = "Gabry", role = "aut",
77
email = "jsg2201@columbia.edu"),

NEWS.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
1-
# cmdstanr 0.8.0.9000
1+
# cmdstanr 0.8.1.9000
22

33
Items for next release go here
44

5+
# cmdstanr 0.8.1
6+
7+
## Minor changes
8+
9+
* Added `CMDSTANR_USE_RTOOLS` environment variable to force stock RTools on Windows by @andrjohns in #980
10+
* Added support for Windows ARM64 by @andrjohns in #990
11+
* Automatically initialise model methods when called, add `inc_warmup` argument to `$unconstrain_draws()` by @andrjohns in #985
12+
13+
## Bugfixes
14+
15+
* Fix errors when using pathfinder object as initial values by @avehtari in #984
16+
* Fix error with `$unconstrain_draws()` returning incorrect assumptions in some cases by @andrjohns in #983
17+
* Fix spurious errors about missing CmdStan config files by @andrjohns in #981
18+
* Fix linking error when exposing SUNDIALS/KINSOL functions or model methods by @andrjohns in #977
19+
* Fix long-standing error with OneDrive paths on Windows by @andrjohns in #990
20+
521
# cmdstanr 0.8.0
622

723
## Major new features

R/args.R

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,24 @@ process_init.default <- function(init, ...) {
10631063
return(init)
10641064
}
10651065

1066+
#' Remove the leftmost dimension if equal to 1
1067+
#' @noRd
1068+
#' @param x An array like object
1069+
.remove_leftmost_dim <- function(x) {
1070+
dims <- dim(x)
1071+
if (length(dims) == 1) {
1072+
return(drop(x))
1073+
} else if (dims[1] == 1) {
1074+
new_dims <- dims[-1]
1075+
# Create a call to subset the array, maintaining all remaining dimensions
1076+
subset_expr <- as.call(c(as.name("["), list(x), 1, rep(TRUE, length(new_dims)), drop = FALSE))
1077+
new_x <- eval(subset_expr)
1078+
return(array(new_x, dim = new_dims))
1079+
} else {
1080+
return(x)
1081+
}
1082+
}
1083+
10661084
#' Write initial values to files if provided as posterior `draws` object
10671085
#' @noRd
10681086
#' @param init A type that inherits the `posterior::draws` class.
@@ -1097,9 +1115,13 @@ process_init.draws <- function(init, num_procs, model_variables = NULL,
10971115
draws_rvar <- posterior::subset_draws(draws_rvar, variable = variable_names)
10981116
inits = lapply(1:num_procs, function(draw_iter) {
10991117
init_i = lapply(variable_names, function(var_name) {
1100-
x = drop(posterior::draws_of(drop(
1101-
posterior::subset_draws(draws_rvar[[var_name]], draw=draw_iter))))
1102-
return(x)
1118+
x = .remove_leftmost_dim(posterior::draws_of(
1119+
posterior::subset_draws(draws_rvar[[var_name]], draw=draw_iter)))
1120+
if (model_variables$parameters[[var_name]]$dimensions == 0) {
1121+
return(as.double(x))
1122+
} else {
1123+
return(x)
1124+
}
11031125
})
11041126
bad_names = unlist(lapply(variable_names, function(var_name) {
11051127
x = drop(posterior::draws_of(drop(
@@ -1295,13 +1317,13 @@ process_init_approx <- function(init, num_procs, model_variables = NULL,
12951317
# Calculate unique draws based on 'lw' using base R functions
12961318
unique_draws = length(unique(draws_df$lw))
12971319
if (num_procs > unique_draws) {
1298-
if (inherits(init, " CmdStanPathfinder ")) {
1320+
if (inherits(init, "CmdStanPathfinder")) {
12991321
algo_name = " Pathfinder "
13001322
extra_msg = " Try running Pathfinder with psis_resample=FALSE."
13011323
} else if (inherits(init, "CmdStanVB")) {
13021324
algo_name = " CmdStanVB "
13031325
extra_msg = ""
1304-
} else if (inherits(init, " CmdStanLaplace ")) {
1326+
} else if (inherits(init, "CmdStanLaplace")) {
13051327
algo_name = " CmdStanLaplace "
13061328
extra_msg = ""
13071329
} else {

R/data.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ process_data <- function(data, model_variables = NULL) {
186186
# generating a decimal point in write_stan_json
187187
if (data_variables[[var_name]]$type == "int"
188188
&& !is.integer(data[[var_name]])) {
189+
if (!is.factor(data[[var_name]])) {
190+
if (!isTRUE(all(is_wholenumber(data[[var_name]])))) {
191+
# Don't warn for NULL/NA, as different warnings are used for those
192+
if (!isTRUE(any(is.na(data[[var_name]])))) {
193+
warning("A non-integer value was supplied for '", var_name, "'!",
194+
" It will be truncated to an integer.", call. = FALSE)
195+
}
196+
} else {
197+
# Round before setting mode to integer to avoid floating point errors
198+
data[[var_name]] <- round(data[[var_name]])
199+
}
200+
}
189201
mode(data[[var_name]]) <- "integer"
190202
}
191203
}

R/install.R

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -453,63 +453,72 @@ build_cmdstan <- function(dir,
453453
} else {
454454
run_cmd <- make_cmd()
455455
}
456-
withr::with_path(
457-
c(
458-
toolchain_PATH_env_var(),
459-
tbb_path(dir = dir)
460-
),
461-
wsl_compatible_run(
462-
command = run_cmd,
463-
args = c(translation_args, paste0("-j", cores), "build"),
464-
wd = dir,
465-
echo_cmd = is_verbose_mode(),
466-
echo = !quiet || is_verbose_mode(),
467-
spinner = quiet,
468-
error_on_status = FALSE,
469-
stderr_callback = function(x, p) { if (quiet) message(x) },
470-
timeout = timeout
456+
withr::with_envvar(
457+
c("HOME" = short_path(Sys.getenv("HOME"))),
458+
withr::with_path(
459+
c(
460+
toolchain_PATH_env_var(),
461+
tbb_path(dir = dir)
462+
),
463+
wsl_compatible_run(
464+
command = run_cmd,
465+
args = c(translation_args, paste0("-j", cores), "build"),
466+
wd = dir,
467+
echo_cmd = is_verbose_mode(),
468+
echo = !quiet || is_verbose_mode(),
469+
spinner = quiet,
470+
error_on_status = FALSE,
471+
stderr_callback = function(x, p) { if (quiet) message(x) },
472+
timeout = timeout
473+
)
471474
)
472475
)
473476
}
474477

475478
clean_cmdstan <- function(dir = cmdstan_path(),
476479
cores = getOption("mc.cores", 2),
477480
quiet = FALSE) {
478-
withr::with_path(
479-
c(
480-
toolchain_PATH_env_var(),
481-
tbb_path(dir = dir)
482-
),
483-
wsl_compatible_run(
484-
command = make_cmd(),
485-
args = "clean-all",
486-
wd = dir,
487-
echo_cmd = is_verbose_mode(),
488-
echo = !quiet || is_verbose_mode(),
489-
spinner = quiet,
490-
error_on_status = FALSE,
491-
stderr_callback = function(x, p) { if (quiet) message(x) }
481+
withr::with_envvar(
482+
c("HOME" = short_path(Sys.getenv("HOME"))),
483+
withr::with_path(
484+
c(
485+
toolchain_PATH_env_var(),
486+
tbb_path(dir = dir)
487+
),
488+
wsl_compatible_run(
489+
command = make_cmd(),
490+
args = "clean-all",
491+
wd = dir,
492+
echo_cmd = is_verbose_mode(),
493+
echo = !quiet || is_verbose_mode(),
494+
spinner = quiet,
495+
error_on_status = FALSE,
496+
stderr_callback = function(x, p) { if (quiet) message(x) }
497+
)
492498
)
493499
)
494500
}
495501

496502
build_example <- function(dir, cores, quiet, timeout) {
497-
withr::with_path(
498-
c(
499-
toolchain_PATH_env_var(),
500-
tbb_path(dir = dir)
501-
),
502-
wsl_compatible_run(
503-
command = make_cmd(),
504-
args = c(paste0("-j", cores),
505-
cmdstan_ext(file.path("examples", "bernoulli", "bernoulli"))),
506-
wd = dir,
507-
echo_cmd = is_verbose_mode(),
508-
echo = !quiet || is_verbose_mode(),
509-
spinner = quiet,
510-
error_on_status = FALSE,
511-
stderr_callback = function(x, p) { if (quiet) message(x) },
512-
timeout = timeout
503+
withr::with_envvar(
504+
c("HOME" = short_path(Sys.getenv("HOME"))),
505+
withr::with_path(
506+
c(
507+
toolchain_PATH_env_var(),
508+
tbb_path(dir = dir)
509+
),
510+
wsl_compatible_run(
511+
command = make_cmd(),
512+
args = c(paste0("-j", cores),
513+
cmdstan_ext(file.path("examples", "bernoulli", "bernoulli"))),
514+
wd = dir,
515+
echo_cmd = is_verbose_mode(),
516+
echo = !quiet || is_verbose_mode(),
517+
spinner = quiet,
518+
error_on_status = FALSE,
519+
stderr_callback = function(x, p) { if (quiet) message(x) },
520+
timeout = timeout
521+
)
513522
)
514523
)
515524
}
@@ -849,7 +858,11 @@ toolchain_PATH_env_var <- function() {
849858
rtools4x_toolchain_path <- function() {
850859
toolchain <- ifelse(is_ucrt_toolchain(), "ucrt64", "mingw64")
851860
if (Sys.getenv("CMDSTANR_USE_RTOOLS") != "") {
852-
toolchain <- "x86_64-w64-mingw32.static.posix"
861+
if (arch_is_aarch64()) {
862+
toolchain <- "aarch64-w64-mingw32.static.posix"
863+
} else {
864+
toolchain <- "x86_64-w64-mingw32.static.posix"
865+
}
853866
}
854867
repair_path(file.path(rtools4x_home_path(), toolchain, "bin"))
855868
}
@@ -871,10 +884,16 @@ rtools4x_version <- function() {
871884

872885
rtools4x_home_path <- function() {
873886
rtools_ver <- rtools4x_version()
887+
if (arch_is_aarch64()) {
888+
rtools_ver <- paste0(rtools_ver, "_AARCH64")
889+
}
874890
path <- Sys.getenv(paste0("RTOOLS", rtools_ver, "_HOME"))
875891

876892
if (!nzchar(path)) {
877893
default_path <- repair_path(file.path(paste0("C:/rtools", rtools_ver)))
894+
if (arch_is_aarch64()) {
895+
default_path <- paste0(default_path, "-aarch64")
896+
}
878897
if (dir.exists(default_path)) {
879898
path <- default_path
880899
}

0 commit comments

Comments
 (0)