Skip to content

Commit

Permalink
Merge pull request #114 from mlverse/context-opt
Browse files Browse the repository at this point in the history
Context aliases
  • Loading branch information
dfalbel committed Feb 14, 2023
2 parents a7fbcac + 1bc847d commit 7b33a01
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
GPU:
runs-on: ['self-hosted', 'gpu']
runs-on: ['self-hosted', 'gce', 'gpu']
name: 'gpu'

container:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage-pak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: test-coverage
jobs:
test-coverage:

runs-on: ['self-hosted', 'gpu']
runs-on: ['self-hosted', 'gce', 'gpu']

container:
image: nvidia/cuda:11.3.1-cudnn8-devel-ubuntu18.04
Expand Down
24 changes: 20 additions & 4 deletions R/context.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,30 @@ context <- R6::R6Class(
},
#' @field opt Current optimizer.
opt = function(new) {
if (missing(new))
return(private$.opt)
if (missing(new)) {
if (!is.null(private$.opt)) {
return(private$.opt)
} else {
if (length(self$optimizers) == 1) {
return(self$optimizers[[1]])
}
}
cli::cli_abort("{.var ctx$opt} not set.")
}
private$.opt <- new
},
#' @field opt_name Current optimizer name.
opt_name = function(new) {
if (missing(new))
return(private$.opt_name)
if (missing(new)) {
if (!is.null(private$.opt_name)) {
return(private$.opt_name)
} else {
if (length(self$optimizers) == 1) {
return(names(self$optimizers))
}
}
cli::cli_abort("{.var ctx$opt_name} not set.")
}
private$.opt_name <- new
},
#' @field data Current dataloader in use.
Expand Down

0 comments on commit 7b33a01

Please sign in to comment.