Enum TensorView
pub enum TensorView<'a> {
F32(HostTensorView<'a, f32>),
F64(HostTensorView<'a, f64>),
I32(HostTensorView<'a, i32>),
I64(HostTensorView<'a, i64>),
Bool(HostTensorView<'a, bool>),
C32(HostTensorView<'a, Complex<f32>>),
C64(HostTensorView<'a, Complex<f64>>),
}Expand description
Variants§
F32(HostTensorView<'a, f32>)
F64(HostTensorView<'a, f64>)
I32(HostTensorView<'a, i32>)
I64(HostTensorView<'a, i64>)
Bool(HostTensorView<'a, bool>)
C32(HostTensorView<'a, Complex<f32>>)
C64(HostTensorView<'a, Complex<f64>>)
Implementations§
§impl<'a> TensorView<'a>
impl<'a> TensorView<'a>
pub fn dtype(&self) -> DType
pub fn dtype(&self) -> DType
Return this view’s dtype.
§Examples
use tenferro_tensor_core::{DType, Tensor};
let tensor = Tensor::from_vec_col_major(vec![1], vec![1.0_f32])?;
assert_eq!(tensor.as_view().dtype(), DType::F32);pub fn shape(&self) -> &[usize]
pub fn shape(&self) -> &[usize]
Borrow this view’s shape.
§Examples
use tenferro_tensor_core::Tensor;
let tensor = Tensor::from_vec_col_major(vec![1], vec![1.0_f64])?;
assert_eq!(tensor.as_view().shape(), &[1]);pub fn rank(&self) -> usize
pub fn rank(&self) -> usize
Return the view rank.
§Examples
use tenferro_tensor_core::Tensor;
let tensor = Tensor::from_vec_col_major(vec![1, 1], vec![1_i64])?;
assert_eq!(tensor.as_view().rank(), 2);pub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Return whether this view has zero logical elements.
§Examples
use tenferro_tensor_core::Tensor;
let tensor = Tensor::from_vec_col_major(vec![0], Vec::<f64>::new())?;
assert!(tensor.as_view().is_empty());pub fn reshape_view(
&self,
shape: impl Into<SmallVec<[usize; 8]>>,
) -> Result<TensorView<'a>, ValidationError>
pub fn reshape_view( &self, shape: impl Into<SmallVec<[usize; 8]>>, ) -> Result<TensorView<'a>, ValidationError>
Return a metadata-only reshape of this dynamic view.
§Examples
use tenferro_tensor_core::Tensor;
let tensor = Tensor::from_vec_col_major(vec![4], vec![1_i32, 2, 3, 4])?;
assert_eq!(tensor.as_view().reshape_view(vec![2, 2])?.shape(), &[2, 2]);§Errors
Returns the underlying view’s validation errors, including
ValidationError::ShapeMismatch,
ValidationError::NonContiguousViewAsSlice, or
ValidationError::IntegerOverflow.
pub fn transpose_view(
&self,
axes: &[usize],
) -> Result<TensorView<'a>, ValidationError>
pub fn transpose_view( &self, axes: &[usize], ) -> Result<TensorView<'a>, ValidationError>
Return a metadata-only transposed dynamic view with axes in the requested order.
§Examples
use tenferro_tensor_core::Tensor;
let tensor = Tensor::from_vec_col_major(vec![1, 2], vec![1_i64, 2])?;
assert_eq!(tensor.as_view().transpose_view(&[1, 0])?.shape(), &[2, 1]);§Errors
Returns ValidationError::InvalidPermutationLength,
ValidationError::AxisOutOfBounds, or
ValidationError::DuplicateAxis when axes is not a permutation of
the view rank.
pub fn slice_view(
&self,
spec: &[SliceSpec],
) -> Result<TensorView<'a>, ValidationError>
pub fn slice_view( &self, spec: &[SliceSpec], ) -> Result<TensorView<'a>, ValidationError>
Return a metadata-only positive-step slice of this dynamic view.
§Examples
use tenferro_tensor_core::{SliceSpec, Tensor};
let tensor = Tensor::from_vec_col_major(vec![3], vec![1_i64, 2, 3])?;
assert_eq!(
tensor.as_view().slice_view(&[SliceSpec { start: 1, end: 3, step: 1 }])?.shape(),
&[2],
);§Errors
Returns ValidationError::RankMismatch,
ValidationError::InvalidSliceStep, or
ValidationError::InvalidSliceBounds for invalid slice parameters.
Trait Implementations§
§impl<'a> Clone for TensorView<'a>
impl<'a> Clone for TensorView<'a>
§fn clone(&self) -> TensorView<'a>
fn clone(&self) -> TensorView<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for TensorView<'a>
impl<'a> RefUnwindSafe for TensorView<'a>
impl<'a> Send for TensorView<'a>
impl<'a> Sync for TensorView<'a>
impl<'a> Unpin for TensorView<'a>
impl<'a> UnsafeUnpin for TensorView<'a>
impl<'a> UnwindSafe for TensorView<'a>
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