pub struct Tensor { /* private fields */ }Expand description
A dense, C-ordered array of numbers.
Element bytes are stored in native endianness, matching what NumPy and the tenbin format write on the same machine.
Implementations§
Source§impl Tensor
impl Tensor
Sourcepub fn new(
dtype: DType,
shape: Vec<usize>,
data: impl Into<Bytes>,
) -> Result<Tensor>
pub fn new( dtype: DType, shape: Vec<usize>, data: impl Into<Bytes>, ) -> Result<Tensor>
Build a tensor from raw native-endian element bytes.
Fails when data does not hold exactly shape.product() * dtype.size()
bytes.
Sourcepub fn from_f32_shaped(values: &[f32], shape: Vec<usize>) -> Tensor
pub fn from_f32_shaped(values: &[f32], shape: Vec<usize>) -> Tensor
Build an f32 tensor with an explicit shape.
§Panics
Panics if shape does not describe exactly values.len() elements.
Sourcepub fn from_u8_shaped(values: Vec<u8>, shape: Vec<usize>) -> Tensor
pub fn from_u8_shaped(values: Vec<u8>, shape: Vec<usize>) -> Tensor
Build a u8 tensor with an explicit shape.
§Panics
Panics if shape does not describe exactly values.len() elements.
Sourcepub fn reshape(&self, shape: Vec<usize>) -> Result<Tensor>
pub fn reshape(&self, shape: Vec<usize>) -> Result<Tensor>
Change the shape, keeping the element data.
Fails when the new shape describes a different number of elements.
Sourcepub fn to_f64_vec(&self) -> Vec<f64>
pub fn to_f64_vec(&self) -> Vec<f64>
Copy the elements out as f64, whatever the stored type.
Sourcepub fn to_f32_vec(&self) -> Vec<f32>
pub fn to_f32_vec(&self) -> Vec<f32>
Copy the elements out as f32, whatever the stored type.
Trait Implementations§
impl Eq for Tensor
impl StructuralPartialEq for Tensor
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> CustomValue for T
impl<T> CustomValue for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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