pub enum TensorView<'a> {
F32(TypedTensorView<'a, f32>),
F64(TypedTensorView<'a, f64>),
I32(TypedTensorView<'a, i32>),
I64(TypedTensorView<'a, i64>),
Bool(TypedTensorView<'a, bool>),
C32(TypedTensorView<'a, Complex<f32>>),
C64(TypedTensorView<'a, Complex<f64>>),
}Expand description
Dynamic read-only borrowed tensor view.
TensorView keeps dtype erased while borrowing typed view metadata and
storage. Use TypedTensorView directly when the scalar type is statically
known.
§Examples
use tenferro_tensor::{DType, TensorView, TypedTensorView};
let data = [1_i32, 2, 3, 4];
let typed = TypedTensorView::from_slice([2, 2], [1, 2], 0, &data)?;
let view = TensorView::I32(typed);
assert_eq!(view.dtype(), DType::I32);
assert_eq!(view.shape(), &[2, 2]);Variants§
F32(TypedTensorView<'a, f32>)
F64(TypedTensorView<'a, f64>)
I32(TypedTensorView<'a, i32>)
I64(TypedTensorView<'a, i64>)
Bool(TypedTensorView<'a, bool>)
C32(TypedTensorView<'a, Complex<f32>>)
C64(TypedTensorView<'a, Complex<f64>>)
Implementations§
Source§impl<'a> TensorView<'a>
impl<'a> TensorView<'a>
Sourcepub fn f32(shape: &'a [usize], data: &'a [f32]) -> Result<Self>
pub fn f32(shape: &'a [usize], data: &'a [f32]) -> Result<Self>
Create a dynamic f32 view over compact column-major host data.
§Examples
use tenferro_tensor::{DType, TensorView};
let data = [1.0_f32, 2.0];
let view = TensorView::f32(&[2], &data)?;
assert_eq!(view.dtype(), DType::F32);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow for compact
shape or offset arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
compact shape reaches beyond data.
Sourcepub fn f64(shape: &'a [usize], data: &'a [f64]) -> Result<Self>
pub fn f64(shape: &'a [usize], data: &'a [f64]) -> Result<Self>
Create a dynamic f64 view over compact column-major host data.
§Examples
use tenferro_tensor::{DType, TensorView};
let data = [1.0_f64, 2.0];
let view = TensorView::f64(&[2], &data)?;
assert_eq!(view.dtype(), DType::F64);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow for compact
shape or offset arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
compact shape reaches beyond data.
Sourcepub fn i64(shape: &'a [usize], data: &'a [i64]) -> Result<Self>
pub fn i64(shape: &'a [usize], data: &'a [i64]) -> Result<Self>
Create a dynamic i64 view over compact column-major host data.
§Examples
use tenferro_tensor::{DType, TensorView};
let data = [1_i64, 2];
let view = TensorView::i64(&[2], &data)?;
assert_eq!(view.dtype(), DType::I64);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow for compact
shape or offset arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
compact shape reaches beyond data.
Sourcepub fn i32(shape: &'a [usize], data: &'a [i32]) -> Result<Self>
pub fn i32(shape: &'a [usize], data: &'a [i32]) -> Result<Self>
Create a dynamic i32 view over compact column-major host data.
§Examples
use tenferro_tensor::{DType, TensorView};
let data = [1_i32, 2];
let view = TensorView::i32(&[2], &data)?;
assert_eq!(view.dtype(), DType::I32);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow for compact
shape or offset arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
compact shape reaches beyond data.
Sourcepub fn bool(shape: &'a [usize], data: &'a [bool]) -> Result<Self>
pub fn bool(shape: &'a [usize], data: &'a [bool]) -> Result<Self>
Create a dynamic bool view over compact column-major host data.
§Examples
use tenferro_tensor::{DType, TensorView};
let data = [true, false];
let view = TensorView::bool(&[2], &data)?;
assert_eq!(view.dtype(), DType::Bool);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow for compact
shape or offset arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
compact shape reaches beyond data.
Sourcepub fn c32(shape: &'a [usize], data: &'a [Complex32]) -> Result<Self>
pub fn c32(shape: &'a [usize], data: &'a [Complex32]) -> Result<Self>
Create a dynamic Complex32 view over compact column-major host data.
§Examples
use num_complex::Complex32;
use tenferro_tensor::{DType, TensorView};
let data = [Complex32::new(1.0, 2.0)];
let view = TensorView::c32(&[1], &data)?;
assert_eq!(view.dtype(), DType::C32);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow for compact
shape or offset arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
compact shape reaches beyond data.
Sourcepub fn c64(shape: &'a [usize], data: &'a [Complex64]) -> Result<Self>
pub fn c64(shape: &'a [usize], data: &'a [Complex64]) -> Result<Self>
Create a dynamic Complex64 view over compact column-major host data.
§Examples
use num_complex::Complex64;
use tenferro_tensor::{DType, TensorView};
let data = [Complex64::new(1.0, 2.0)];
let view = TensorView::c64(&[1], &data)?;
assert_eq!(view.dtype(), DType::C64);§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow for compact
shape or offset arithmetic overflow, or
tenferro_tensor_core::ValidationError::ViewOutOfBounds when the
compact shape reaches beyond data.
pub fn dtype(&self) -> DType
pub fn shape(&self) -> &[usize]
Sourcepub fn placement(&self) -> &Placement
pub fn placement(&self) -> &Placement
Return the placement metadata carried by this borrowed view.
§Examples
use tenferro_tensor::{MemoryKind, TensorView};
let view = TensorView::f64(&[1], &[1.0])?;
assert_eq!(view.placement().memory_kind, MemoryKind::UnpinnedHost);Sourcepub fn backend_family(&self) -> Option<&'static str>
pub fn backend_family(&self) -> Option<&'static str>
Return the physical backend family, when this view is backend-owned.
§Examples
use tenferro_tensor::TensorView;
let view = TensorView::f64(&[1], &[1.0])?;
assert_eq!(view.backend_family(), None);Sourcepub fn allocation_domain(&self) -> Option<AllocationDomainId>
pub fn allocation_domain(&self) -> Option<AllocationDomainId>
Return the shared allocation domain, when this view has one.
§Examples
use tenferro_tensor::TensorView;
let view = TensorView::f64(&[1], &[1.0])?;
assert_eq!(view.allocation_domain(), None);Sourcepub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize>
pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize>
Compute the physical element offset for a logical index.
§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::RankMismatch when indices
has the wrong rank, tenferro_tensor_core::ValidationError::InvalidArgument
when an index is outside its axis extent, or
tenferro_tensor_core::ValidationError::IntegerOverflow when offset
arithmetic overflows.
Sourcepub fn is_col_major_contiguous(&self) -> Result<bool>
pub fn is_col_major_contiguous(&self) -> Result<bool>
Return whether this view is compact column-major.
§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow when
compactness arithmetic overflows.
Sourcepub fn layout_summary(&self) -> String
pub fn layout_summary(&self) -> String
Return a compact string summary of this view’s layout metadata.
Sourcepub fn assert_col_major_contiguous(&self) -> Result<()>
pub fn assert_col_major_contiguous(&self) -> Result<()>
Assert this view is compact column-major.
§Errors
Returns crate::Error::Validation with
tenferro_tensor_core::ValidationError::IntegerOverflow when
compactness arithmetic overflows, or
tenferro_tensor_core::ValidationError::InvalidArgument when the
view is not compact column-major.
Trait Implementations§
Source§impl<'a> Clone for TensorView<'a>
impl<'a> Clone for TensorView<'a>
Source§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