pub struct Tensor { /* private fields */ }Expand description
A multi-dimensional tensor with typed storage
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn new(
data: Vec<u8>,
shape: Vec<usize>,
dtype: DType,
) -> Result<Self, TensorError>
pub fn new( data: Vec<u8>, shape: Vec<usize>, dtype: DType, ) -> Result<Self, TensorError>
Create a new tensor from raw data bytes with the given shape and dtype
Sourcepub unsafe fn from_storage(
storage: TensorStorage,
shape: Vec<usize>,
dtype: DType,
offset: usize,
) -> Result<Self, TensorError>
pub unsafe fn from_storage( storage: TensorStorage, shape: Vec<usize>, dtype: DType, offset: usize, ) -> Result<Self, TensorError>
Create a tensor from existing storage
§Safety
The storage must contain valid data for the given shape and dtype. The offset + size must not exceed the storage length.
Sourcepub fn from_f32(data: &[f32], shape: Vec<usize>) -> Result<Self, TensorError>
pub fn from_f32(data: &[f32], shape: Vec<usize>) -> Result<Self, TensorError>
Create a tensor from f32 data
Sourcepub fn set_name(&mut self, name: impl Into<String>)
pub fn set_name(&mut self, name: impl Into<String>)
Set the tensor name (for GPU weight lookup)
Sourcepub fn with_name(self, name: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
Create a named tensor (builder pattern)
Sourcepub fn as_f32(&self) -> Result<&[f32], TensorError>
pub fn as_f32(&self) -> Result<&[f32], TensorError>
Get the data as f32 slice (only valid for F32 dtype)
Sourcepub fn as_f32_mut(&mut self) -> Result<&mut [f32], TensorError>
pub fn as_f32_mut(&mut self) -> Result<&mut [f32], TensorError>
Get mutable access to data as f32 slice (only valid for F32 dtype)
Sourcepub fn is_contiguous(&self) -> bool
pub fn is_contiguous(&self) -> bool
Check if the tensor is contiguous in memory
Sourcepub fn contiguous(&self) -> Result<Self, TensorError>
pub fn contiguous(&self) -> Result<Self, TensorError>
Return a contiguous copy of this tensor if not already contiguous
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Tensor
impl RefUnwindSafe for Tensor
impl Send for Tensor
impl Sync for Tensor
impl Unpin for Tensor
impl UnsafeUnpin for Tensor
impl UnwindSafe for Tensor
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,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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 more