Skip to main content

TensorData

Enum TensorData 

Source
pub enum TensorData {
    Owned(Vec<u8>),
    Borrowed(&'static [u8]),
    Shared(Arc<Vec<u8>>),
    Mapped {
        mmap: Arc<Mmap>,
        offset: usize,
        length: usize,
    },
    Empty,
}
Expand description

Container for tensor data with different storage backends

Variants§

§

Owned(Vec<u8>)

Owned byte vector (most common case)

§

Borrowed(&'static [u8])

Reference to borrowed data (zero-copy when possible)

§

Shared(Arc<Vec<u8>>)

Shared reference-counted data

§

Mapped

Memory-mapped data (when using mmap feature)

Fields

§mmap: Arc<Mmap>

The memory map

§offset: usize

Offset within the map

§length: usize

Length of the data

§

Empty

Empty/uninitialized data

Implementations§

Source§

impl TensorData

Source

pub fn new_owned(data: Vec<u8>) -> Self

Create new owned tensor data

Source

pub fn new_borrowed(data: &'static [u8]) -> Self

Create new borrowed tensor data

Source

pub fn new_shared(data: Vec<u8>) -> Self

Create new shared tensor data

Source

pub fn empty() -> Self

Create empty tensor data

Source

pub fn zeros(size: usize) -> Self

Create tensor data with specified size filled with zeros

Source

pub fn try_zeros(size: usize) -> Result<Self>

Fallibly create tensor data with the specified size filled with zeros.

Source

pub fn filled(size: usize, value: u8) -> Self

Create tensor data with specified size filled with a value

Source

pub fn try_filled(size: usize, value: u8) -> Result<Self>

Fallibly create tensor data with the specified size and fill value.

Source

pub fn new_mapped(mmap: Arc<Mmap>, offset: usize, length: usize) -> Result<Self>

Create memory-mapped tensor data

Source

pub fn len(&self) -> usize

Get the length of the tensor data in bytes

Source

pub fn is_empty(&self) -> bool

Check if the tensor data is empty

Source

pub fn as_slice(&self) -> &[u8] ⓘ

Get a slice of the tensor data.

A Mapped value constructed directly with an invalid range yields an empty slice. Use Self::try_as_slice when invalid mapped data must be distinguished from valid empty data.

Source

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

Get a checked slice of the tensor data.

Unlike Self::as_slice, this reports an invalid directly constructed memory-mapped range as GGUFError::InvalidTensorData.

Source

pub fn as_mut_slice(&mut self) -> Option<&mut [u8]>

Get mutable access to the data (only for owned data)

Source

pub fn to_owned(&self) -> Vec<u8> ⓘ

Convert to owned data (cloning if necessary)

Source

pub fn try_to_owned(&self) -> Result<Vec<u8>>

Convert to owned data while reporting invalid mapped ranges and allocation failure.

Source

pub fn into_owned(self) -> Vec<u8> ⓘ

Take ownership of the data if possible, otherwise clone

Source

pub fn storage_type(&self) -> TensorStorageType

Get the storage type

Source

pub fn storage_info(&self) -> TensorDataInfo

Get storage information

Source

pub fn is_aligned(&self) -> bool

Check if the data is properly aligned

Source

pub fn is_aligned_to(&self, alignment: usize) -> bool

Check if the data is aligned to a specific boundary

Source

pub fn alignment(&self) -> Option<usize>

Get the alignment of the data pointer

Source

pub fn slice(&self, start: usize, length: usize) -> Result<TensorData>

Create a slice of the tensor data

Source

pub fn concat(&self, other: &TensorData) -> TensorData

Concatenate with another tensor data

Source

pub fn content_equals(&self, other: &TensorData) -> bool

Check if two tensor data instances have the same content

Source

pub fn hex_preview(&self, max_bytes: usize) -> String

Get a hexadecimal representation of the first few bytes (for debugging)

Source

pub fn validate(&self) -> Result<()>

Validate the tensor data for basic consistency

Source

pub fn checksum(&self) -> u32

Calculate a small non-cryptographic checksum for caller-side comparison.

This value is not collision resistant and does not establish integrity or authenticity without a separately trusted reference value.

Source

pub fn memory_usage(&self) -> TensorMemoryUsage

Get memory usage information

Trait Implementations§

Source§

impl Clone for TensorData

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 TensorData

Source§

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

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

impl Default for TensorData

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for TensorData

Available on crate feature std only.
Source§

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

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

impl PartialEq for TensorData

Source§

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

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

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

Inequality operator !=. Read more

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.