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.
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"))
#> 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).