Skip to main content

ShapeData

Struct ShapeData 

Source
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 EqShapeData is only ever used as a map value, so structural equality is not required.

Fields§

§dtype: DataType

The 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

Source

pub fn scalar(dtype: DataType, value: DimExpr) -> Self

A rank-0 scalar holding value.

Source

pub fn vector(dtype: DataType, elems: Vec<DimExpr>) -> Self

A rank-1 vector holding elems.

Source

pub fn float_scalar(dtype: DataType, value: f64) -> Self

A rank-0 floating-point scalar holding value.

Source

pub fn float_vector(dtype: DataType, values: Vec<f64>) -> Self

A rank-1 floating-point vector holding values.

Source

pub fn as_float_scalar(&self) -> Option<f64>

This value interpreted as a floating-point scalar, if it is one.

Source

pub fn as_float_vector(&self) -> Option<&[f64]>

This value interpreted as a floating-point vector, if it is one.

Source

pub fn is_scalar(&self) -> bool

Whether this is a rank-0 scalar.

Source

pub fn within_bounds(&self) -> bool

Whether the element count is within MAX_SHAPE_DATA_ELEMS.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for ShapeData

Source§

fn clone(&self) -> ShapeData

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ShapeData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ShapeData

Source§

fn eq(&self, other: &ShapeData) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ShapeData

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.