Returns the total number of elements implied by a shape.
The product is computed in std::size_t to avoid sign issues when
the caller wants to use the result for allocation sizing.
Parameters
shapeShapeShape vector to reduce. May be empty (scalar) or contain negative sentinel values.
Returns
std::size_tProduct of all dimensions. 1 for an empty shape (scalar convention); 0 as soon as any dimension is negative — the caller is responsible for not allocating storage in that case.
Notes
The early-return-zero behaviour for negative dims is deliberate: it lets
dynamic-shape pipelines pass an unresolved Shape through generic
code paths without manually filtering for sentinels.
Examples
shape_numel({}) // 1 (scalar)
shape_numel({3, 4}) // 12
shape_numel({-1, 8}) // 0 (unresolved leading dim)