-
#include "tensorstore/strided_layout.h"
-
absl::Status
tensorstore::ValidateShapeBroadcast(span<const Index> source_shape,
span<const Index> target_shape); Validates that
source_shape
can be broadcast totarget_shape
.A
source_shape
can be broadcast to atarget_shape
if, starting from the trailing (highest index) dimensions, the size insource_shape
is either1
or equal to the size intarget_shape
. Any additional leading dimensions ofsource_shape
that don’t correspond to a dimension oftarget_shape
must be1
. There are no restrictions on additional leading dimensions oftarget_shape
that don’t correspond to a dimension ofsource_shape
.For example:
[VALID] source_shape: 5 target_shape: 4, 5
[VALID] source_shape: 4, 1 target_shape: 4, 5
[VALID] source_shape: 1, 1, 5 target_shape: 4, 5
[INVALID] source_shape: 2, 5 target_shape: 4, 5
[INVALID] source_shape: 2, 5 target_shape: 5