Skip to content

Commit 6daf429

Browse files
committed
Merge branch 'master' into expose_new_stan_args
2 parents 695dba6 + 30c945c commit 6daf429

12 files changed

Lines changed: 196 additions & 21 deletions

File tree

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ jobs:
3737

3838
- uses: actions/checkout@v4
3939

40-
- uses: r-lib/actions/setup-r@v2.8.2
41-
with:
42-
r-version: 'release'
43-
rtools-version: '42'
44-
- uses: r-lib/actions/setup-pandoc@v2.8.2
40+
- uses: r-lib/actions/setup-r@v2.8.7
41+
- uses: r-lib/actions/setup-pandoc@v2.8.7
4542

4643
- name: Query dependencies
4744
run: |
@@ -58,7 +55,7 @@ jobs:
5855
install.packages("curl")
5956
shell: Rscript {0}
6057

61-
- uses: Vampire/setup-wsl@v2
58+
- uses: Vampire/setup-wsl@v3
6259
with:
6360
distribution: Ubuntu-22.04
6461
use-cache: 'false'

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ jobs:
5757
sudo apt-get install -y libcurl4-openssl-dev || true
5858
sudo apt-get install -y openmpi-bin openmpi-common libopenmpi-dev || true
5959
60-
- uses: r-lib/actions/setup-r@v2.8.2
60+
- uses: r-lib/actions/setup-r@v2.8.7
6161
with:
6262
r-version: ${{ matrix.config.r }}
6363
rtools-version: ${{ matrix.config.rtools }}
64-
- uses: r-lib/actions/setup-pandoc@v2.8.2
64+
- uses: r-lib/actions/setup-pandoc@v2.8.7
6565

6666
- name: Query dependencies
6767
run: |

.github/workflows/Test-coverage.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ jobs:
3434
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"
3535
- uses: actions/checkout@v4
3636

37-
- uses: r-lib/actions/setup-r@v2.8.2
38-
- uses: r-lib/actions/setup-pandoc@v2.8.2
37+
- uses: r-lib/actions/setup-r@v2.8.7
38+
- uses: r-lib/actions/setup-pandoc@v2.8.7
3939

4040
- name: Install Ubuntu dependencies
4141
run: |
@@ -85,12 +85,9 @@ jobs:
8585
steps:
8686
- uses: actions/checkout@v4
8787

88-
- uses: r-lib/actions/setup-r@v2.8.2
89-
with:
90-
r-version: 'release'
91-
rtools-version: '42'
88+
- uses: r-lib/actions/setup-r@v2.8.7
9289

93-
- uses: r-lib/actions/setup-pandoc@v2.8.2
90+
- uses: r-lib/actions/setup-pandoc@v2.8.7
9491

9592
- name: Query dependencies
9693
run: |

.github/workflows/cmdstan-tarball-check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ jobs:
4040
sudo apt-get install -y libcurl4-openssl-dev || true
4141
sudo apt-get install -y openmpi-bin openmpi-common libopenmpi-dev || true
4242
43-
- uses: r-lib/actions/setup-r@v2.8.2
43+
- uses: r-lib/actions/setup-r@v2.8.7
4444
with:
4545
r-version: ${{ matrix.config.r }}
4646
rtools-version: ${{ matrix.config.rtools }}
4747

48-
- uses: r-lib/actions/setup-pandoc@v2.8.2
48+
- uses: r-lib/actions/setup-pandoc@v2.8.7
4949

5050
- name: Query dependencies
5151
run: |

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ S3method(as_draws,CmdStanMCMC)
66
S3method(as_draws,CmdStanMLE)
77
S3method(as_draws,CmdStanPathfinder)
88
S3method(as_draws,CmdStanVB)
9+
export(as.CmdStanDiagnose)
10+
export(as.CmdStanGQ)
11+
export(as.CmdStanLaplace)
12+
export(as.CmdStanMCMC)
13+
export(as.CmdStanMLE)
14+
export(as.CmdStanPathfinder)
15+
export(as.CmdStanVB)
916
export(as_cmdstan_fit)
1017
export(as_draws)
1118
export(as_mcmc.list)

R/args.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ SampleArgs <- R6::R6Class(
266266
fileext = ".json"
267267
)
268268
for (i in seq_along(inv_metric_paths)) {
269+
if (length(inv_metric[[i]]) == 1 && metric == "diag_e") {
270+
inv_metric[[i]] <- array(inv_metric[[i]], dim = c(1))
271+
}
269272
write_stan_json(list(inv_metric = inv_metric[[i]]), inv_metric_paths[i])
270273
}
271274

R/fit.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,10 @@ inv_metric <- function(matrix = TRUE) {
17841784
out <- private$inv_metric_
17851785
if (matrix && !is.matrix(out[[1]])) {
17861786
# convert each vector to a diagonal matrix
1787-
out <- lapply(out, diag)
1787+
out <- lapply(out, function(x) diag(x, nrow = length(x)))
1788+
} else if (length(out[[1]]) == 1) {
1789+
# convert each scalar to an array with dimension 1
1790+
out <- lapply(out, array, dim = c(1))
17881791
}
17891792
out
17901793
}

R/generics.R

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
#' Coercion methods for CmdStan objects
3+
#'
4+
#' These methods are used to coerce objects into `cmdstanr` objects.
5+
#' Primarily intended for other packages to use when interfacing
6+
#' with `cmdstanr`.
7+
#'
8+
#' @param object to be coerced
9+
#' @param ... additional arguments
10+
#'
11+
#' @name cmdstan_coercion
12+
NULL
13+
14+
#' @rdname cmdstan_coercion
15+
#' @export
16+
as.CmdStanMCMC <- function(object, ...) {
17+
UseMethod("as.CmdStanMCMC")
18+
}
19+
20+
#' @rdname cmdstan_coercion
21+
#' @export
22+
as.CmdStanMLE <- function(object, ...) {
23+
UseMethod("as.CmdStanMLE")
24+
}
25+
26+
#' @rdname cmdstan_coercion
27+
#' @export
28+
as.CmdStanLaplace <- function(object, ...) {
29+
UseMethod("as.CmdStanLaplace")
30+
}
31+
32+
#' @rdname cmdstan_coercion
33+
#' @export
34+
as.CmdStanVB <- function(object, ...) {
35+
UseMethod("as.CmdStanVB")
36+
}
37+
38+
#' @rdname cmdstan_coercion
39+
#' @export
40+
as.CmdStanPathfinder <- function(object, ...) {
41+
UseMethod("as.CmdStanPathfinder")
42+
}
43+
44+
#' @rdname cmdstan_coercion
45+
#' @export
46+
as.CmdStanGQ <- function(object, ...) {
47+
UseMethod("as.CmdStanGQ")
48+
}
49+
50+
#' @rdname cmdstan_coercion
51+
#' @export
52+
as.CmdStanDiagnose <- function(object, ...) {
53+
UseMethod("as.CmdStanDiagnose")
54+
}

R/install.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,10 @@ rtools4x_version <- function() {
855855
rtools_ver <- "40"
856856
} else if (R.version$minor < "3.0") {
857857
rtools_ver <- "42"
858-
} else {
858+
} else if (R.version$minor < "5.0") {
859859
rtools_ver <- "43"
860+
} else {
861+
rtools_ver <- "44"
860862
}
861863
rtools_ver
862864
}

R/utils.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,9 @@ assert_valid_draws_format <- function(format) {
394394
}
395395
if (format %in% c("rvars", "draws_rvars")) {
396396
stop(
397-
"\nWe are fixing a bug in fit$draws(format = 'draws_rvars').",
398-
"\nFor now please use posterior::as_draws_rvars(fit$draws()) instead."
397+
"\nTo use the rvar format please convert after extracting the draws, ",
398+
"e.g., posterior::as_draws_rvars(fit$draws()).",
399+
call. = FALSE
399400
)
400401
}
401402
}

0 commit comments

Comments
 (0)