pub struct ShapeData {
pub dtype: DataType,
pub dims: Vec<usize>,
pub elems: Vec<DimExpr>,
pub float_elems: Option<Vec<f64>>,
}Expand description
The known element values of a rank-0 or rank-1 integer tensor flowing through a shape-computation subgraph.
Integer tensors carry their values in elems as
DimExprs. Floating-point scalar constants (needed by Range, whose
float form the CPU kernel supports) are carried additively in
float_elems; for those, elems is empty. Eq is not
derived because f64 is not Eq — ShapeData is only ever used as a map
value, so structural equality is not required.
Fields§
§dtype: DataTypeThe element type (Int64/Int32, or Bool for masks; Float32/
Float64 for the float-scalar side-channel).
dims: Vec<usize>Static dimensions. Empty == rank-0 scalar; [n] == rank-1 vector.
elems: Vec<DimExpr>Row-major integer elements. Length is 1 for a scalar, dims[0] for a
vector. Empty for floating-point shape-data (see float_elems).
float_elems: Option<Vec<f64>>Row-major floating-point elements for rank-0/rank-1 floating-point
constants used by Range and Resize; None otherwise.
Implementations§
Source§impl ShapeData
impl ShapeData
Sourcepub fn float_scalar(dtype: DataType, value: f64) -> Self
pub fn float_scalar(dtype: DataType, value: f64) -> Self
A rank-0 floating-point scalar holding value.
Sourcepub fn float_vector(dtype: DataType, values: Vec<f64>) -> Self
pub fn float_vector(dtype: DataType, values: Vec<f64>) -> Self
A rank-1 floating-point vector holding values.
Sourcepub fn as_float_scalar(&self) -> Option<f64>
pub fn as_float_scalar(&self) -> Option<f64>
This value interpreted as a floating-point scalar, if it is one.
Sourcepub fn as_float_vector(&self) -> Option<&[f64]>
pub fn as_float_vector(&self) -> Option<&[f64]>
This value interpreted as a floating-point vector, if it is one.
Sourcepub fn within_bounds(&self) -> bool
pub fn within_bounds(&self) -> bool
Whether the element count is within MAX_SHAPE_DATA_ELEMS.
Sourcepub fn as_shape(&self) -> Vec<DimExpr>
pub fn as_shape(&self) -> Vec<DimExpr>
This value’s contents interpreted as a shape (each element is a dim).
Used by Reshape/Expand/ConstantOfShape to turn a resolved shape
vector into the output shape.
Sourcepub fn from_tensor(dtype: DataType, dims: &[usize], data: &[u8]) -> Option<Self>
pub fn from_tensor(dtype: DataType, dims: &[usize], data: &[u8]) -> Option<Self>
Extract shape-data from a concrete constant tensor, if it is a small
(rank ≤ 1, within MAX_SHAPE_DATA_ELEMS) integer or boolean tensor.
Non-integer tensors, higher-rank tensors, and over-large tensors are not
tracked (returns None) — only the shape-computation operands matter.