#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 to target_shape.

A source_shape can be broadcast to a target_shape if, starting from the trailing (highest index) dimensions, the size in source_shape is either 1 or equal to the size in target_shape. Any additional leading dimensions of source_shape that don’t correspond to a dimension of target_shape must be 1. There are no restrictions on additional leading dimensions of target_shape that don’t correspond to a dimension of source_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

Returns:

absl::OkStatus() if the shapes are compatible.

Error absl::StatusCode::kInvalidArgument:

if the shapes are not compatible.