assert_same_batch_size: Assert that Shapes have the Same Batch Size

View source: R/shape.R

assert_same_batch_sizeR Documentation

Assert that Shapes have the Same Batch Size

Description

Rejects inputs whose batch sizes, i.e. first dimensions, disagree. An unknown (NA) batch size is compatible with any other, so only the known ones have to agree.

Unlike the other assertions this returns the common batch size rather than its input, because that is what the caller needs next: an operator that drops the batch dimension while it works has to put it back afterwards.

Usage

assert_same_batch_size(shapes, id)

Arguments

shapes

(list() of integer())
The input shapes.

id

(character(1))
The id of the PipeOp, which the error message names.

Value

(integer(1)) The common batch size, invisibly, or NA_integer_ if no input has a known one.

See Also

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

Examples

assert_same_batch_size(list(c(8, 3), c(8, 5)), id = "nn_block")
# an unknown batch size is compatible with a known one, which is the one that is returned
assert_same_batch_size(list(c(NA, 3), c(8, 5)), id = "nn_block")
try(assert_same_batch_size(list(c(8, 3), c(4, 5)), id = "nn_block"))

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