Skip to content

Commit

Permalink
Merge pull request #1395 from rstudio/update-guides
Browse files Browse the repository at this point in the history
Update guides
  • Loading branch information
t-kalinowski authored Jan 18, 2024
2 parents 7d1529f + 03732d7 commit 3667ec0
Show file tree
Hide file tree
Showing 38 changed files with 667 additions and 585 deletions.
4 changes: 2 additions & 2 deletions R/image-utils.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

#' Saves an image stored as a NumPy array to a path or file object.
#' Saves an image stored as an array to a path or file object.
#'
#' @param path
#' Path or file object.
#'
#' @param x
#' NumPy array.
#' An array.
#'
#' @param data_format
#' Image data format, either `"channels_first"` or
Expand Down
7 changes: 6 additions & 1 deletion R/model-training.R
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ function(x,
line_length = getOption("width"), # width - (12L * show_trainable),
positions = NULL,
expand_nested = FALSE,
show_trainable = x$built && as.logical(length(x$non_trainable_weights)),
show_trainable = NA,
...,
# width = getOption("width"),
# rich = TRUE, ??
Expand All @@ -898,6 +898,11 @@ function(x,
args <- capture_args(ignore = c("x", "compact", "width"),
force = c("show_trainable", "line_length"))

if(is.na(args$show_trainable)) {
built <- as_r_value(py_get_attr(x, "built", silent = TRUE)) %||% FALSE
args$show_trainable <- built && as.logical(length(x$non_trainable_weights))
}

# Do we need to check for model$built before calling summary?
with_rich_config(
out <- trimws(py_capture_output(do.call(x$summary, args)))
Expand Down
18 changes: 12 additions & 6 deletions R/py-classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function(classname,
inherit = NULL,
parent_env = parent.frame(),
private = list(),
modifiers = quote(expr =),
# modifiers = quote(expr =),
default_formals = function(...) {})
{
# force all new_py_type() args
Expand Down Expand Up @@ -63,10 +63,10 @@ function(classname,
frmls$self <- NULL

bdy <- bquote({
args <- capture_args(.(modifiers), enforce_all_dots_named = FALSE)
args <- capture_args(enforce_all_dots_named = FALSE) # .(modifiers),
do.call(.(as.name(classname)), args)
})
rm(modifiers, default_formals) # free memory
rm(default_formals) # free memory ; rm(modifiers)

as.function.default(c(frmls, bdy))
}
Expand Down Expand Up @@ -431,18 +431,24 @@ py_func2 <- function(fn, convert, name = deparse(substitute(fn))) {
pass_sig <- iterate(sig$parameters$values(), function(p) {
if(p$kind == inspect$Parameter$POSITIONAL_ONLY)
p$name
else if (p$kind == inspect$Parameter$POSITIONAL_OR_KEYWORD)
# pass as positional, since there might be a positional args collector up ahead, and
# having kwargs before a positional collector is illegal
p$name
else if (p$kind == inspect$Parameter$VAR_POSITIONAL)
paste0("*", p$name)
else if (p$kind == inspect$Parameter$VAR_KEYWORD)
paste0("**", p$name)
else
else if(p$kind == inspect$Parameter$KEYWORD_ONLY)
paste0(p$name, "=", p$name)
else
stop("Unrecognized function argument type: ", p$name)
})
pass_sig <- paste0(pass_sig, collapse = ", ")
code <- glue::glue("
def wrap_fn(_fn):
def wrap_fn(r_fn):
def {name}{py_str(sig)}:
return _fn({pass_sig})
return r_fn({pass_sig})
return {name}
")
util <- reticulate::py_run_string(code, local = TRUE, convert = convert)
Expand Down
6 changes: 4 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,10 @@ function(x,
force = c("show_layer_names"))
args$model <- x

if(is.na(show_trainable))
show_trainable <- x$built && as.logical(length(x$non_trainable_weights))
if (is.na(show_trainable)) {
built <- as_r_value(py_get_attr(x, "built", silent = TRUE)) %||% FALSE
show_trainable <- built && as.logical(length(x$non_trainable_weights))
}
args$show_trainable <- show_trainable

if (is.null(to_file)) {
Expand Down
148 changes: 84 additions & 64 deletions docs/articles/custom_train_step_in_tensorflow.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/articles/functional_api.html

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

8 changes: 4 additions & 4 deletions docs/articles/getting_started.html

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

Binary file modified docs/articles/getting_started/unnamed-chunk-11-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3667ec0

Please sign in to comment.