pub struct TensorData<T> { /* private fields */ }Expand description
Tensor data in a contiguous memory layout.
This struct holds tensor data in row-major (C-style) order, suitable for direct transfer to ML frameworks.
Implementations§
Source§impl<T: Clone + Default> TensorData<T>
impl<T: Clone + Default> TensorData<T>
Sourcepub fn new(rows: usize, cols: usize) -> Self
pub fn new(rows: usize, cols: usize) -> Self
Creates a new tensor with the given shape, filled with default values.
Sourcepub fn from_vec(data: Vec<T>, rows: usize, cols: usize) -> Result<Self>
pub fn from_vec(data: Vec<T>, rows: usize, cols: usize) -> Result<Self>
Creates a tensor from existing data and shape.
§Errors
Returns an error if the data length doesn’t match rows * cols.
#[requires(data.len() == rows * cols)] #[ensures(result.is_ok() ==> result.shape() == [rows, cols])] #[ensures(result.is_ok() ==> result.as_slice().len() == rows * cols)] #[invariant(self.data.len() == self.shape[0] * self.shape[1])]
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns the underlying data as a mutable slice.
Sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns a raw pointer to the underlying data.
Useful for FFI integration with ML frameworks.
Trait Implementations§
Source§impl<T: Clone> Clone for TensorData<T>
impl<T: Clone> Clone for TensorData<T>
Source§fn clone(&self) -> TensorData<T>
fn clone(&self) -> TensorData<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for TensorData<T>
impl<T> RefUnwindSafe for TensorData<T>where
T: RefUnwindSafe,
impl<T> Send for TensorData<T>where
T: Send,
impl<T> Sync for TensorData<T>where
T: Sync,
impl<T> Unpin for TensorData<T>where
T: Unpin,
impl<T> UnsafeUnpin for TensorData<T>
impl<T> UnwindSafe for TensorData<T>where
T: UnwindSafe,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreCreates a shared type from an unshared type.