Skip to main content

Storage

Enum Storage 

Source
pub enum Storage {
    F32(Vec<f32>),
    F16(Vec<u16>),
    BF16(Vec<u16>),
    I8(Vec<i8>),
    I32(Vec<i32>),
    Quantized {
        dtype: DType,
        bytes: Vec<u8>,
    },
}
Expand description

An owned CPU buffer of tensor elements.

Variants§

§

F32(Vec<f32>)

§

F16(Vec<u16>)

Raw IEEE 754 binary16 bits. Stored as u16 rather than a float type because Rust’s f32/f64 are the only floats with hardware and library support; every element must go through crate::half::f16_to_f32 to be computed on.

§

BF16(Vec<u16>)

Raw bfloat16 bits, likewise u16; see crate::half::bf16_to_f32.

§

I8(Vec<i8>)

§

I32(Vec<i32>)

§

Quantized

Any block-quantized format (DType::Q4_0, DType::Q4_1, DType::Q5_0, DType::Q5_1, DType::Q8_0): raw on-disk block bytes plus the tag saying how to decode them. Never indexed elementwise directly — see DType::is_quantized and [crate::quant].

Fields

§dtype: DType
§bytes: Vec<u8>

Implementations§

Source§

impl Storage

Source

pub fn dtype(&self) -> DType

The element type this storage holds.

Source

pub fn len(&self) -> usize

Number of logical elements this storage holds.

For quantized storage this is derived from the byte length (every byte belongs to some block, and every block decodes to exactly DType::block_size elements) rather than tracked separately, which is only sound because Self::new_quantized is the sole constructor and it guarantees the byte length is a whole number of blocks.

Source

pub fn is_empty(&self) -> bool

Source

pub fn new_quantized( dtype: DType, bytes: Vec<u8>, elem_count: usize, ) -> Result<Self>

Builds quantized storage for elem_count elements of dtype from raw block bytes.

Rejects two distinct failure modes with distinct errors, both already defined by kopitiam-core for exactly this purpose:

  • elem_count is not a whole number of blocks (e.g. 33 elements of a 32-wide format) -> Error::PartialQuantizedBlock. This is not a rounding question — there is no valid byte layout for a partial block, so it is rejected before ever looking at bytes.
  • bytes does not contain exactly the number of bytes that elem_count blocks require -> Error::StorageTooSmall. This catches truncated reads and mismatched shape/data pairs at construction time instead of an out-of-bounds panic on first use.

Trait Implementations§

Source§

impl Clone for Storage

Source§

fn clone(&self) -> Storage

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 Storage

Source§

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

Formats the value using the given formatter. 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, 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.