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§
Source§impl<T> HostTensor<T>
impl<T> HostTensor<T>
Sourcepub fn from_vec_col_major(
shape: impl Into<ShapeVec>,
data: Vec<T>,
) -> Result<Self>
pub fn from_vec_col_major( shape: impl Into<ShapeVec>, data: Vec<T>, ) -> Result<Self>
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]);Sourcepub 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]);Sourcepub 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);Sourcepub 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());Sourcepub 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]);Sourcepub 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]);Sourcepub 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());Sourcepub fn into_vec_col_major(self) -> (ShapeVec, Vec<T>)
pub fn into_vec_col_major(self) -> (ShapeVec, 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]);Sourcepub fn into_reshaped(self, shape: impl Into<ShapeVec>) -> Result<Self>
pub fn into_reshaped(self, shape: impl Into<ShapeVec>) -> Result<Self>
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]);Trait Implementations§
Source§impl<T: Clone> Clone for HostTensor<T>
impl<T: Clone> Clone for HostTensor<T>
Source§fn clone(&self) -> HostTensor<T>
fn clone(&self) -> HostTensor<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 moreSource§impl<T: Debug> Debug for HostTensor<T>
impl<T: Debug> Debug for HostTensor<T>
Source§impl<T: PartialEq> PartialEq for HostTensor<T>
impl<T: PartialEq> PartialEq for HostTensor<T>
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
Mutably borrows from an owned value. Read more