Skip to contents

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.

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"))
#> Error : PipeOp 'nn_block' requires all its inputs to have the same batch size, but got the shapes [(8,3);(4,5)] (with the batch sizes 8 and 4).