Skip to content

Commit

Permalink
Add shape() examples
Browse files Browse the repository at this point in the history
  • Loading branch information
t-kalinowski committed May 21, 2024
1 parent 1b4f1cd commit cd205e9
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions R/shape.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#' Tensor shape utility
#'
#' This function can be used to create or get the shape of an object.
#' This function can be used to get or create a tensor shape.
#'
#' # Examples
#' ```{r}
Expand Down Expand Up @@ -53,6 +53,15 @@
#' A useful pattern is to unpack the `shape()` with `%<-%`, like this:
#' ```r
#' c(batch_size, seq_len, channels) %<-% shape(x)
#'
#' # `%<-%` also has support for skipping values
#' # during unpacking with `.` and `...`. For example,
#' # To retrieve just the first and/or last dim:
#' c(batch_size, ...) %<-% shape(x)
#' c(batch_size, ., .) %<-% shape(x)
#' c(..., channels) %<-% shape(x)
#' c(batch_size, ..., channels) %<-% shape(x)
#' c(batch_size, ., channels) %<-% shape(x)
#' ```
#'
#' ```{r}
Expand Down Expand Up @@ -98,8 +107,8 @@
#' via `as.integer()`.
#'
#' @returns A list with a `"keras_shape"` class attribute. Each element of the
#' list will be either a) `NULL`, b) an integer or c) a scalar integer tensor
#' (e.g., when supplied a TF tensor with a unspecified dimension in a function
#' list will be either a) `NULL`, b) an R integer or c) a scalar integer tensor
#' (e.g., when supplied a TF tensor with an unspecified dimension in a function
#' being traced).
#'
#' @export
Expand Down Expand Up @@ -154,7 +163,7 @@ shape <- function(...) {

#' @export
#' @rdname shape
#' @param x A 'keras_shape' object
#' @param x A `keras_shape` object.
#' @param prefix Whether to format the shape object with a prefix. Defaults to
#' `"shape"`.
format.keras_shape <- function(x, ..., prefix = TRUE) {
Expand Down

0 comments on commit cd205e9

Please sign in to comment.