Skip to contents

Checks that shape is a valid shape, i.e. an integer() with at least one dimension, NA where a dimension is unknown. See the "Shape Inference" section of PipeOpTorch for the conventions.

Usage

assert_shape(
  shape,
  null_ok = FALSE,
  coerce = TRUE,
  unknown_batch = NULL,
  len = NULL
)

Arguments

shape

(integer())
A shape, with NA for the dimensions whose size is unknown.

null_ok

(logical(1))
Whether NULL, i.e. a wholly unknown shape, is valid.

coerce

(logical(1))
Whether to coerce the input to an integer() if possible.

unknown_batch

(logical(1) | NULL)
Whether the batch dimension must be unknown, i.e. NA. If left NULL (default), the first dimension can be NA or not.

len

(integer(1))
The required number of dimensions.

Value

The shape, coerced to an integer() if coerce is TRUE.

Examples

assert_shape(c(NA, 3, 32, 32))
#> [1] NA  3 32 32
try(assert_shape("not a shape"))
#> Error : Invalid shape: must be an integer vector, but is character.