Storage

Struct Storage 

Source
pub struct Storage<T: Scalar> { /* private fields */ }
Expand description

Raw memory storage for tensor data.

Storage is the fundamental building block for tensors. It manages a contiguous block of memory on a specific device and is reference-counted to allow efficient sharing between tensor views.

Implementations§

Source§

impl<T: Scalar> Storage<T>

Source

pub fn zeros(len: usize, device: Device) -> Self

Creates new storage with the given capacity, initialized to zero.

§Arguments
  • len - Number of elements to allocate
  • device - Device to allocate on
§Returns

New storage initialized to zeros.

Source

pub fn from_vec(data: Vec<T>, device: Device) -> Self

Creates storage from an existing vector.

§Arguments
  • data - Vector of data
  • device - Device the storage is on
§Returns

New storage wrapping the data.

Source

pub fn from_slice(data: &[T], device: Device) -> Self

Creates storage from a slice by copying the data.

§Arguments
  • data - Slice of data to copy
  • device - Device to allocate on
§Returns

New storage containing a copy of the data.

Source

pub const fn len(&self) -> usize

Returns the number of elements in this storage view.

Source

pub const fn is_empty(&self) -> bool

Returns true if the storage is empty.

Source

pub const fn offset(&self) -> usize

Returns the offset into the underlying buffer.

Source

pub fn device(&self) -> Device

Returns the device this storage is on.

Source

pub fn size_bytes(&self) -> usize

Returns the size in bytes of this storage.

Source

pub fn slice(&self, offset: usize, len: usize) -> Result<Self>

Creates a view into a portion of this storage.

§Arguments
  • offset - Starting offset relative to this view
  • len - Number of elements in the new view
§Returns

A new storage view, or error if bounds are invalid.

Source

pub fn is_unique(&self) -> bool

Returns true if this storage is uniquely owned (not shared).

Source

pub fn as_slice(&self) -> StorageReadGuard<'_, T>

Returns an immutable reference to the data.

§Panics

Panics if the lock is poisoned.

Source

pub fn as_slice_mut(&self) -> StorageWriteGuard<'_, T>

Returns a mutable reference to the data.

§Panics

Panics if the lock is poisoned.

Source

pub fn copy_from(&self, other: &Self) -> Result<()>

Copies data from another storage into this one.

§Arguments
  • other - Source storage to copy from
§Returns

Ok if successful, error if lengths don’t match.

Source

pub fn deep_copy(&self) -> Self

Makes a deep copy of this storage.

Source

pub fn to_device(&self, device: Device) -> Result<Self>

Transfers this storage to a different device.

§Arguments
  • device - Target device
§Returns

New storage on the target device.

Trait Implementations§

Source§

impl<T: Scalar> Clone for Storage<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Scalar> Debug for Storage<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Storage<T>

§

impl<T> !RefUnwindSafe for Storage<T>

§

impl<T> Send for Storage<T>

§

impl<T> Sync for Storage<T>

§

impl<T> Unpin for Storage<T>

§

impl<T> !UnwindSafe for Storage<T>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.