Geometric and type description of a tensor.
TensorMeta is stored by value inside TensorImpl
(not on the heap) so that shape / dtype / device queries are a single
pointer dereference. Views share the same Storage as their
base tensor but carry an independent TensorMeta with
potentially different shape, stride, or implicit byte offset (the
offset is encoded in Storage).
Attributes
shapeShapestrideStridestride.size() == shape.size() to be considered a valid contiguous layout by is_contiguous_for.dtypeDtypeDtype::F32.deviceDeviceDevice::CPU.Notes
Equality of two TensorMeta instances is structural —
matching shape, stride, dtype, and device implies the two metas
describe layout-equivalent tensors (modulo storage offset).
Methods
2Returns whether the stored stride matches row-major (C-order) contiguous layout for elem_size-byte elements.
A tensor is C-contiguous when stride[i] = elem_size * prod(shape[i+1:]) for every axis i. A 0-dim scalar is
contiguous by definition.
Parameters
elem_ sizestd::size_tsizeof(float) for F32). Must match the dtype width for the result to be meaningful.Returns
booltrue if stride matches C-contiguous layout for the given element size, false otherwise. Returns false when stride.size() does not match shape.size().
Notes
Used by TensorImpl::is_contiguous and by op kernels that
require contiguous input — non-contiguous tensors must be
materialised via a copy before such kernels run.
Returns the total number of elements described by shape.
Computed as the product of all dimension sizes; a 0-dim scalar
(empty shape) returns 1 by convention.
Math
Returns
std::size_tshape[0] * shape[1] * ... * shape[N-1], or 1 for a scalar.
Notes
shape_numel is the one element-count rule; a second one here
cast a negative extent to 2^64 - 1 while allocation counted it
as empty. A negative extent raises InvalidArgument.