Skip to main content

TypedTensorView

Struct TypedTensorView 

Source
pub struct TypedTensorView<'a, T, R = DynRank, D = Dynamic>{ /* private fields */ }
Expand description

Read-only borrowed view of typed tensor storage with arbitrary strides.

TypedTensorView is the typed representation for layout-only tensor transformations. It borrows an existing host or backend allocation and carries a logical shape, strides, and an offset. Slicing, reshaping when stride-compatible, and transpose_view update only metadata and do not copy storage.

Materialize through TensorStructural::to_contiguous_read on the active backend session when a compact owned TypedTensor is required. Use TypedTensorView::as_slice only when the current view is contiguous in the requested layout.

§Examples

use tenferro_tensor::{Rank, TypedTensorView};

let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked([2, 2], [1, 2], 0, &data)?;
assert_eq!(view.get(&[1, 1]), Some(&4));

Borrowed typed view of one tensor representation.

The buffer stays concrete on purpose: a generic-associated buffer would make the projection invariant in 'a, and the borrowed-read surface relies on TensorRead<'long> shortening to TensorRead<'short>. D therefore marks which representation produced the view - Host is only ever built from host slices, with no retained region.

Implementations§

Source§

impl<'a, T, const N: usize, D> TypedTensorView<'a, T, Rank<N>, D>
where T: 'static, D: Representation,

Source

pub fn host_col_major_view(&self) -> Result<ColMajorView<'a, T, N>, Error>

Validate and borrow this tensor view as a compact column-major host view.

Nonzero compact offsets are represented by the returned logical slice without copying.

§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let data = [0_i32, 1, 2, 3, 4];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked([2, 2], [1, 2], 1, &data)?;
assert_eq!(view.host_col_major_view()?.as_slice(), &[1, 2, 3, 4]);
§Errors

Returns crate::Error::RuntimeState when storage is backend-owned, or crate::Error::Validation when compact layout, shape arithmetic, or the logical host range is invalid.

Source§

impl<'a, T> TypedTensorView<'a, T>
where T: 'static,

Source

pub fn from_col_major( shape: &[usize], data: &'a [T], ) -> Result<TypedTensorView<'a, T>, Error>

Create a borrowed dynamic-rank view over compact column-major host data.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::from_col_major(&[2, 2], &data)?;
assert_eq!(view.strides(), &[1, 2]);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow when compact strides or reachable bounds overflow, or tenferro_tensor_core::ValidationError::ViewOutOfBounds when the requested shape reaches beyond data.

Source

pub fn from_slice( shape: impl AsRef<[usize]>, strides: impl AsRef<[isize]>, offset: isize, data: &'a [T], ) -> Result<TypedTensorView<'a, T>, Error>

Create a borrowed host view from explicit layout metadata.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice(vec![3], vec![-1], 2, &data)?;
assert_eq!(view.get(&[2]), Some(&1));
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::RankMismatch when shape and strides have different ranks, tenferro_tensor_core::ValidationError::ViewOutOfBounds when the reachable layout exceeds data, or tenferro_tensor_core::ValidationError::IntegerOverflow when layout arithmetic overflows.

Source§

impl<'a, T, R, D> TypedTensorView<'a, T, R, D>
where T: 'static, R: TensorRank, D: Representation,

Source

pub fn from_slice_ranked( shape: impl Into<<R as TensorRank>::Shape>, strides: impl Into<<R as TensorRank>::Strides>, offset: isize, data: &'a [T], ) -> Result<TypedTensorView<'a, T, R, D>, Error>

Create a rank-generic borrowed host view from explicit layout metadata.

§Examples
use tenferro_tensor::{Rank, TypedTensorView};

let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked([2, 2], [1, 2], 0, &data)?;
assert_eq!(view.get(&[1, 1]), Some(&4));
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::RankMismatch when the typed rank does not match shape or strides, tenferro_tensor_core::ValidationError::ViewOutOfBounds when the reachable layout exceeds data, or tenferro_tensor_core::ValidationError::IntegerOverflow when layout arithmetic overflows.

Source§

impl<'a, T, R> TypedTensorView<'a, T, R>
where T: 'static, R: TensorRank,

Source

pub fn is_host_memory(&self) -> bool

Whether this view borrows host-addressed memory.

The same answer Self::try_host acts on and TypedTensor::is_host_memory gives for the owner: the borrowed payload decides, never Placement::memory_kind.

§Examples
use tenferro_tensor::TypedTensor;

let tensor = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0])?;
assert!(tensor.as_view().is_host_memory());
Source

pub fn try_host( self, op: &'static str, ) -> Result<TypedTensorView<'a, T, R, Host>, Error>

Checked narrowing of a borrowed view to the host representation.

This is the one place a borrowed dynamic view becomes Host-marked: it succeeds exactly when the view borrows host elements (a plain host owner, a host slice, or a CPU-resident allocation group) and keeps the layout and the placement label. It runs Self::is_host_memory, so a CPU entry point that narrows here and a CPU entry point that validates without narrowing reach the same verdict. A consumer that receives the result reads it through TypedTensorView::as_host_slice without a further check.

§Examples
use tenferro_tensor::TypedTensor;

let tensor = TypedTensor::<f64>::from_vec_col_major(vec![2], vec![1.0, 2.0])?;
let host = tensor.as_view().try_host("example")?;
assert_eq!(host.as_host_slice(), &[1.0, 2.0]);
§Errors

Returns crate::Error::RuntimeState attributed to op when the view borrows backend (device) storage; download the tensor to host first.

Source§

impl<'a, T, R> TypedTensorView<'a, T, R, Host>
where T: 'static, R: TensorRank,

Source

pub fn into_dynamic(self) -> TypedTensorView<'a, T, R>

Widen a host-marked view to the runtime union without copying.

§Examples
use tenferro_tensor::{DynRank, Host, TypedTensorView};

let data = [1_i32, 2];
let host: TypedTensorView<'_, i32, DynRank, Host> =
    TypedTensorView::from_host_slice(vec![2].as_slice(), vec![1].as_slice(), 0, &data)?;
let dynamic = host.into_dynamic();
assert_eq!(dynamic.host_storage()?, &[1, 2]);
Source§

impl<'a, T, R> TypedTensorView<'a, T, R, Host>
where T: 'static, R: TensorRank,

Source

pub fn from_host_slice( shape: impl Into<<R as TensorRank>::Shape>, strides: impl Into<<R as TensorRank>::Strides>, offset: isize, data: &'a [T], ) -> Result<TypedTensorView<'a, T, R, Host>, Error>

Create a representation-marked view over an explicit host layout.

A Host-marked view is only ever built from a host slice, so it carries no retained region and its host slice needs no runtime check.

§Examples
use tenferro_tensor::{DynRank, Host, TypedTensorView};

let data = [1_i32, 2, 3, 4];
let view: TypedTensorView<'_, i32, DynRank, Host> =
    TypedTensorView::from_host_slice(vec![2, 2].as_slice(), vec![1, 2].as_slice(), 0, &data)?;
assert_eq!(view.as_host_slice(), &[1, 2, 3, 4]);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::RankMismatch when strides has a different rank, or tenferro_tensor_core::ValidationError::ViewOutOfBounds / tenferro_tensor_core::ValidationError::IntegerOverflow when the reachable layout leaves data or overflows.

Source

pub fn as_host_slice(&self) -> &'a [T]

Borrow the host elements without a runtime representation check.

§Examples
use tenferro_tensor::{DynRank, Host, TypedTensorView};

let data = [1_i32, 2];
let view: TypedTensorView<'_, i32, DynRank, Host> =
    TypedTensorView::from_host_slice(vec![2].as_slice(), vec![1].as_slice(), 0, &data)?;
assert_eq!(view.as_host_slice(), &[1, 2]);
§Panics

Panics only if a Host-marked view was built from non-host storage, which no constructor in this crate does.

Source§

impl<'a, T, R, D> TypedTensorView<'a, T, R, D>
where T: 'static, R: TensorRank, D: Representation,

Source

pub fn into_tensor_read(self) -> Result<TensorRead<'a>, Error>
where T: TensorScalar,

Erase a borrowed view’s rank and dtype for session dispatch without allocating tensor storage or promoting it into an allocation group. Common ranks use the existing inline shape and stride metadata.

§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let data = [1.0_f64, 2.0];
let view = TypedTensorView::<_, Rank<1>>::from_slice_ranked([2], [1], 0, &data)?;
let read = view.into_tensor_read()?;
assert_eq!(read.as_slice::<f64>()?, &[1.0, 2.0]);
§Errors

Returns crate::Error::Validation with ValidationError::IntegerOverflow for unrepresentable metadata or ValidationError::ViewOutOfBounds if the layout leaves its allocation.

Source

pub fn shape(&self) -> &[usize]

Return the logical shape.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [0_i32; 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
assert_eq!(view.shape(), &[2]);
Source

pub fn rank(&self) -> usize

Return the logical rank carried by this view.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [0_i32; 6];
let view = TypedTensorView::from_slice(vec![2, 3], vec![1, 2], 0, &data)?;
assert_eq!(view.rank(), 2);
Source

pub fn strides(&self) -> &[isize]

Return strides in element units.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [0_i32; 2];
let view = TypedTensorView::from_slice(vec![2], vec![-1], 1, &data)?;
assert_eq!(view.strides(), &[-1]);
Source

pub fn offset(&self) -> isize

Return the physical element offset.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![1], vec![1], 1, &data)?;
assert_eq!(view.offset(), 1);
Source

pub fn host_storage(&self) -> Result<&'a [T], Error>

Return the borrowed host storage backing this view.

This exposes the entire backing host allocation, not just the logical slice covered by this view. Use TypedTensorView::as_slice when the caller needs the contiguous logical region instead.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
assert_eq!(view.host_storage()?, &[1, 2]);
§Errors

Returns crate::Error::RuntimeState when this view wraps a backend buffer; backend storage must be downloaded before host inspection.

Source

pub fn n_elements(&self) -> usize

Return the number of logical elements in this view.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [0_i32; 6];
let view = TypedTensorView::from_slice(vec![2, 3], vec![1, 2], 0, &data)?;
assert_eq!(view.n_elements(), 6);
Source

pub fn layout(&self) -> &TensorLayout<R>

Return layout metadata for this view.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
assert!(view.layout().is_compact_col_major().unwrap());
Source

pub fn placement(&self) -> &Placement

Return placement metadata for this view.

§Examples
use tenferro_tensor::{MemoryKind, TypedTensorView};

let data = [1_i32];
let view = TypedTensorView::from_slice(vec![1], vec![1], 0, &data)?;
assert_eq!(view.placement().memory_kind, MemoryKind::UnpinnedHost);
Source

pub fn linear_offset(&self, indices: &[usize]) -> Option<usize>

Compute the physical element offset for a logical index.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice(vec![3], vec![-1], 2, &data)?;
assert_eq!(view.linear_offset(&[2]), Some(0));
Source

pub fn layout_linear_offset(&self, indices: &[usize]) -> Result<usize, Error>

Compute the physical element offset for a logical index, returning a typed error.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice([3], [-1], 2, &data)?;
assert_eq!(view.layout_linear_offset(&[2])?, 0);
§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.

Source

pub fn is_col_major_contiguous(&self) -> Result<bool, Error>

Return whether this view is compact column-major.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2];
let view = TypedTensorView::from_slice([2], [1], 0, &data)?;
assert!(view.is_col_major_contiguous()?);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::IntegerOverflow if compactness arithmetic overflows.

Source

pub fn layout_summary(&self) -> String

Return a compact string summary of this view’s layout metadata.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2];
let view = TypedTensorView::from_slice([2], [1], 0, &data)?;
assert!(view.layout_summary().contains("shape=[2]"));
Source

pub fn assert_col_major_contiguous(&self) -> Result<(), Error>

Assert this view is compact column-major.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2];
let view = TypedTensorView::from_slice([2], [1], 0, &data)?;
view.assert_col_major_contiguous()?;
§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.

Source

pub fn get(&self, indices: &[usize]) -> Option<&T>

Borrow one host element by logical index.

Returns None for out-of-bounds indices and backend buffers.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
assert_eq!(view.get(&[1]), Some(&2));
Source

pub fn as_slice(&self) -> Result<&'a [T], Error>

Borrow the contiguous host slice covered by this view.

Returns an explicit error for backend buffers and for non-contiguous layouts. This method never downloads or materializes backend data.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice(vec![2], vec![1], 1, &data)?;
assert_eq!(view.as_slice()?, &[2, 3]);
§Errors

Returns crate::Error::RuntimeState when this view wraps a backend buffer, tenferro_tensor_core::ValidationError::NonContiguousViewAsSlice when the layout is not compact column-major, tenferro_tensor_core::ValidationError::InvalidArgument when the view offset is negative, or crate::Error::Validation with tenferro_tensor_core::ValidationError::ViewOutOfBounds or tenferro_tensor_core::ValidationError::IntegerOverflow when the requested host range is invalid.

Source

pub fn duplicate(&self) -> Result<TypedTensor<T, R>, Error>
where T: Clone,

Explicitly duplicate a compact host view into a new owner.

Backend views require an explicit provider canonicalization or download boundary; this method never transfers or materializes them implicitly.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2];
let view = TypedTensorView::from_slice(vec![2], vec![1], 0, &data)?;
let copy = view.duplicate()?;
assert_eq!(copy.as_slice()?, &[1, 2]);
§Errors

Returns crate::Error::HostAccess or ValidationError::NonContiguousViewAsSlice when the view is backend owned or not contiguous, and ValidationError::InvalidArgument when the static-rank shape cannot be reconstructed.

Source

pub fn to_col_major(&self) -> Result<TypedTensor<T, R>, Error>
where T: Clone,

Explicitly copy a host view, including strided/offset views, to a compact owner.

§Examples
use tenferro_tensor::{Rank, TypedTensorView};
let storage = [1, 4, 2, 5, 3, 6];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked(
    [2, 3], [1, 2], 0, &storage,
)?;
let transposed = view.transpose_view([1, 0])?;
assert_eq!(transposed.to_col_major()?.as_slice()?, &[1, 2, 3, 4, 5, 6]);
§Errors

Backend-only storage returns crate::Error::RuntimeState; invalid layout or rank conversion returns crate::Error::Validation.

Source

pub fn transpose_view( &self, axes: impl AsRef<[usize]>, ) -> Result<TypedTensorView<'a, T, R, D>, Error>

Return a metadata-only axis permutation.

§Examples
use tenferro_tensor::{Rank, TypedTensorView};

let data = [1_i32, 2, 3, 4, 5, 6];
let view = TypedTensorView::<_, Rank<2>>::from_slice_ranked([2, 3], [1, 2], 0, &data)?;
let transposed = view.transpose_view([1, 0])?;
assert_eq!(transposed.shape(), &[3, 2]);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::InvalidPermutationLength, tenferro_tensor_core::ValidationError::AxisOutOfBounds, or tenferro_tensor_core::ValidationError::DuplicateAxis when axes is not a valid permutation of the view rank.

Source

pub fn slice_view( &self, slices: &[StridedSliceSpec], ) -> Result<TypedTensorView<'a, T, R, D>, Error>

Return a metadata-only slice using one StridedSliceSpec per axis.

§Examples
use tenferro_tensor::{StridedSliceSpec, TypedTensorView};

let data = [1_i32, 2, 3];
let view = TypedTensorView::from_slice(vec![3], vec![1], 0, &data)?;
let reversed = view.slice_view(&[StridedSliceSpec::reverse()])?;
assert_eq!(reversed.get(&[0]), Some(&3));
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::RankMismatch when the slice count differs from the view rank, tenferro_tensor_core::ValidationError::InvalidSliceStep or tenferro_tensor_core::ValidationError::InvalidSliceBounds for an invalid slice, tenferro_tensor_core::ValidationError::IntegerOverflow for slice arithmetic overflow, or tenferro_tensor_core::ValidationError::ViewOutOfBounds when the resulting layout exceeds the backing buffer.

Source

pub fn slice_axis_view( &self, axis: usize, slice: StridedSliceSpec, ) -> Result<TypedTensorView<'a, T, R, D>, Error>

Return a metadata-only slice along one axis.

§Examples
use tenferro_tensor::{StridedSliceSpec, TypedTensorView};

let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::from_slice(vec![2, 2], vec![1, 2], 0, &data)?;
assert_eq!(view.slice_axis_view(1, StridedSliceSpec::reverse())?.get(&[0, 0]), Some(&3));
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::AxisOutOfBounds when axis is outside the view rank, tenferro_tensor_core::ValidationError::InvalidSliceStep or tenferro_tensor_core::ValidationError::InvalidSliceBounds for an invalid slice, tenferro_tensor_core::ValidationError::IntegerOverflow for slice arithmetic overflow, or tenferro_tensor_core::ValidationError::ViewOutOfBounds when the resulting layout exceeds the backing buffer.

Source

pub fn reshape_view( &self, shape: &[usize], ) -> Result<TypedTensorView<'a, T, DynRank, D>, Error>

Return a metadata-only dynamic-rank reshape for contiguous column-major views.

§Examples
use tenferro_tensor::TypedTensorView;

let data = [1_i32, 2, 3, 4];
let view = TypedTensorView::from_slice(vec![2, 2], vec![1, 2], 0, &data)?;
assert_eq!(view.reshape_view(&[4])?.shape(), &[4]);
§Errors

Returns crate::Error::Validation with tenferro_tensor_core::ValidationError::NonContiguousViewAsSlice when the source is not compact column-major, tenferro_tensor_core::ValidationError::ShapeMismatch (whose tenferro_tensor_core::ShapeMismatch::ReshapeElementCount source records the counts) when element counts differ, tenferro_tensor_core::ValidationError::IntegerOverflow for shape arithmetic overflow, or tenferro_tensor_core::ValidationError::ViewOutOfBounds when the reshaped view exceeds the backing buffer.

Source§

impl<'a, R> TypedTensorView<'a, Complex<f32>, R>
where R: TensorRank,

Source

pub fn as_real_view(&self) -> Result<TypedTensorView<'a, f32>, Error>

Borrow this complex view as an interleaved real view without copying.

The result has dynamic rank because reinterpretation prepends the component axis [2, ...]. Only Complex32 <-> f32 is sealed in this API; this is representation reinterpretation, not numeric conversion.

§Examples
use tenferro_tensor::{Complex32, TypedTensorView};

let data = [Complex32::new(1.0, 2.0)];
let view = TypedTensorView::from_col_major(&[1], &data)?;
let real = view.as_real_view()?;
assert_eq!(real.shape(), &[2, 1]);
assert_eq!(real.as_slice()?, &[1.0_f32, 2.0]);
§Errors

Returns an error when the view layout is not a valid sealed representation or when backend reinterpretation is unsupported.

Source§

impl<'a, R> TypedTensorView<'a, Complex<f64>, R>
where R: TensorRank,

Source

pub fn as_real_view(&self) -> Result<TypedTensorView<'a, f64>, Error>

Borrow this complex view as an interleaved real view without copying.

The result has dynamic rank because reinterpretation prepends the component axis [2, ...]. Only Complex64 <-> f64 is sealed in this API; this is representation reinterpretation, not numeric conversion.

§Examples
use tenferro_tensor::{Complex64, TypedTensorView};

let data = [Complex64::new(1.0, 2.0)];
let view = TypedTensorView::from_col_major(&[1], &data)?;
let real = view.as_real_view()?;
assert_eq!(real.shape(), &[2, 1]);
assert_eq!(real.as_slice()?, &[1.0_f64, 2.0]);
§Errors

Returns an error when the view layout is not a valid sealed representation or when backend reinterpretation is unsupported.

Source§

impl<'a, R> TypedTensorView<'a, f32, R>
where R: TensorRank,

Source

pub fn as_complex_view( &self, ) -> Result<TypedTensorView<'a, Complex<f32>>, Error>

Borrow this interleaved real view as a complex view without copying.

The source must have a leading extent and stride of 2 and 1, and every remaining stride plus the offset must be divisible by 2.

§Examples
use tenferro_tensor::{Complex32, TypedTensorView};

let data = [1.0_f32, 2.0];
let view = TypedTensorView::from_col_major(&[2, 1], &data)?;
let complex = view.as_complex_view()?;
assert_eq!(complex.shape(), &[1]);
assert_eq!(complex.as_slice()?, &[Complex32::new(1.0, 2.0)]);
§Errors

Returns an error when the view layout is not a valid sealed representation or when backend reinterpretation is unsupported.

Source§

impl<'a, R> TypedTensorView<'a, f64, R>
where R: TensorRank,

Source

pub fn as_complex_view( &self, ) -> Result<TypedTensorView<'a, Complex<f64>>, Error>

Borrow this interleaved real view as a complex view without copying.

The source must have a leading extent and stride of 2 and 1, and every remaining stride plus the offset must be divisible by 2.

§Examples
use tenferro_tensor::{Complex64, TypedTensorView};

let data = [1.0_f64, 2.0];
let view = TypedTensorView::from_col_major(&[2, 1], &data)?;
let complex = view.as_complex_view()?;
assert_eq!(complex.shape(), &[1]);
assert_eq!(complex.as_slice()?, &[Complex64::new(1.0, 2.0)]);
§Errors

Returns an error when the view layout is not a valid sealed representation or when backend reinterpretation is unsupported.

Trait Implementations§

Source§

impl<T> AsView for TypedTensorView<'_, T>
where T: TensorScalar,

Source§

type Repr = Typed<T>

The representation results take for this input.
Source§

fn as_read(&self) -> TensorRead<'_>

Borrow this input as a TensorRead. Metadata only; never copies element data. Read more
Source§

impl<'a, T, R, D> Clone for TypedTensorView<'a, T, R, D>

Source§

fn clone(&self) -> TypedTensorView<'a, T, R, D>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T, R, D> Debug for TypedTensorView<'a, T, R, D>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T, R = DynRank, D = Dynamic> !RefUnwindSafe for TypedTensorView<'a, T, R, D>

§

impl<'a, T, R = DynRank, D = Dynamic> !UnwindSafe for TypedTensorView<'a, T, R, D>

§

impl<'a, T, R, D> Freeze for TypedTensorView<'a, T, R, D>
where <R as TensorRank>::Shape: Freeze, <R as TensorRank>::Strides: Freeze,

§

impl<'a, T, R, D> Send for TypedTensorView<'a, T, R, D>
where <R as TensorRank>::Shape: Send, <R as TensorRank>::Strides: Send, D: Send, T: Send + Sync,

§

impl<'a, T, R, D> Sync for TypedTensorView<'a, T, R, D>
where <R as TensorRank>::Shape: Sync, <R as TensorRank>::Strides: Sync, D: Sync, T: Sync,

§

impl<'a, T, R, D> Unpin for TypedTensorView<'a, T, R, D>
where <R as TensorRank>::Shape: Unpin, <R as TensorRank>::Strides: Unpin, D: Unpin, T: Unpin, R: Unpin,

§

impl<'a, T, R, D> UnsafeUnpin for TypedTensorView<'a, T, R, D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<X> CoreOps for X
where X: AsView + ?Sized,

Source§

fn exp( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise exponential. Read more
Source§

fn neg( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise negation. Read more
Source§

fn sign( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise sign. Read more
Source§

fn conj( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise complex conjugate (identity on real dtypes). Read more
Source§

fn log( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise natural logarithm. Read more
Source§

fn expm1( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise exp(x) - 1. Read more
Source§

fn log1p( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise log(1 + x). Read more
Source§

fn erf( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise error function. Read more
Source§

fn sin( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise sine. Read more
Source§

fn cos( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise cosine. Read more
Source§

fn tanh( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise hyperbolic tangent. Read more
Source§

fn sqrt( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise square root. Read more
Source§

fn rsqrt( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise reciprocal square root. Read more
Source§

fn abs( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as CoreRepr>::Real, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise absolute value; complex inputs return their modulus. Read more
Source§

fn sigmoid( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Logistic sigmoid. Read more
Source§

fn silu( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

SiLU (x * sigmoid(x)). Read more
Source§

fn softplus( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Softplus log(1 + exp(x)). Read more
Source§

fn gelu( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

GELU with the exact error function. Read more
Source§

fn gelu_tanh( &self, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

GELU with the tanh approximation. Read more
Source§

fn mul( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise product with broadcasting. Read more
Source§

fn sub( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise difference with broadcasting. Read more
Source§

fn div( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise quotient with broadcasting. Read more
Source§

fn rem( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise remainder with broadcasting. Read more
Source§

fn pow( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise power with broadcasting. Read more
Source§

fn maximum( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise maximum with broadcasting. Read more
Source§

fn minimum( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise minimum with broadcasting. Read more
Source§

fn add( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise sum with broadcasting. Read more
Source§

fn add_into( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, dest: Dest<<<X as AsView>::Repr as Repr>::Write<'_>>, ) -> Result<(), Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise sum with broadcasting. Read more
Source§

fn matmul( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Matrix product of the two leading axes, batched over trailing axes. Read more
Source§

fn compare( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, dir: CompareDir, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as CoreRepr>::Bool, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise comparison with broadcasting; returns a bool tensor. Read more
Source§

fn clamp( &self, lower: &impl AsView<Repr = <X as AsView>::Repr>, upper: &impl AsView<Repr = <X as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Elementwise clamp to [lower, upper] with broadcasting. Read more
Source§

fn where_select<Y>( &self, on_true: &Y, on_false: &impl AsView<Repr = <Y as AsView>::Repr>, exec: &mut dyn Engine, ) -> Result<<<Y as AsView>::Repr as Repr>::Value, Error>
where Y: SelectOperand<<X as AsView>::Repr> + ?Sized, <X as AsView>::Repr: CoreRepr,

Elementwise selection: on_true where the receiver is true, on_false elsewhere, with broadcasting. The receiver is the bool condition; a typed receiver must be TypedTensor<bool>. Read more
Source§

fn dot_general( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, config: DotGeneralConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

General contraction with batch dimensions (DotGeneralConfig); DotGeneralOptions conjugates an operand. Read more
Source§

fn dot_general_with( &self, b: &impl AsView<Repr = <X as AsView>::Repr>, config: DotGeneralConfig, options: &DotGeneralOptions, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

General contraction with batch dimensions (DotGeneralConfig); DotGeneralOptions conjugates an operand. Read more
Source§

fn reduce_sum( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Sum over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_max( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Maximum over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_min( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Minimum over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_prod( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Product over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_sum_squares( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Sum of squared magnitudes over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reduce_mean( &self, axes: Option<&[isize]>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Mean over axes (None: every axis); axes are signed, -1 is the last axis. Read more
Source§

fn reshape( &self, shape: &[usize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Reshape to shape in column-major element order. Read more
Source§

fn broadcast_in_dim( &self, shape: &[usize], dims: &[usize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Broadcast to shape; dims[i] is the output axis of input axis i (an IR-level dimension map, unsigned like the *Config structs). Read more
Source§

fn transpose( &self, perm: &[isize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Permute axes; perm is signed (-1 is the last axis). Read more
Source§

fn reverse( &self, axes: &[isize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Reverse the order of elements along axes (signed). Read more
Source§

fn tril( &self, k: i64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Lower triangle of the two leading axes relative to diagonal k. Read more
Source§

fn triu( &self, k: i64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Upper triangle of the two leading axes relative to diagonal k. Read more
Source§

fn extract_diag( &self, axis_a: isize, axis_b: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Extract the diagonal of axes axis_a and axis_b (signed). Read more
Source§

fn embed_diag( &self, axis_a: isize, axis_b: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Embed axis axis_a of the receiver as the diagonal of a new axis pair; axis_b (signed, against the output rank) is the position of the inserted axis. Read more
Source§

fn slice( &self, config: SliceConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Static strided slice (SliceConfig). Read more
Source§

fn pad( &self, config: PadConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Pad with edge and interior padding (PadConfig). Read more
Source§

fn gather( &self, indices: &impl AsView, config: GatherConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

XLA-style gather (GatherConfig); indices is an integer tensor of any representation. Read more
Source§

fn scatter( &self, indices: &impl AsView, updates: &impl AsView, config: ScatterConfig, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

XLA-style scatter (ScatterConfig); indices and updates may have any representation. Read more
Source§

fn dynamic_slice( &self, starts: &impl AsView, sizes: &[usize], exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Slice of sizes starting at the run-time starts (an integer vector). Read more
Source§

fn dynamic_update_slice( &self, update: &impl AsView<Repr = <X as AsView>::Repr>, starts: &impl AsView, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Copy of the receiver with update written at the run-time starts. Read more
Source§

fn concatenate( inputs: &[&X], axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr, X: Sized,

Concatenate inputs along axis (signed). Called as CoreOps::concatenate(&[&a, &b], axis, exec). Read more
Source§

fn convert(&self, to: DType, exec: &mut dyn Engine) -> Result<Tensor, Error>
where <X as AsView>::Repr: CoreRepr,

Checked dtype conversion along tenferro’s promotion lattice. The result is a dtype-erased Tensor because its dtype is a run-time value. Read more
Source§

fn cast(&self, to: DType, exec: &mut dyn Engine) -> Result<Tensor, Error>
where <X as AsView>::Repr: CoreRepr,

Explicit, possibly lossy dtype projection. The result is a dtype-erased Tensor because its dtype is a run-time value. Read more
Source§

fn scale_real( &self, factor: f64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Multiply by a real scalar. Read more
Source§

fn scale_complex( &self, factor: Complex<f64>, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Multiply by a complex scalar. Read more
Source§

fn softmax( &self, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Softmax along axis (signed). Read more
Source§

fn log_softmax( &self, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Log-softmax along axis (signed). Read more
Source§

fn masked_softmax( &self, mask: &impl AsView, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Softmax along axis over the entries where mask is true. Read more
Source§

fn masked_log_softmax( &self, mask: &impl AsView, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Log-softmax along axis over the entries where mask is true. Read more
Source§

fn take_along_axis( &self, indices: &impl AsView, axis: isize, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Gather along axis (signed) with per-position integer indices. Read more
Source§

fn layer_norm( &self, axis: isize, weight: Option<&X>, bias: Option<&X>, eps: f64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

Layer normalization over axis (signed) with optional affine weight and bias. Read more
Source§

fn rms_norm( &self, axis: isize, weight: Option<&X>, bias: Option<&X>, eps: f64, exec: &mut dyn Engine, ) -> Result<<<X as AsView>::Repr as Repr>::Value, Error>
where <X as AsView>::Repr: CoreRepr,

RMS normalization over axis (signed) with optional affine weight and bias. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Y, C> SelectOperand<C> for Y
where Y: AsView + ?Sized, C: SelectCondition,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.