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

Context aliases #114

Merged
merged 2 commits into from
Feb 14, 2023
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 .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