Skip to contents

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.

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"))
#> Error : PipeOp 'nn_conv2d' requires the number of channels of the input shape to be known, but got shape (NA,NA,10,10).