Skip to content

Commit cd205e9

Browse files
committed
Add shape() examples
1 parent 1b4f1cd commit cd205e9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

R/shape.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#' Tensor shape utility
33
#'
4-
#' This function can be used to create or get the shape of an object.
4+
#' This function can be used to get or create a tensor shape.
55
#'
66
#' # Examples
77
#' ```{r}
@@ -53,6 +53,15 @@
5353
#' A useful pattern is to unpack the `shape()` with `%<-%`, like this:
5454
#' ```r
5555
#' c(batch_size, seq_len, channels) %<-% shape(x)
56+
#'
57+
#' # `%<-%` also has support for skipping values
58+
#' # during unpacking with `.` and `...`. For example,
59+
#' # To retrieve just the first and/or last dim:
60+
#' c(batch_size, ...) %<-% shape(x)
61+
#' c(batch_size, ., .) %<-% shape(x)
62+
#' c(..., channels) %<-% shape(x)
63+
#' c(batch_size, ..., channels) %<-% shape(x)
64+
#' c(batch_size, ., channels) %<-% shape(x)
5665
#' ```
5766
#'
5867
#' ```{r}
@@ -98,8 +107,8 @@
98107
#' via `as.integer()`.
99108
#'
100109
#' @returns A list with a `"keras_shape"` class attribute. Each element of the
101-
#' list will be either a) `NULL`, b) an integer or c) a scalar integer tensor
102-
#' (e.g., when supplied a TF tensor with a unspecified dimension in a function
110+
#' list will be either a) `NULL`, b) an R integer or c) a scalar integer tensor
111+
#' (e.g., when supplied a TF tensor with an unspecified dimension in a function
103112
#' being traced).
104113
#'
105114
#' @export
@@ -154,7 +163,7 @@ shape <- function(...) {
154163

155164
#' @export
156165
#' @rdname shape
157-
#' @param x A 'keras_shape' object
166+
#' @param x A `keras_shape` object.
158167
#' @param prefix Whether to format the shape object with a prefix. Defaults to
159168
#' `"shape"`.
160169
format.keras_shape <- function(x, ..., prefix = TRUE) {

0 commit comments

Comments
 (0)