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>
impl<T: Scalar> Storage<T>
Sourcepub fn zeros(len: usize, device: Device) -> Self
pub fn zeros(len: usize, device: Device) -> Self
Creates new storage with the given capacity, initialized to zero.
Sourcepub fn from_vec(data: Vec<T>, device: Device) -> Self
pub fn from_vec(data: Vec<T>, device: Device) -> Self
Creates storage from an existing vector (always on CPU).
Sourcepub fn from_slice(data: &[T], device: Device) -> Self
pub fn from_slice(data: &[T], device: Device) -> Self
Creates storage from a slice by copying the data.
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Returns the size in bytes of this storage.
Sourcepub fn slice(&self, offset: usize, len: usize) -> Result<Self>
pub fn slice(&self, offset: usize, len: usize) -> Result<Self>
Creates a view into a portion of this storage.
Sourcepub fn as_slice(&self) -> StorageReadGuard<'_, T>
pub fn as_slice(&self) -> StorageReadGuard<'_, T>
Returns an immutable reference to the CPU data.
§Panics
Panics if the storage is on GPU. Use to_vec() for device-safe access.
Sourcepub fn as_slice_mut(&self) -> StorageWriteGuard<'_, T>
pub fn as_slice_mut(&self) -> StorageWriteGuard<'_, T>
Sourcepub fn copy_from(&self, other: &Self) -> Result<()>
pub fn copy_from(&self, other: &Self) -> Result<()>
Copies data from another storage into this one.
Sourcepub fn deep_copy(&self) -> Self
pub fn deep_copy(&self) -> Self
Makes a deep copy of this storage.
For GPU storage, this only works for Storage<f32>.
Other types will panic on GPU storage.
Trait Implementations§
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> UnsafeUnpin for Storage<T>
impl<T> !UnwindSafe for Storage<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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