Returns the total number of elements implied by a shape — the one element-count rule; TensorMeta::numel and every allocation sized by a shape go through it.
The product is computed in std::size_t so the result can size an
allocation directly.
Parameters
shapeShapeA concrete shape. May be empty (scalar).
Returns
std::size_tProduct of all dimensions. 1 for an empty shape (scalar convention).
Raises
InvalidArgumentA dimension is negative (
throw_negative_dim). It has no count: as a size_t it is 2^64 - 1, and a kernel that walks that count runs off its buffer.Examples
:: shape_numel({}) // 1 (scalar)
shape_numel({3, 4}) // 12
shape_numel({-1, 8}) // throws InvalidArgument