1
-
2
1
# ' Create a new CmdStanModel object
3
2
# '
4
3
# ' @description \if{html}{\figure{logo.png}{options: width=25}}
@@ -252,7 +251,7 @@ CmdStanModel <- R6::R6Class(
252
251
private $ stan_file_ <- absolute_path(stan_file )
253
252
private $ stan_code_ <- readLines(stan_file )
254
253
private $ model_name_ <- sub(" " , " _" , strip_ext(basename(private $ stan_file_ )))
255
- private $ precompile_cpp_options_ <- validate_precompile_cpp_options (args $ cpp_options ) %|| % list ()
254
+ private $ precompile_cpp_options_ <- validate_cpp_options (args $ cpp_options ) %|| % list ()
256
255
private $ precompile_stanc_options_ <- assert_valid_stanc_options(args $ stanc_options ) %|| % list ()
257
256
if (! is.null(args $ user_header ) || ! is.null(args $ cpp_options [[" USER_HEADER" ]]) ||
258
257
! is.null(args $ cpp_options [[" user_header" ]])) {
@@ -392,18 +391,20 @@ CmdStanModel <- R6::R6Class(
392
391
# because that value is only set if model has been recomplied
393
392
# since CmdStanModel instantiation
394
393
if (! fallback ) {
395
- return (self $ exe_info()[[' stan_version' ]])
394
+ return (self $ exe_info()[[" stan_version" ]])
396
395
}
397
396
for (candidate in c(
398
- self $ exe_info()[[' stan_version' ]],
399
- self $ exe_info_fallback()[[' stan_version' ]]
400
- )) if (! is.null(candidate )) return (candidate )
397
+ self $ exe_info()[[" stan_version" ]],
398
+ self $ exe_info_fallback()[[" stan_version" ]]
399
+ )) if (! is.null(candidate )) return (candidate )
401
400
},
402
401
cpp_options = function () {
403
402
warning(
404
- ' mod$cpp_options() will be deprecated in the next major version of cmdstanr. ' ,
405
- ' Use mod$exe_info() to see options from last compilation. ' ,
406
- ' Use mod$precompile_cpp_options() to see default options for next compilation.'
403
+ " mod$cpp_options() will be deprecated " ,
404
+ " in the next major version of cmdstanr. " ,
405
+ " Use mod$exe_info() to see options from last compilation. " ,
406
+ " Use mod$precompile_cpp_options() " ,
407
+ " to see default options for next compilation."
407
408
)
408
409
private $ cpp_options_
409
410
},
@@ -565,13 +566,16 @@ compile <- function(quiet = TRUE,
565
566
566
567
if (! is.null(user_header ) && (
567
568
! is.null(cpp_options [[" USER_HEADER" ]]) || ! is.null(cpp_options [[" user_header" ]])
568
- )) warning(" User header specified both via user_header argument and via cpp_options arguments" )
569
+ )) warning(
570
+ " User header specified both via user_header argument " ,
571
+ " and via cpp_options arguments"
572
+ )
569
573
570
574
if (length(cpp_options ) == 0 && ! is.null(private $ precompile_cpp_options_ )) {
571
575
cpp_options <- private $ precompile_cpp_options_
572
576
}
573
577
cpp_options_legacy <- cpp_options
574
- cpp_options <- validate_precompile_cpp_options (cpp_options )
578
+ cpp_options <- validate_cpp_options (cpp_options )
575
579
576
580
if (length(stanc_options ) == 0 && ! is.null(private $ precompile_stanc_options_ )) {
577
581
stanc_options <- private $ precompile_stanc_options_
@@ -810,7 +814,10 @@ compile <- function(quiet = TRUE,
810
814
private $ precompile_stanc_options_ <- NULL
811
815
private $ precompile_include_paths_ <- NULL
812
816
813
- # Must be run after private$cmdstan_version_, private$exe_file_, and private$precompiled_cpp_options_
817
+ # Must be run after
818
+ # - private$cmdstan_version_
819
+ # - private$exe_file_
820
+ # - private$precompiled_cpp_options_
814
821
# are all up to date
815
822
self $ exe_info(update = TRUE )
816
823
@@ -1340,7 +1347,11 @@ sample <- function(data = NULL,
1340
1347
output_dir = output_dir ,
1341
1348
output_basename = output_basename ,
1342
1349
sig_figs = sig_figs ,
1343
- opencl_ids = assert_valid_opencl(opencl_ids , self $ exe_info(), self $ exe_info_fallback()),
1350
+ opencl_ids = assert_valid_opencl(
1351
+ opencl_ids ,
1352
+ self $ exe_info(),
1353
+ self $ exe_info_fallback()
1354
+ ),
1344
1355
model_variables = model_variables ,
1345
1356
save_cmdstan_config = save_cmdstan_config
1346
1357
)
@@ -1597,7 +1608,11 @@ optimize <- function(data = NULL,
1597
1608
num_procs = 1 ,
1598
1609
show_stderr_messages = show_exceptions ,
1599
1610
show_stdout_messages = show_messages ,
1600
- threads_per_proc = assert_valid_threads(threads , self $ exe_info(), self $ exe_info_fallback())
1611
+ threads_per_proc = assert_valid_threads(
1612
+ threads ,
1613
+ self $ exe_info(),
1614
+ self $ exe_info_fallback()
1615
+ )
1601
1616
)
1602
1617
model_variables <- NULL
1603
1618
if (is_variables_method_supported(self )) {
@@ -1632,7 +1647,11 @@ optimize <- function(data = NULL,
1632
1647
output_dir = output_dir ,
1633
1648
output_basename = output_basename ,
1634
1649
sig_figs = sig_figs ,
1635
- opencl_ids = assert_valid_opencl(opencl_ids , self $ exe_info(), self $ exe_info_fallback()),
1650
+ opencl_ids = assert_valid_opencl(
1651
+ opencl_ids ,
1652
+ self $ exe_info(),
1653
+ self $ exe_info_fallback()
1654
+ ),
1636
1655
model_variables = model_variables ,
1637
1656
save_cmdstan_config = save_cmdstan_config
1638
1657
)
@@ -1737,7 +1756,11 @@ laplace <- function(data = NULL,
1737
1756
num_procs = 1 ,
1738
1757
show_stderr_messages = show_exceptions ,
1739
1758
show_stdout_messages = show_messages ,
1740
- threads_per_proc = assert_valid_threads(threads , self $ exe_info(), self $ exe_info_fallback())
1759
+ threads_per_proc = assert_valid_threads(
1760
+ threads ,
1761
+ self $ exe_info(),
1762
+ self $ exe_info_fallback()
1763
+ )
1741
1764
)
1742
1765
model_variables <- NULL
1743
1766
if (is_variables_method_supported(self )) {
@@ -1799,7 +1822,11 @@ laplace <- function(data = NULL,
1799
1822
output_dir = output_dir ,
1800
1823
output_basename = output_basename ,
1801
1824
sig_figs = sig_figs ,
1802
- opencl_ids = assert_valid_opencl(opencl_ids , self $ exe_info(), self $ exe_info_fallback()),
1825
+ opencl_ids = assert_valid_opencl(
1826
+ opencl_ids ,
1827
+ self $ exe_info(),
1828
+ self $ exe_info_fallback()
1829
+ ),
1803
1830
model_variables = model_variables ,
1804
1831
save_cmdstan_config = save_cmdstan_config
1805
1832
)
@@ -1887,7 +1914,11 @@ variational <- function(data = NULL,
1887
1914
num_procs = 1 ,
1888
1915
show_stderr_messages = show_exceptions ,
1889
1916
show_stdout_messages = show_messages ,
1890
- threads_per_proc = assert_valid_threads(threads , self $ exe_info(), self $ exe_info_fallback())
1917
+ threads_per_proc = assert_valid_threads(
1918
+ threads ,
1919
+ self $ exe_info(),
1920
+ self $ exe_info_fallback()
1921
+ )
1891
1922
)
1892
1923
model_variables <- NULL
1893
1924
if (is_variables_method_supported(self )) {
@@ -1922,7 +1953,11 @@ variational <- function(data = NULL,
1922
1953
output_dir = output_dir ,
1923
1954
output_basename = output_basename ,
1924
1955
sig_figs = sig_figs ,
1925
- opencl_ids = assert_valid_opencl(opencl_ids , self $ exe_info(), self $ exe_info_fallback()),
1956
+ opencl_ids = assert_valid_opencl(
1957
+ opencl_ids ,
1958
+ self $ exe_info(),
1959
+ self $ exe_info_fallback()
1960
+ ),
1926
1961
model_variables = model_variables ,
1927
1962
save_cmdstan_config = save_cmdstan_config
1928
1963
)
@@ -2032,7 +2067,11 @@ pathfinder <- function(data = NULL,
2032
2067
num_procs = 1 ,
2033
2068
show_stderr_messages = show_exceptions ,
2034
2069
show_stdout_messages = show_messages ,
2035
- threads_per_proc = assert_valid_threads(num_threads , self $ exe_info(), self $ exe_info_fallback())
2070
+ threads_per_proc = assert_valid_threads(
2071
+ num_threads ,
2072
+ self $ exe_info(),
2073
+ self $ exe_info_fallback()
2074
+ )
2036
2075
)
2037
2076
model_variables <- NULL
2038
2077
if (is_variables_method_supported(self )) {
@@ -2072,7 +2111,11 @@ pathfinder <- function(data = NULL,
2072
2111
output_dir = output_dir ,
2073
2112
output_basename = output_basename ,
2074
2113
sig_figs = sig_figs ,
2075
- opencl_ids = assert_valid_opencl(opencl_ids , self $ exe_info(), self $ exe_info_fallback()),
2114
+ opencl_ids = assert_valid_opencl(
2115
+ opencl_ids ,
2116
+ self $ exe_info(),
2117
+ self $ exe_info_fallback()
2118
+ ),
2076
2119
model_variables = model_variables ,
2077
2120
num_threads = num_threads ,
2078
2121
save_cmdstan_config = save_cmdstan_config
@@ -2169,7 +2212,12 @@ generate_quantities <- function(fitted_params,
2169
2212
procs <- CmdStanGQProcs $ new(
2170
2213
num_procs = length(fitted_params_files ),
2171
2214
parallel_procs = checkmate :: assert_integerish(parallel_chains , lower = 1 , null.ok = TRUE ),
2172
- threads_per_proc = assert_valid_threads(threads_per_chain , self $ exe_info(), self $ exe_info_fallback(), multiple_chains = TRUE )
2215
+ threads_per_proc = assert_valid_threads(
2216
+ threads_per_chain ,
2217
+ self $ exe_info(),
2218
+ self $ exe_info_fallback(),
2219
+ multiple_chains = TRUE
2220
+ )
2173
2221
)
2174
2222
model_variables <- NULL
2175
2223
if (is_variables_method_supported(self )) {
@@ -2190,7 +2238,11 @@ generate_quantities <- function(fitted_params,
2190
2238
output_dir = output_dir ,
2191
2239
output_basename = output_basename ,
2192
2240
sig_figs = sig_figs ,
2193
- opencl_ids = assert_valid_opencl(opencl_ids , self $ exe_info(), self $ exe_info_fallback()),
2241
+ opencl_ids = assert_valid_opencl(
2242
+ opencl_ids ,
2243
+ self $ exe_info(),
2244
+ self $ exe_info_fallback()
2245
+ ),
2194
2246
model_variables = model_variables
2195
2247
)
2196
2248
runset <- CmdStanRun $ new(args , procs )
@@ -2407,7 +2459,9 @@ model_variables <- function(stan_file, include_paths = NULL, allow_undefined = F
2407
2459
}
2408
2460
2409
2461
is_variables_method_supported <- function (mod ) {
2410
- cmdstan_version() > = " 2.27.0" && mod $ has_stan_file() && file.exists(mod $ stan_file())
2462
+ cmdstan_version() > = " 2.27.0" &&
2463
+ mod $ has_stan_file() &&
2464
+ file.exists(mod $ stan_file())
2411
2465
}
2412
2466
2413
2467
resolve_exe_path <- function (
0 commit comments