assert_known_dims: Assert that Dimensions are Known

View source: R/shape.R

assert_known_dimsR Documentation

Assert that Dimensions are Known

Description

Ensure that a specific dimension is known, i.e. not NA.

Usage

assert_known_dims(shape, dims, what, id = NULL)

Arguments

shape

(integer())
The input shape.

dims

(integer())
Indices of the dimensions that must be known.

what

(character(1))
Describes those dimensions in the error message, e.g. "the channel dimension (dimension 2)".

id

(character(1) | NULL)
The id of the PipeOp the assertion is made for, which the error message names. NULL when the assertion is not made for a PipeOp.

Value

The shape, invisibly.

See Also

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

Examples

# a convolution needs the number of input channels, but not the spatial extent
assert_known_dims(c(NA, 3, NA, NA), 2, "the number of channels", id = "nn_conv2d")
try(assert_known_dims(c(NA, NA, 10, 10), 2, "the number of channels", id = "nn_conv2d"))

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