Skip to main content

Tensor

Struct Tensor 

Source
pub struct Tensor<'a> { /* private fields */ }
Expand description

Read-only borrow of a tensor owned by a crate::Interpreter.

Tensor<'a> cannot outlive the interpreter it came from — the borrow checker enforces this by attaching a phantom lifetime to the underlying pointer.

Implementations§

Source§

impl<'a> Tensor<'a>

Source

pub fn dims(&self) -> Vec<i32>

Tensor shape as a list of per-axis dimensions.

Source

pub fn dtype(&self) -> TfLiteType

Element type of the tensor.

Source

pub fn name(&self) -> Option<&str>

Tensor name as reported by the model, if any.

Source

pub fn byte_size(&self) -> usize

Total size of the tensor’s data buffer in bytes.

Source

pub fn quantization(&self) -> TfLiteQuantizationParams

Affine quantization parameters (scale, zero_point).

Source

pub fn data(&self) -> &[u8]

Raw byte view of the tensor’s data buffer.

Returns an empty slice if the C API reports a NULL data pointer.

Source

pub fn as_slice_f32(&self) -> Result<&[f32]>

Typed &[f32] view; errors if the tensor is not Float32.

Source

pub fn as_slice_i8(&self) -> Result<&[i8]>

Typed &[i8] view; errors if the tensor is not Int8.

Source

pub fn as_slice_u8(&self) -> Result<&[u8]>

Typed &[u8] view; errors if the tensor is not UInt8.

Source

pub fn as_slice_i32(&self) -> Result<&[i32]>

Typed &[i32] view; errors if the tensor is not Int32.

Source

pub fn to_vec_f32(&self) -> Result<Vec<f32>>

Read the tensor as a fresh Vec<f32>, dequantizing Int8/UInt8 using the tensor’s quantization parameters.

The dequantization formula is real = (q - zero_point) * scale. Float32 tensors are copied straight through.

Auto Trait Implementations§

§

impl<'a> !Send for Tensor<'a>

§

impl<'a> !Sync for Tensor<'a>

§

impl<'a> Freeze for Tensor<'a>

§

impl<'a> RefUnwindSafe for Tensor<'a>

§

impl<'a> Unpin for Tensor<'a>

§

impl<'a> UnsafeUnpin for Tensor<'a>

§

impl<'a> UnwindSafe for Tensor<'a>

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> 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, 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.