Skip to content

Commit

Permalink
import parallelly
Browse files Browse the repository at this point in the history
  • Loading branch information
mllg committed Mar 5, 2021
1 parent a6864f5 commit 4a5ec5d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ import(paradox)
importFrom(R6,R6Class)
importFrom(R6,is.R6)
importFrom(graphics,plot)
importFrom(parallelly,availableCores)
importFrom(stats,contr.treatment)
importFrom(stats,predict)
importFrom(stats,rnorm)
Expand Down
10 changes: 5 additions & 5 deletions R/set_threads.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@
#' Object to set threads for, e.g. a [Learner].
#' This object is modified in-place.
#' @param n (`integer(1)`)\cr
#' Number of threads to use.
#' Number of threads to use. Defaults to [parallelly::availableCores()].
#'
#' @return Same object as input `x` (changed in-place),
#' with possibly updated parameter values.
#' @export
set_threads = function(x, n = parallelly::availableCores()) {
set_threads = function(x, n = availableCores()) {
UseMethod("set_threads")
}

#' @rdname set_threads
#' @export
set_threads.default = function(x, n = parallelly::availableCores()) { # nolint
set_threads.default = function(x, n = availableCores()) { # nolint
x
}

#' @rdname set_threads
#' @export
set_threads.Learner = function(x, n = parallelly::availableCores()) { # nolint
set_threads.Learner = function(x, n = availableCores()) { # nolint
id = x$param_set$ids(tags = "threads")
if (length(id)) {
x$param_set$values = insert_named(x$param_set$values, named_list(id, n))
Expand All @@ -47,6 +47,6 @@ set_threads.Learner = function(x, n = parallelly::availableCores()) { # nolint

#' @rdname set_threads
#' @export
set_threads.list = function(x, n = parallelly::availableCores()) { # nolint
set_threads.list = function(x, n = availableCores()) { # nolint
lapply(x, set_threads, n = n)
}
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @importFrom graphics plot
#' @importFrom stats predict rnorm runif sd contr.treatment
#' @importFrom uuid UUIDgenerate
#' @importFrom parallelly availableCores
#'
#' @section Learn mlr3:
#' * Book on mlr3: \url{https://mlr3book.mlr-org.com}
Expand Down
10 changes: 5 additions & 5 deletions man/set_threads.Rd

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

0 comments on commit 4a5ec5d

Please sign in to comment.