pub struct TensorStorage { /* private fields */ }Expand description
Reference-counted tensor storage for memory management
Implementations§
Source§impl TensorStorage
impl TensorStorage
Sourcepub fn new(data: Vec<f32>, shape: Vec<usize>, dtype: DType) -> Self
pub fn new(data: Vec<f32>, shape: Vec<usize>, dtype: DType) -> Self
Create new tensor storage with data
Sourcepub fn new_pooled(shape: Vec<usize>, dtype: DType) -> FfiResult<Self>
pub fn new_pooled(shape: Vec<usize>, dtype: DType) -> FfiResult<Self>
Create new tensor storage with pooled allocation
Sourcepub fn from_external(data: Vec<f32>, shape: Vec<usize>, dtype: DType) -> Self
pub fn from_external(data: Vec<f32>, shape: Vec<usize>, dtype: DType) -> Self
Create tensor storage from external data (e.g., NumPy array)
Sourcepub fn data(&self) -> MutexGuard<'_, Vec<f32>>
pub fn data(&self) -> MutexGuard<'_, Vec<f32>>
Get a reference to the data (read-only)
Sourcepub fn data_mut(&self) -> MutexGuard<'_, Vec<f32>>
pub fn data_mut(&self) -> MutexGuard<'_, Vec<f32>>
Get a mutable reference to the data
Sourcepub fn view(&self, new_shape: Vec<usize>) -> FfiResult<Self>
pub fn view(&self, new_shape: Vec<usize>) -> FfiResult<Self>
Create a view with different shape (same data)
Sourcepub fn is_external(&self) -> bool
pub fn is_external(&self) -> bool
Check if this storage comes from external memory
Sourcepub fn grad(&self) -> MutexGuard<'_, Option<Vec<f32>>>
pub fn grad(&self) -> MutexGuard<'_, Option<Vec<f32>>>
Get gradient data (None if no gradient computed)
Sourcepub fn clear_grad(&self)
pub fn clear_grad(&self)
Clear gradient
Sourcepub fn version(&self) -> usize
pub fn version(&self) -> usize
Get current version (for gradient tracking) Uses atomic load for lock-free read access
Sourcepub fn increment_version(&self)
pub fn increment_version(&self)
Increment version (called on in-place operations) Uses atomic increment for lock-free update
Trait Implementations§
Source§impl Clone for TensorStorage
impl Clone for TensorStorage
Source§fn clone(&self) -> TensorStorage
fn clone(&self) -> TensorStorage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TensorStorage
impl Debug for TensorStorage
Source§impl Drop for TensorStorage
impl Drop for TensorStorage
Auto Trait Implementations§
impl !RefUnwindSafe for TensorStorage
impl !UnwindSafe for TensorStorage
impl Freeze for TensorStorage
impl Send for TensorStorage
impl Sync for TensorStorage
impl Unpin for TensorStorage
impl UnsafeUnpin for TensorStorage
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
Mutably borrows from an owned value. Read more
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> ⓘ
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 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> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.