Skip to content

Commit

Permalink
docs: escape examples if torch not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
sebffischer committed Feb 7, 2024
1 parent d995f74 commit 7c9aa2c
Show file tree
Hide file tree
Showing 168 changed files with 29 additions and 14,864 deletions.
1 change: 1 addition & 0 deletions R/DataDescriptor.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#' @export
#' @include utils.R
#' @seealso ModelDescriptor, lazy_tensor
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # Create a dataset
#' dsg = dataset(
Expand Down
1 change: 1 addition & 0 deletions R/LearnerTorchModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' @family Graph Network
#' @include LearnerTorch.R
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # We show the learner using a classification task
#'
Expand Down
1 change: 1 addition & 0 deletions R/PipeOpModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#' @family Graph Network
#' @family PipeOp
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' ## creating an PipeOpModule manually
#'
Expand Down
1 change: 1 addition & 0 deletions R/PipeOpTaskPreprocTorch.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#'
#' @include PipeOpTorch.R
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # Creating a simple task
#' d = data.table(
Expand Down
1 change: 1 addition & 0 deletions R/PipeOpTorch.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#' [`Graph`] which allows the graph to be modified by-reference in different parts of the code.
#' @export
#' @family Graph Network
#' @examplesIf torch::torch_is_installed()
#' @examples
#' ## Creating a neural network
#' # In torch
Expand Down
1 change: 1 addition & 0 deletions R/PipeOpTorchCallbacks.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#' @family Model Configuration
#' @family PipeOp
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' po_cb = po("torch_callbacks", "checkpoint")
#' po_cb$param_set
Expand Down
4 changes: 4 additions & 0 deletions R/PipeOpTorchIngress.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ PipeOpTorchIngress = R6Class("PipeOpTorchIngress",
#' @return `TorchIngressToken` object.
#' @family Graph Network
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # Define a task for which we want to define an ingress token
#' task = tsk("iris")
Expand Down Expand Up @@ -177,6 +178,7 @@ print.TorchIngressToken = function(x, ...) {
#' @export
#' @family Graph Network
#' @family PipeOps
#' @examplesIf torch::torch_is_installed()
#' @examples
# We select the numeric features first
#' graph = po("select", selector = selector_type(c("numeric", "integer"))) %>>%
Expand Down Expand Up @@ -227,6 +229,7 @@ register_po("torch_ingress_num", PipeOpTorchIngressNumeric)
#' @family PipeOps
#' @family Graph Network
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
# We first select the categorical features
#' graph = po("select", selector = selector_type("factor")) %>>%
Expand Down Expand Up @@ -277,6 +280,7 @@ register_po("torch_ingress_categ", PipeOpTorchIngressCategorical)
#' @family Graph Network
#' @export
#' @include utils.R shape.R
#' @examplesIf torch::torch_is_installed()
#' @examples
#' po_ingress = po("torch_ingress_ltnsr")
#' task = tsk("lazy_iris")
Expand Down
1 change: 1 addition & 0 deletions R/PipeOpTorchLoss.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#' @family Model Configuration
#'
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' po_loss = po("torch_loss", loss = t_loss("cross_entropy"))
#' po_loss$param_set
Expand Down
2 changes: 2 additions & 0 deletions R/PipeOpTorchModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ PipeOpTorchModel = R6Class("PipeOpTorchModel",
#' @inheritSection mlr_pipeops_torch_model Internals
#' @family PipeOps
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # simple logistic regression
#'
Expand Down Expand Up @@ -150,6 +151,7 @@ PipeOpTorchModelClassif = R6Class("PipeOpTorchModelClassif",
#' @inheritSection mlr_pipeops_torch_model Internals
#' @family PipeOps
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # simple linear regression
#'
Expand Down
1 change: 1 addition & 0 deletions R/PipeOpTorchOptimizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' @family PipeOp
#' @family Model Configuration
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' po_opt = po("torch_optimizer", "sgd", lr = 0.01)
#' po_opt$param_set
Expand Down
1 change: 1 addition & 0 deletions R/TaskClassif_lazy_iris.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#'
#' @references
#' `r format_bib("anderson_1936")`
#' @examplesIf torch::torch_is_installed()
#' @examples
#' task = tsk("lazy_iris")
#' df = task$data()
Expand Down
2 changes: 2 additions & 0 deletions R/TorchCallback.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ as_torch_callbacks.character = function(x, clone = FALSE, ...) { # nolint
#' @family Torch Descriptor
#'
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # Create a new torch callback from an existing callback set
#' torch_callback = TorchCallback$new(CallbackSetCheckpoint)
Expand Down Expand Up @@ -247,6 +248,7 @@ TorchCallback = R6Class("TorchCallback",
#' @return [`TorchCallback`]
#' @include zzz.R CallbackSet.R
#' @family Callback
#' @examplesIf torch::torch_is_installed()
#' @examples
#' custom_tcb = torch_callback("custom",
#' initialize = function(name) {
Expand Down
1 change: 1 addition & 0 deletions R/TorchLoss.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ as_torch_loss.character = function(x, clone = FALSE, ...) { # nolint
#'
#' @family Torch Descriptor
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # Create a new torch loss
#' torch_loss = TorchLoss$new(torch_loss = nn_mse_loss, task_types = "regr")
Expand Down
2 changes: 2 additions & 0 deletions R/TorchOptimizer.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ as_torch_optimizer.character = function(x, clone = FALSE, ...) { # nolint
#'
#' @family Torch Descriptor
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # Create a new torch loss
#' torch_opt = TorchOptimizer$new(optim_adam, label = "adam")
Expand Down Expand Up @@ -146,6 +147,7 @@ TorchOptimizer = R6::R6Class("TorchOptimizer",
#' @family Torch Descriptor
#' @family Dictionary
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' mlr3torch_optimizers$get("adam")
#' # is equivalent to
Expand Down
1 change: 1 addition & 0 deletions R/lazy_tensor.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ is_lazy_tensor = function(x) {
#' 1. A new [`DataDescriptor`] is created
#'
#' @return [`lazy_tensor`]
#' @examplesIf torch::torch_is_installed()
#' @examples
#' lt = as_lazy_tensor(1:10)
#' add_five = po("module", module = function(x) x + 5)
Expand Down
1 change: 1 addition & 0 deletions R/materialize.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#' @param ... (any)\cr
#' Additional arguments.
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' lt1 = as_lazy_tensor(torch_randn(10, 3))
#' materialize(lt1, rbind = TRUE)
Expand Down
1 change: 1 addition & 0 deletions R/nn_graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#' @return [`nn_graph`]
#' @family Graph Network
#' @export
#' @examplesIf torch::torch_is_installed()
#' @examples
#' graph = mlr3pipelines::Graph$new()
#' graph$add_pipeop(po("module_1", module = nn_linear(10, 20)), clone = FALSE)
Expand Down
3 changes: 2 additions & 1 deletion R/reset_last_layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#' @return Same as input `model` with modified last layer.
#' @export
#'
#' @examplesIf torch::torch_is_installed()
#' @examples
#' \dontrun{
#' # AlexNet
#' if (mlr3misc::requires_namespaces("torchvision")) {
#' if (mlr3misc::requires_namespaces("torchvision") && torch::torch_is_installed(h)) {
#' model = torchvision::model_alexnet(pretrained = TRUE)
#' model$classifier[[7]]$out_feature
#' model = reset_last_layer(model, 10)
Expand Down
1 change: 1 addition & 0 deletions R/task_dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#' The device, e.g. `"cuda"` or `"cpu"`.
#' @export
#' @return [`torch::dataset`]
#' @examplesIf torch::torch_is_installed()
#' @examples
#' task = tsk("iris")
#' sepal_ingress = TorchIngressToken(
Expand Down
1 change: 1 addition & 0 deletions man-roxygen/learner_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#' <% id = paste0(task_types_vec[1], ".", name)%>
#' <% task_id = default_task_id(lrn(id)) %>
#'
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # Define the Learner and set parameter values
#' <%= sprintf("learner = lrn(\"%s\")", id)%>
Expand Down
2 changes: 2 additions & 0 deletions man-roxygen/pipeop_torch_example.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#' <% param_vals = if (exists("param_vals", inherits = FALSE)) paste0(", ", param_vals)%>
#'
#' @examplesIf torch::torch_is_installed()
#' @examples
#' # Construct the PipeOp
#' pipeop = po("<%=id %>"<%=param_vals%>)
Expand All @@ -10,6 +11,7 @@


# Maybe finish this at some point
# @examplesIf torch::torch_is_installed()
# md = ModelDescriptor(
# graph =
# )
Expand Down
166 changes: 0 additions & 166 deletions man/DataDescriptor.Rd

This file was deleted.

Loading

0 comments on commit 7c9aa2c

Please sign in to comment.