Skip to main content

Storage

Struct Storage 

Source
pub struct Storage { /* private fields */ }
Expand description

An owned, reference-counted buffer of elements on one device.

Storage is untyped at the buffer level — a flat byte buffer plus the DType that says how to read it. Typed access is the business of the backend that allocated it; nothing else may reinterpret the bytes. Multiple tensors (views) may share one storage; storage never knows how many.

Implementations§

Source§

impl Storage

Source

pub fn cpu_zeros(numel: usize, dtype: DType) -> Self

Allocate zero-initialized CPU storage for numel elements of dtype.

Source

pub fn cpu_from_bytes(bytes: Vec<u8>, dtype: DType) -> Self

Wrap raw host bytes as CPU storage. The byte length must be a multiple of the dtype size; the caller asserts the encoding.

Source

pub fn dtype(&self) -> DType

The element type of this buffer.

Source

pub fn device(&self) -> Device

The device this buffer lives on.

Source

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

The raw bytes, when the storage is on the CPU.

Backends other than the CPU reference return None; they expose their own typed access instead.

Trait Implementations§

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