assert_shape: Assert a Shape

View source: R/shape.R

assert_shapeR Documentation

Assert a Shape

Description

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.

See Also

Other Shape Assertions: assert_dim_in_range(), assert_known_dims(), assert_ndim(), assert_not_batch_dim(), assert_positive_extent(), assert_same_batch_size(), assert_same_ndim(), assert_shapes()

Examples

assert_shape(c(NA, 3, 32, 32))
try(assert_shape("not a shape"))

mlr3torch documentation built on Oct. 30, 2026, 5:10 p.m.