Struct HostTensor
pub struct HostTensor<T> { /* private fields */ }Expand description
Owned contiguous host tensor in column-major order.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert_eq!(tensor.as_slice(), &[1.0, 2.0]);Implementations§
§impl<T> HostTensor<T>
impl<T> HostTensor<T>
pub fn from_vec_col_major(
shape: impl Into<SmallVec<[usize; 8]>>,
data: Vec<T>,
) -> Result<HostTensor<T>, ValidationError>
pub fn from_vec_col_major( shape: impl Into<SmallVec<[usize; 8]>>, data: Vec<T>, ) -> Result<HostTensor<T>, ValidationError>
Create an owned tensor from a column-major host buffer.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::from_vec_col_major(vec![2], vec![1_i64, 2])?;
assert_eq!(tensor.shape(), &[2]);§Errors
Returns ValidationError::ShapeDataLengthMismatch when the shape
product differs from data.len(), or ValidationError::IntegerOverflow
when validating the shape overflows.
pub fn shape(&self) -> &[usize]
pub fn shape(&self) -> &[usize]
Borrow this tensor’s shape.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::from_vec_col_major(vec![2], vec![true, false])?;
assert_eq!(tensor.shape(), &[2]);pub fn rank(&self) -> usize
pub fn rank(&self) -> usize
Return the tensor rank.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::from_vec_col_major(vec![2, 1], vec![1.0_f32, 2.0])?;
assert_eq!(tensor.rank(), 2);pub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true when this tensor has zero elements.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::<f64>::from_vec_col_major(vec![0], vec![])?;
assert!(tensor.is_empty());pub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Borrow the contiguous column-major host buffer.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::from_vec_col_major(vec![1], vec![7_i32])?;
assert_eq!(tensor.as_slice(), &[7]);pub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Mutably borrow the contiguous column-major host buffer.
§Examples
use tenferro_tensor_core::HostTensor;
let mut tensor = HostTensor::from_vec_col_major(vec![1], vec![7_i32])?;
tensor.as_mut_slice()[0] = 8;
assert_eq!(tensor.as_slice(), &[8]);pub fn as_view(&self) -> HostTensorView<'_, T>
pub fn as_view(&self) -> HostTensorView<'_, T>
Borrow this tensor as a compact zero-offset view.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?;
assert!(tensor.as_view().is_zero_offset_col_major()?);pub fn into_vec_col_major(self) -> (SmallVec<[usize; 8]>, Vec<T>)
pub fn into_vec_col_major(self) -> (SmallVec<[usize; 8]>, Vec<T>)
Consume this tensor into its shape and column-major buffer.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::from_vec_col_major(vec![1], vec![3.0_f64])?;
assert_eq!(tensor.into_vec_col_major().1, vec![3.0]);pub fn into_reshaped(
self,
shape: impl Into<SmallVec<[usize; 8]>>,
) -> Result<HostTensor<T>, ValidationError>
pub fn into_reshaped( self, shape: impl Into<SmallVec<[usize; 8]>>, ) -> Result<HostTensor<T>, ValidationError>
Consume this tensor into the same data with a different shape.
§Examples
use tenferro_tensor_core::HostTensor;
let tensor = HostTensor::from_vec_col_major(vec![4], vec![1.0_f64, 2.0, 3.0, 4.0])?;
assert_eq!(tensor.into_reshaped(vec![2, 2])?.shape(), &[2, 2]);§Errors
Returns ValidationError::ShapeMismatch when the requested shape has
a different element count, or ValidationError::IntegerOverflow when
validating that count overflows.
Trait Implementations§
§impl<T> Clone for HostTensor<T>where
T: Clone,
impl<T> Clone for HostTensor<T>where
T: Clone,
§fn clone(&self) -> HostTensor<T>
fn clone(&self) -> HostTensor<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<T> Debug for HostTensor<T>where
T: Debug,
impl<T> Debug for HostTensor<T>where
T: Debug,
§impl<T> PartialEq for HostTensor<T>where
T: PartialEq,
impl<T> PartialEq for HostTensor<T>where
T: PartialEq,
impl<T> StructuralPartialEq for HostTensor<T>
Auto Trait Implementations§
impl<T> Freeze for HostTensor<T>
impl<T> RefUnwindSafe for HostTensor<T>where
T: RefUnwindSafe,
impl<T> Send for HostTensor<T>where
T: Send,
impl<T> Sync for HostTensor<T>where
T: Sync,
impl<T> Unpin for HostTensor<T>where
T: Unpin,
impl<T> UnsafeUnpin for HostTensor<T>
impl<T> UnwindSafe for HostTensor<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
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>
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>
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