pub struct Tensor { /* private fields */ }Expand description
A multi-dimensional tensor stored as raw bytes.
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn new(data: Vec<u8>, shape: Vec<usize>, dtype: DType) -> Self
pub fn new(data: Vec<u8>, shape: Vec<usize>, dtype: DType) -> Self
Create a new tensor from raw bytes.
Sourcepub fn from_f32(data: &[f32], shape: Vec<usize>) -> Self
pub fn from_f32(data: &[f32], shape: Vec<usize>) -> Self
Create an F32 tensor from a float slice.
pub fn shape(&self) -> &[usize]
pub fn dtype(&self) -> DType
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Size of the underlying data in bytes.
Sourcepub fn as_f32_slice(&self) -> &[f32]
pub fn as_f32_slice(&self) -> &[f32]
View the data as an f32 slice. Panics if dtype is not F32.
Sourcepub fn as_f32_slice_mut(&mut self) -> &mut [f32]
pub fn as_f32_slice_mut(&mut self) -> &mut [f32]
View the data as a mutable f32 slice. Panics if dtype is not F32.
Sourcepub fn to_f32_vec(&self) -> Vec<f32>
pub fn to_f32_vec(&self) -> Vec<f32>
Convert tensor data to a Vec<f32>, dequantizing if necessary.
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> 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