Skip to main content

Tensor

Struct Tensor 

Source
pub struct Tensor {
    pub name: String,
    pub dims: Vec<usize>,
    pub dtype: DType,
    pub ggml_type: u32,
    pub n_elements: usize,
    pub byte_len: usize,
    pub relative_offset: usize,
    pub absolute_offset: usize,
}
Expand description

A single tensor’s directory entry: name, shape, dtype, and offsets.

This is a metadata-only descriptor — it owns no weight data. Use GgufLayout::tensor_bytes to obtain the raw payload.

Fields§

§name: String

Full tensor name as stored in the GGUF directory.

§dims: Vec<usize>

Shape dimensions (GGML innermost-first order).

§dtype: DType

Parsed dtype enum.

§ggml_type: u32

Raw ggml_type code (preserved for round-tripping).

§n_elements: usize

Total number of elements (product of dims).

§byte_len: usize

Total byte length of the tensor payload.

§relative_offset: usize

Offset relative to the tensor data region start.

§absolute_offset: usize

Absolute byte offset within the file buffer.

Implementations§

Source§

impl Tensor

Source

pub fn read_f32_values(&self, bytes: &[u8]) -> Result<Vec<f32>>

Read the raw tensor bytes as little-endian f32 values.

Only valid for DType::F32 tensors; returns an error otherwise.

Source

pub fn read_u16_values(&self, bytes: &[u8]) -> Result<Vec<u16>>

Decode F16/BF16 tensor bytes into raw u16 lane values using little-endian chunk parsing (no numeric conversion).

Source

pub fn dequantize_f16(&self, bytes: &[u8]) -> Result<Vec<f32>>

Decode an F16 tensor into a newly-allocated Vec<f32>. The only numeric conversion exposed by this crate — purely a bit-level reinterpretation of each 16-bit half into a 32-bit float.

Trait Implementations§

Source§

impl Clone for Tensor

Source§

fn clone(&self) -> Self

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 Tensor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Tensor

§

impl Freeze for Tensor

§

impl Move for Tensor

§

impl RefUnwindSafe for Tensor

§

impl Send for Tensor
where RawVecInner: Send,

§

impl Sync for Tensor
where RawVecInner: Sync,

§

impl Unpin for Tensor
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Tensor

§

impl UnwindSafe for Tensor
where RawVecInner: UnwindSafe,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.