Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable fast options by default #81

Merged
merged 4 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ BugReports: https://github.com/bfast2/bfast/issues
LazyLoad: yes
LazyData: yes
LinkingTo: Rcpp
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(bfastpp)
export(bfastts)
export(create16dayts)
export(set_default_options)
export(set_fallback_options)
export(set_fast_options)
import(forecast)
import(stats)
Expand Down
49 changes: 21 additions & 28 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.onLoad <- function(libname, pkgname) {
op <- options()
op.bfast <- list(
bfast.prefer_matrix_methods = FALSE,
bfast.use_bfastts_modifications = FALSE,
strucchange.use_armadillo=FALSE
bfast.prefer_matrix_methods = TRUE,
bfast.use_bfastts_modifications = TRUE,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This depends on #19 though. And good to include a more complex test in the bfastpp examples, perhaps, that would cover regular and irregular cases.

strucchange.use_armadillo=TRUE
)
toset <- !(names(op.bfast) %in% names(op))
if(any(toset)) options(op.bfast[toset])
Expand All @@ -13,46 +13,39 @@

#' Set package options with regard to computation times
#'
#' These functions set options of the bfast and strucchangeRcpp package to enable
#' faster computations. The fast options should return equal results but
#' require the \code{strucchangeRcpp} package, which includes
#' matrix-based functions. Notice that only some functions of the \code{bfast}
#' package make use of these options.

#' These functions set options of the bfast and strucchangeRcpp packages to enable
#' faster computations. By default (\code{set_default_options}), these optimizations are
#' enabled. Notice that only some functions of the \code{bfast}
#' package make use of these options. \code{set_fast_options} is an alias for \code{set_default_options}.
#'
#' @name setoptions
#' @aliases set_fast_options set_default_options
#' @aliases set_default_options set_fallback_options set_fast_options
#' @return A list of modified options and their new values.
#' @author Marius Appel
#' @examples
#'
#'
#' # run bfastmonitor with different options and compare computation times
#' library(zoo)
#' NDVIa <- as.ts(zoo(som$NDVI.a, som$Time))
#'
#' set_fast_options()
#' set_default_options()
#' system.time(replicate(100, bfastmonitor(NDVIa, start = c(2010, 13))))
#'
#' set_default_options()
#' set_fallback_options()
#' system.time(replicate(100, bfastmonitor(NDVIa, start = c(2010, 13))))
#'
#' @export set_fast_options set_default_options
set_fast_options <- function() {
if (!requireNamespace("strucchangeRcpp", quietly = TRUE)) {
warning("package strucchangeRcpp required for enabling fast options; using default implementation of strucchange")
}
else {
return(options(strucchange.use_armadillo=TRUE,
bfast.prefer_matrix_methods=TRUE,
bfast.use_bfastts_modifications=TRUE))
}
#' @export set_fast_options set_default_options set_fallback_options
set_default_options <- function() {
return(options(strucchange.use_armadillo=TRUE,
bfast.prefer_matrix_methods=TRUE,
bfast.use_bfastts_modifications=TRUE))
}

set_fast_options <- set_default_options

set_default_options <- function() {
if (requireNamespace("strucchangeRcpp", quietly = TRUE)) {
return(options(strucchange.use_armadillo=FALSE,
bfast.prefer_matrix_methods=FALSE,
bfast.use_bfastts_modifications=FALSE))
}
set_fallback_options <- function() {
return(options(strucchange.use_armadillo=FALSE,
bfast.prefer_matrix_methods=FALSE,
bfast.use_bfastts_modifications=FALSE))
}
21 changes: 9 additions & 12 deletions man/setoptions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.