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>
impl<'a> Tensor<'a>
Sourcepub fn dtype(&self) -> TfLiteType
pub fn dtype(&self) -> TfLiteType
Element type of the tensor.
Sourcepub fn quantization(&self) -> TfLiteQuantizationParams
pub fn quantization(&self) -> TfLiteQuantizationParams
Affine quantization parameters (scale, zero_point).
Sourcepub fn data(&self) -> &[u8] ⓘ
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.
Sourcepub fn as_slice_f32(&self) -> Result<&[f32]>
pub fn as_slice_f32(&self) -> Result<&[f32]>
Typed &[f32] view; errors if the tensor is not Float32.
Sourcepub fn as_slice_i8(&self) -> Result<&[i8]>
pub fn as_slice_i8(&self) -> Result<&[i8]>
Typed &[i8] view; errors if the tensor is not Int8.
Sourcepub fn as_slice_u8(&self) -> Result<&[u8]>
pub fn as_slice_u8(&self) -> Result<&[u8]>
Typed &[u8] view; errors if the tensor is not UInt8.
Sourcepub fn as_slice_i32(&self) -> Result<&[i32]>
pub fn as_slice_i32(&self) -> Result<&[i32]>
Typed &[i32] view; errors if the tensor is not Int32.
Sourcepub fn to_vec_f32(&self) -> Result<Vec<f32>>
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.