Skip to main content

TensorView

Struct TensorView 

Source
pub struct TensorView<'a, Scalar, const MAX_RANK: usize = DEFAULT_MAX_RANK> { /* private fields */ }
Expand description

A read-only, zero-copy view into a Tensor.

TensorView borrows the parent tensor’s memory for the duration of 'a without owning or copying any data. Views may have arbitrary byte strides, so they transparently represent slicing, transposition, or step-sampling of the underlying storage — iteration and indexing honour those strides.

A view is normally obtained by calling Tensor::view or by slicing: tensor.slice((0..4_usize, ..)). For lower-level construction from a raw pointer plus shape/stride arrays, see TensorView::from_raw_parts.

TensorView is the immutable counterpart of TensorSpan. Both share the same layout fields, but a view cannot be used to mutate the backing storage. Multiple views into the same tensor may coexist, subject to Rust’s borrow rules; a mutable span excludes all other references.

The 'a lifetime ties the view to the source tensor (or outer view), ensuring the referenced memory outlives the view itself.

Implementations§

Source§

impl<'a, Scalar: MaxSim, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_maxsim_pack_in<Alloc: Allocator>( &self, alloc: Alloc, ) -> Result<MaxSimPackedMatrix<Scalar, Alloc>, TensorError>

Pack this 2D tensor view for MaxSim scoring using the provided allocator.

Source

pub fn try_maxsim_pack( &self, ) -> Result<MaxSimPackedMatrix<Scalar, Global>, TensorError>

Pack this 2D tensor view for MaxSim scoring using the global allocator.

Source§

impl<'a, Scalar: Dots, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>
where Scalar::Accumulator: 'static,

Source

pub fn try_dots_symmetric( &self, ) -> Result<Tensor<Scalar::Accumulator, Global, MAX_RANK>, TensorError>

Computes the symmetric dot-product matrix C = A × Aᵀ.

Given a matrix of row vectors, computes the matrix of all pairwise dot products. The result is a symmetric n×n matrix where result[i,j] = dot(row_i, row_j).

§Example
use numkong::{Tensor, TensorView};

// 100 vectors of dimension 768
let vectors = Tensor::<f32>::try_full(&[100, 768], 0.0)?;

// Compute 100×100 symmetric matrix
let gram = vectors.view().try_dots_symmetric()?;
assert_eq!(gram.shape(), &[100, 100]);
Source

pub fn try_dots_symmetric_into<OutputTensor, const OUTPUT_MAX_RANK: usize>( &self, c: &mut OutputTensor, ) -> Result<(), TensorError>
where OutputTensor: TensorMut<Scalar::Accumulator, OUTPUT_MAX_RANK>,

Computes the symmetric dot-product matrix into pre-allocated output.

Only the upper triangle of c is written; the lower triangle is left as-is. The output may be a &mut Tensor<...> or &mut TensorSpan<...>.

Source§

impl<'a, Scalar: Angulars, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_angulars_symmetric( &self, ) -> Result<Tensor<Scalar::SpatialResult, Global, MAX_RANK>, TensorError>

Computes symmetric angular distance matrix for a set of vectors.

Source

pub fn try_angulars_symmetric_into<OutputTensor, const OUTPUT_MAX_RANK: usize>( &self, c: &mut OutputTensor, ) -> Result<(), TensorError>
where OutputTensor: TensorMut<Scalar::SpatialResult, OUTPUT_MAX_RANK>,

Computes symmetric angular distances into pre-allocated output. Only the upper triangle is written.

Source§

impl<'a, Scalar: Euclideans, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_euclideans_symmetric( &self, ) -> Result<Tensor<Scalar::SpatialResult, Global, MAX_RANK>, TensorError>

Computes symmetric euclidean distance matrix for a set of vectors.

Source

pub fn try_euclideans_symmetric_into<OutputTensor, const OUTPUT_MAX_RANK: usize>( &self, c: &mut OutputTensor, ) -> Result<(), TensorError>
where OutputTensor: TensorMut<Scalar::SpatialResult, OUTPUT_MAX_RANK>,

Computes symmetric euclidean distances into pre-allocated output. Only the upper triangle is written.

Source§

impl<'a, Scalar: Hammings, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_hammings_symmetric( &self, ) -> Result<Tensor<u32, Global, MAX_RANK>, TensorError>

Computes symmetric Hamming distance matrix for a set of binary vectors.

Source

pub fn try_hammings_symmetric_into<OutputTensor, const OUTPUT_MAX_RANK: usize>( &self, c: &mut OutputTensor, ) -> Result<(), TensorError>
where OutputTensor: TensorMut<u32, OUTPUT_MAX_RANK>,

Computes symmetric Hamming distances into pre-allocated output. Only the upper triangle is written.

Source§

impl<'a, Scalar: Jaccards, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_jaccards_symmetric( &self, ) -> Result<Tensor<Scalar::JaccardResult, Global, MAX_RANK>, TensorError>

Computes symmetric Jaccard distance matrix for a set of binary vectors.

Source

pub fn try_jaccards_symmetric_into<OutputTensor, const OUTPUT_MAX_RANK: usize>( &self, c: &mut OutputTensor, ) -> Result<(), TensorError>
where OutputTensor: TensorMut<Scalar::JaccardResult, OUTPUT_MAX_RANK>,

Computes symmetric Jaccard distances into pre-allocated output. Only the upper triangle is written.

Source§

impl<'a, Scalar, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub unsafe fn from_raw_parts( data: *const Scalar, shape: &[usize], strides_bytes: &[isize], ) -> Self

Create a view from a raw pointer, shape, and byte strides.

The shape specifies logical dimensions. For sub-byte types, the storage count is inferred as shape.product() / dimensions_per_value(). For normal types the two are equal.

§Safety
  • data must be valid for reads over the region described by shape and strides_bytes.
  • The pointed-to memory must outlive 'a.
  • shape.len() must be <= MAX_RANK.
  • shape.len() must equal strides_bytes.len().
§Panics

Panics if shape.len() > MAX_RANK or shape.len() != strides_bytes.len().

Source

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

Returns the shape of the view.

Source

pub fn ndim(&self) -> usize

Returns the number of dimensions.

Source

pub fn rank(&self) -> usize

Returns the number of dimensions (alias for ndim()).

Source

pub fn numel(&self) -> usize

Returns the total number of logical elements (computed from shape).

Source

pub fn is_empty(&self) -> bool

Returns true if the view has no elements.

Source

pub fn stride_bytes(&self, dim: usize) -> isize

Returns the stride in bytes for the given dimension.

Source

pub fn as_ptr(&self) -> *const Scalar

Returns a pointer to the first element.

Source

pub fn has_contiguous_rows(&self) -> bool

Check if the view has contiguous rows.

Source

pub fn is_contiguous(&self) -> bool

Check if the entire view is contiguous in memory.

Source

pub unsafe fn get_unchecked(&self, index: usize) -> &Scalar

Get element at flat index (only valid for contiguous views).

§Safety

Caller must ensure the view is contiguous and index is in bounds.

Source

pub fn try_flat<AnyIndex: VectorIndex>( &self, index: AnyIndex, ) -> Result<&Scalar, TensorError>

Try to get an element by flat logical row-major index.

Negative isize indices wrap from the end (-1 is the last element). Returns TensorError::DimensionMismatch on a rank-0 view and TensorError::IndexOutOfBounds when the index is outside the logical element count.

§Examples
use numkong::tensor::Tensor;

let t = Tensor::<f32>::try_from_slice(&[1.0, 2.0, 3.0, 4.0], &[2, 2]).unwrap();
let view = t.view();
assert_eq!(*view.try_flat(0_usize).unwrap(), 1.0);
assert_eq!(*view.try_flat(-1_i32).unwrap(), 4.0);
Source

pub fn try_coords<C: TensorCoordinates>( &self, coords: C, ) -> Result<&Scalar, TensorError>

Try to get an element by exact coordinates.

Source

pub fn try_scalar(&self) -> Result<&Scalar, TensorError>

Try to access the scalar value of a rank-0 tensor view.

Source

pub fn slice_leading<AnyIndex: VectorIndex>( &self, index: AnyIndex, ) -> Result<TensorView<'a, Scalar, MAX_RANK>, TensorError>

Slice the leading axis by one index, reducing rank by one.

Source

pub fn slice( &self, spec: impl SliceSpec, ) -> Result<TensorView<'a, Scalar, MAX_RANK>, TensorError>

Slice the view along multiple dimensions.

Accepts tuples of Rust range types or &[SliceRange]. Indexing with a scalar reduces the rank, while range arguments preserve it.

§Examples
use numkong::tensor::{Tensor, SliceRange};

let t = Tensor::<f32>::try_full(&[4, 5], 1.0).unwrap();
let view = t.view();

// Rust-native tuple syntax
let row = view.slice((1_usize, ..)).unwrap();            // t[1, :]
let block = view.slice((1..3_usize, 0..4_usize)).unwrap();// t[1:3, 0:4]

// Enum-based syntax for programmatic construction
let same_row = view.slice(&[SliceRange::index(1), SliceRange::full()]).unwrap();
assert_eq!(row.shape(), same_row.shape());
Source§

impl<'a, Scalar: Clone + StorageElement, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn to_owned(&self) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Copy the view contents to a new owned Tensor.

Source

pub fn storage_len(&self) -> usize

Number of storage values (for sub-byte types, less than numel).

Source

pub fn as_contiguous_slice(&self) -> Option<&[Scalar]>

Convert to slice (only valid for contiguous views).

Source§

impl<'a, Scalar, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn axis_views<AnyIndex: VectorIndex>( &self, axis: AnyIndex, ) -> Result<AxisIterator<'a, Scalar, MAX_RANK>, TensorError>

Iterate along the given axis, yielding sub-tensor views with rank-1.

Source§

impl<'a, Scalar: StorageElement, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn transpose(&self) -> Result<TensorView<'a, Scalar, MAX_RANK>, TensorError>

Transpose (reverse all dimensions, no data copy).

Returns an error for sub-byte types with ndim >= 2, since transposing would produce non-contiguous strides that break packed element addressing.

Source

pub fn reshape( &self, new_shape: &[usize], ) -> Result<TensorView<'a, Scalar, MAX_RANK>, TensorError>

Reshape the view (must have same total elements, contiguous only).

Returns an error for sub-byte types, since reshape would invalidate the packed element layout.

Source

pub fn flatten(&self) -> Result<TensorView<'a, Scalar, MAX_RANK>, TensorError>

Flatten to 1D (requires contiguous layout).

Source

pub fn squeeze(&self) -> TensorView<'a, Scalar, MAX_RANK>

Remove dimensions of size 1.

Source§

impl<'a, Scalar: FloatConvertible, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn iter(&self) -> TensorViewIterator<'a, Scalar, MAX_RANK>

Returns a lazy iterator over all logical scalars in row-major order.

Yields (position, DimRef) pairs. Use .iter().dims() for just dimensions. For sub-byte types, the innermost dimension is expanded.

Source§

impl<'a, Scalar: Clone + EachScale, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>
where Scalar::Scalar: From<f32> + Mul<Output = Scalar::Scalar> + Copy,

Source

pub fn try_scale_tensor( &self, alpha: Scalar::Scalar, beta: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_scale_tensor_into( &self, alpha: Scalar::Scalar, beta: Scalar::Scalar, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source

pub fn try_add_scalar( &self, scalar: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_sub_scalar( &self, scalar: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_mul_scalar( &self, scalar: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_add_scalar_into( &self, scalar: Scalar::Scalar, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source

pub fn try_sub_scalar_into( &self, scalar: Scalar::Scalar, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source

pub fn try_mul_scalar_into( &self, scalar: Scalar::Scalar, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Scalar: Clone + EachSum, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_add_tensor( &self, other: &TensorView<'_, Scalar, MAX_RANK>, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_add_tensor_into( &self, other: &TensorView<'_, Scalar, MAX_RANK>, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Scalar: Clone + EachBlend, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>
where Scalar::Scalar: From<f32> + Copy,

Source

pub fn try_blend_tensor( &self, other: &TensorView<'_, Scalar, MAX_RANK>, alpha: Scalar::Scalar, beta: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_blend_tensor_into( &self, other: &TensorView<'_, Scalar, MAX_RANK>, alpha: Scalar::Scalar, beta: Scalar::Scalar, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source

pub fn try_sub_tensor( &self, other: &TensorView<'_, Scalar, MAX_RANK>, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_sub_tensor_into( &self, other: &TensorView<'_, Scalar, MAX_RANK>, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Scalar: Clone + EachFMA, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>
where Scalar::Scalar: From<f32> + Copy,

Source

pub fn try_fma_tensors( &self, b: &TensorView<'_, Scalar, MAX_RANK>, c: &TensorView<'_, Scalar, MAX_RANK>, alpha: Scalar::Scalar, beta: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_fma_tensors_into( &self, b: &TensorView<'_, Scalar, MAX_RANK>, c: &TensorView<'_, Scalar, MAX_RANK>, alpha: Scalar::Scalar, beta: Scalar::Scalar, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source

pub fn try_mul_tensor( &self, other: &TensorView<'_, Scalar, MAX_RANK>, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_mul_tensor_into( &self, other: &TensorView<'_, Scalar, MAX_RANK>, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Source: Clone + CastDtype, const MAX_RANK: usize> TensorView<'a, Source, MAX_RANK>

Source

pub fn try_cast_dtype<Destination: Clone + CastDtype>( &self, ) -> Result<Tensor<Destination, Global, MAX_RANK>, TensorError>

Source

pub fn try_cast_dtype_into<Destination: Clone + CastDtype>( &self, out: &mut TensorSpan<'_, Destination, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Scalar: Clone + EachSin, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_sin(&self) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_sin_into( &self, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Scalar: Clone + EachCos, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_cos(&self) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_cos_into( &self, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Scalar: Clone + EachATan, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>

Source

pub fn try_atan(&self) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source

pub fn try_atan_into( &self, out: &mut TensorSpan<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Scalar: Clone + ReduceMoments, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>
where Scalar::SumOutput: Clone + Default + AddAssign, Scalar::SumSqOutput: Clone + Default + AddAssign + SumSqToF64,

Source

pub fn try_moments_all( &self, ) -> Result<(Scalar::SumOutput, Scalar::SumSqOutput), TensorError>

Source

pub fn try_moments_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<(Tensor<<Scalar as ReduceMoments>::SumOutput, Global, MAX_RANK>, Tensor<<Scalar as ReduceMoments>::SumSqOutput, Global, MAX_RANK>), TensorError>

Source

pub fn try_moments_axis_into<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, sum_out: &mut Tensor<Scalar::SumOutput, Global, MAX_RANK>, sumsq_out: &mut Tensor<Scalar::SumSqOutput, Global, MAX_RANK>, ) -> Result<(), TensorError>

Source

pub fn try_sum_all(&self) -> Result<Scalar::SumOutput, TensorError>

Source

pub fn try_sum_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<Scalar::SumOutput, Global, MAX_RANK>, TensorError>

Source

pub fn try_sum_axis_into<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, out: &mut Tensor<Scalar::SumOutput, Global, MAX_RANK>, ) -> Result<(), TensorError>

Source

pub fn try_norm_all(&self) -> Result<f64, TensorError>

Source

pub fn try_norm_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<f64, Global, MAX_RANK>, TensorError>

Source

pub fn try_norm_axis_into<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, out: &mut Tensor<f64, Global, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<'a, Scalar: Clone + ReduceMinMax, const MAX_RANK: usize> TensorView<'a, Scalar, MAX_RANK>
where Scalar::Output: Clone + Default + PartialOrd,

Source

pub fn try_minmax_all( &self, ) -> Result<MinMaxResult<Scalar::Output>, TensorError>

Source

pub fn try_minmax_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<MinMaxResult<Tensor<<Scalar as ReduceMinMax>::Output, Global, MAX_RANK>, Tensor<usize, Global, MAX_RANK>>, TensorError>

Source

pub fn try_minmax_axis_into<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, min_out: &mut Tensor<Scalar::Output, Global, MAX_RANK>, argmin_out: &mut Tensor<usize, Global, MAX_RANK>, max_out: &mut Tensor<Scalar::Output, Global, MAX_RANK>, argmax_out: &mut Tensor<usize, Global, MAX_RANK>, ) -> Result<(), TensorError>

Source

pub fn try_min_all(&self) -> Result<Scalar::Output, TensorError>

Source

pub fn try_argmin_all(&self) -> Result<usize, TensorError>

Source

pub fn try_max_all(&self) -> Result<Scalar::Output, TensorError>

Source

pub fn try_argmax_all(&self) -> Result<usize, TensorError>

Source

pub fn try_min_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<Scalar::Output, Global, MAX_RANK>, TensorError>

Source

pub fn try_argmin_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<usize, Global, MAX_RANK>, TensorError>

Source

pub fn try_max_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<Scalar::Output, Global, MAX_RANK>, TensorError>

Source

pub fn try_argmax_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<usize, Global, MAX_RANK>, TensorError>

Trait Implementations§

Source§

impl<'a, 'b, Scalar: StorageElement, const MAX_RANK: usize> CopyFrom<&'b TensorView<'_, Scalar, MAX_RANK>> for TensorSpan<'a, Scalar, MAX_RANK>

Source§

fn copy_from( &mut self, source: &'b TensorView<'_, Scalar, MAX_RANK>, ) -> Result<(), TensorError>

Copy from source into self. Returns an error on a shape or storage mismatch and does not modify the destination on error.
Source§

impl<'a, I0: VectorIndex, I1: VectorIndex, Scalar, const MAX_RANK: usize> Index<(I0, I1)> for TensorView<'a, Scalar, MAX_RANK>

Source§

type Output = Scalar

The returned type after indexing.
Source§

fn index(&self, index: (I0, I1)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, Scalar, const MAX_RANK: usize> Index<(I0, I1, I2)> for TensorView<'a, Scalar, MAX_RANK>

Source§

type Output = Scalar

The returned type after indexing.
Source§

fn index(&self, index: (I0, I1, I2)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, Scalar: StorageElement, const MAX_RANK: usize> Index<(I0, I1, I2, I3)> for TensorView<'a, Scalar, MAX_RANK>

Source§

type Output = Scalar

The returned type after indexing.
Source§

fn index(&self, index: (I0, I1, I2, I3)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, Scalar: StorageElement, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4)> for TensorView<'a, Scalar, MAX_RANK>

Source§

type Output = Scalar

The returned type after indexing.
Source§

fn index(&self, index: (I0, I1, I2, I3, I4)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, Scalar: StorageElement, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5)> for TensorView<'a, Scalar, MAX_RANK>

Source§

type Output = Scalar

The returned type after indexing.
Source§

fn index(&self, index: (I0, I1, I2, I3, I4, I5)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, Scalar: StorageElement, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5, I6)> for TensorView<'a, Scalar, MAX_RANK>

Source§

type Output = Scalar

The returned type after indexing.
Source§

fn index(&self, index: (I0, I1, I2, I3, I4, I5, I6)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, I0: VectorIndex, I1: VectorIndex, I2: VectorIndex, I3: VectorIndex, I4: VectorIndex, I5: VectorIndex, I6: VectorIndex, I7: VectorIndex, Scalar: StorageElement, const MAX_RANK: usize> Index<(I0, I1, I2, I3, I4, I5, I6, I7)> for TensorView<'a, Scalar, MAX_RANK>

Source§

type Output = Scalar

The returned type after indexing.
Source§

fn index(&self, index: (I0, I1, I2, I3, I4, I5, I6, I7)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, AnyIndex: VectorIndex, Scalar, const MAX_RANK: usize> Index<AnyIndex> for TensorView<'a, Scalar, MAX_RANK>

Source§

type Output = Scalar

The returned type after indexing.
Source§

fn index(&self, index: AnyIndex) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, Scalar: FloatConvertible, const MAX_RANK: usize> IntoIterator for &'a TensorView<'a, Scalar, MAX_RANK>

Source§

type Item = ([usize; MAX_RANK], DimRef<'a, Scalar>)

The type of the elements being iterated over.
Source§

type IntoIter = TensorViewIterator<'a, Scalar, MAX_RANK>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, Scalar: FloatConvertible, const MAX_RANK: usize> PartialEq for TensorView<'a, Scalar, MAX_RANK>
where Scalar::DimScalar: PartialEq,

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a, Scalar: StorageElement, const R: usize> TensorRef<Scalar, R> for TensorView<'a, Scalar, R>

Source§

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

Logical shape as a slice of length ndim(). Read more
Source§

fn ndim(&self) -> usize

Number of dimensions currently in use. Read more
Source§

fn stride_bytes(&self, dim: usize) -> isize

Byte stride along dimension dim. Read more
Source§

fn as_ptr(&self) -> *const Scalar

Raw pointer to the first storage element. Read more
Source§

fn view(&self) -> TensorView<'_, Scalar, R>

Borrow as an immutable TensorView with the same shape and strides. Read more
Source§

fn numel(&self) -> usize

Total number of logical elements (product of shape dimensions). Read more
Source§

fn rank(&self) -> usize

Alias for ndim — number of dimensions.
Source§

fn is_empty(&self) -> bool

Returns true if the tensor contains zero logical elements. Read more
Source§

fn has_contiguous_rows(&self) -> bool

Returns true for rank-2 tensors whose innermost stride equals one element — the layout required by GEMM’s left-hand matrix.
Source§

fn is_contiguous(&self) -> bool

Returns true if the entire tensor is stored in row-major contiguous order with no gaps. Read more

Auto Trait Implementations§

§

impl<'a, Scalar, const MAX_RANK: usize = DEFAULT_MAX_RANK> !Send for TensorView<'a, Scalar, MAX_RANK>

§

impl<'a, Scalar, const MAX_RANK: usize = DEFAULT_MAX_RANK> !Sync for TensorView<'a, Scalar, MAX_RANK>

§

impl<'a, Scalar, const MAX_RANK: usize> Freeze for TensorView<'a, Scalar, MAX_RANK>

§

impl<'a, Scalar, const MAX_RANK: usize> RefUnwindSafe for TensorView<'a, Scalar, MAX_RANK>
where Scalar: RefUnwindSafe,

§

impl<'a, Scalar, const MAX_RANK: usize> Unpin for TensorView<'a, Scalar, MAX_RANK>

§

impl<'a, Scalar, const MAX_RANK: usize> UnsafeUnpin for TensorView<'a, Scalar, MAX_RANK>

§

impl<'a, Scalar, const MAX_RANK: usize> UnwindSafe for TensorView<'a, Scalar, MAX_RANK>
where Scalar: RefUnwindSafe,

Blanket Implementations§

Source§

impl<C, Scalar, const R: usize> AllCloseOps<Scalar, R> for C
where Scalar: FloatConvertible, C: TensorRef<Scalar, R>, <Scalar as FloatConvertible>::DimScalar: NumberLike,

Source§

fn allclose( &self, other: &(impl TensorRef<Scalar, MAX_RANK> + ?Sized), atol: f64, rtol: f64, ) -> bool

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<Container, const MAX_RANK: usize> BitwiseReductions<MAX_RANK> for Container
where Container: TensorRef<u1x8, MAX_RANK> + ?Sized,

Source§

fn popcount(&self) -> u64

Number of set bits across the entire tensor.
Source§

fn any_set(&self) -> bool

true if at least one bit in the tensor is set.
Source§

fn none_set(&self) -> bool

true if no bit in the tensor is set.
Source§

fn all_set(&self) -> bool

true if every bit in the tensor is set.
Source§

impl<Scalar, const R: usize, C> BlendOps<Scalar, R> for C
where Scalar: Clone + EachBlend, C: TensorRef<Scalar, R>, <Scalar as EachBlend>::Scalar: From<f32> + Copy,

Source§

fn try_sub_tensor( &self, other: &(impl TensorRef<Scalar, MAX_RANK> + ?Sized), ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

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<Source, const R: usize, C> CastOps<Source, R> for C
where Source: Clone + CastDtype, C: TensorRef<Source, R>,

Source§

fn try_cast_dtype<Destination: Clone + CastDtype>( &self, ) -> Result<Tensor<Destination, Global, MAX_RANK>, TensorError>

Source§

impl<Scalar, const R: usize, C> FmaOps<Scalar, R> for C
where Scalar: Clone + EachFMA, C: TensorRef<Scalar, R>, <Scalar as EachFMA>::Scalar: From<f32> + Copy,

Source§

fn try_mul_tensor( &self, other: &(impl TensorRef<Scalar, MAX_RANK> + ?Sized), ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

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<Scalar, const R: usize, C> MinMaxOps<Scalar, R> for C
where Scalar: Clone + ReduceMinMax, C: TensorRef<Scalar, R>, <Scalar as ReduceMinMax>::Output: Clone + Default + PartialOrd,

Source§

fn try_minmax_all(&self) -> Result<MinMaxResult<Scalar::Output>, TensorError>

Source§

fn try_minmax_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<MinMaxResult<Tensor<<Scalar as ReduceMinMax>::Output, Global, MAX_RANK>, Tensor<usize, Global, MAX_RANK>>, TensorError>

Source§

fn try_minmax_axis_into<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, min_out: &mut Tensor<Scalar::Output, Global, MAX_RANK>, argmin_out: &mut Tensor<usize, Global, MAX_RANK>, max_out: &mut Tensor<Scalar::Output, Global, MAX_RANK>, argmax_out: &mut Tensor<usize, Global, MAX_RANK>, ) -> Result<(), TensorError>

Source§

fn try_min_all(&self) -> Result<Scalar::Output, TensorError>

Source§

fn try_argmin_all(&self) -> Result<usize, TensorError>

Source§

fn try_max_all(&self) -> Result<Scalar::Output, TensorError>

Source§

fn try_argmax_all(&self) -> Result<usize, TensorError>

Source§

fn try_min_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<Scalar::Output, Global, MAX_RANK>, TensorError>

Source§

fn try_argmin_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<usize, Global, MAX_RANK>, TensorError>

Source§

fn try_max_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<Scalar::Output, Global, MAX_RANK>, TensorError>

Source§

fn try_argmax_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<usize, Global, MAX_RANK>, TensorError>

Source§

impl<Scalar, const R: usize, C> MomentsOps<Scalar, R> for C
where Scalar: Clone + ReduceMoments, C: TensorRef<Scalar, R>, <Scalar as ReduceMoments>::SumOutput: Clone + Default + AddAssign, <Scalar as ReduceMoments>::SumSqOutput: Clone + Default + AddAssign + SumSqToF64,

Source§

fn try_moments_all( &self, ) -> Result<(Scalar::SumOutput, Scalar::SumSqOutput), TensorError>

Source§

fn try_moments_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<(Tensor<<Scalar as ReduceMoments>::SumOutput, Global, MAX_RANK>, Tensor<<Scalar as ReduceMoments>::SumSqOutput, Global, MAX_RANK>), TensorError>

Source§

fn try_moments_axis_into<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, sum_out: &mut Tensor<Scalar::SumOutput, Global, MAX_RANK>, sumsq_out: &mut Tensor<Scalar::SumSqOutput, Global, MAX_RANK>, ) -> Result<(), TensorError>

Source§

fn try_sum_all(&self) -> Result<Scalar::SumOutput, TensorError>

Source§

fn try_sum_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<Scalar::SumOutput, Global, MAX_RANK>, TensorError>

Source§

fn try_sum_axis_into<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, out: &mut Tensor<Scalar::SumOutput, Global, MAX_RANK>, ) -> Result<(), TensorError>

Source§

fn try_norm_all(&self) -> Result<f64, TensorError>

Source§

fn try_norm_axis<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, ) -> Result<Tensor<f64, Global, MAX_RANK>, TensorError>

Source§

fn try_norm_axis_into<AnyIndex: VectorIndex>( &self, axis: AnyIndex, keep_dims: bool, out: &mut Tensor<f64, Global, MAX_RANK>, ) -> Result<(), TensorError>

Source§

impl<Scalar, const R: usize, C> ScaleOps<Scalar, R> for C
where Scalar: Clone + EachScale, C: TensorRef<Scalar, R>, <Scalar as EachScale>::Scalar: From<f32> + Mul<Output = <Scalar as EachScale>::Scalar> + Copy,

Source§

fn try_add_scalar( &self, scalar: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source§

fn try_sub_scalar( &self, scalar: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source§

fn try_mul_scalar( &self, scalar: Scalar::Scalar, ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source§

impl<Scalar, const R: usize, C> SumOps<Scalar, R> for C
where Scalar: Clone + EachSum, C: TensorRef<Scalar, R>,

Source§

fn try_add_tensor( &self, other: &(impl TensorRef<Scalar, MAX_RANK> + ?Sized), ) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source§

impl<Scalar, const R: usize, OutputTensor> SymmetricAngulars<Scalar, R> for OutputTensor
where Scalar: Angulars, OutputTensor: TensorRef<Scalar, R>,

Source§

fn try_angulars_symmetric( &self, ) -> Result<Tensor<Scalar::SpatialResult, Global, MAX_RANK>, TensorError>

Source§

fn try_angulars_symmetric_into<Out, const OUTPUT_MAX_RANK: usize>( &self, c: &mut Out, ) -> Result<(), TensorError>
where Out: TensorMut<Scalar::SpatialResult, OUTPUT_MAX_RANK>,

Writes the symmetric angular-distance matrix into pre-allocated output. Only the upper triangle is written.
Source§

impl<Scalar, const R: usize, OutputTensor> SymmetricDots<Scalar, R> for OutputTensor
where Scalar: Dots, OutputTensor: TensorRef<Scalar, R>, <Scalar as Dots>::Accumulator: 'static,

Source§

fn try_dots_symmetric( &self, ) -> Result<Tensor<Scalar::Accumulator, Global, MAX_RANK>, TensorError>

Source§

fn try_dots_symmetric_into<Out, const OUTPUT_MAX_RANK: usize>( &self, c: &mut Out, ) -> Result<(), TensorError>
where Out: TensorMut<Scalar::Accumulator, OUTPUT_MAX_RANK>,

Writes the symmetric dot-product matrix into pre-allocated output. Only the upper triangle is written.
Source§

impl<Scalar, const R: usize, OutputTensor> SymmetricEuclideans<Scalar, R> for OutputTensor
where Scalar: Euclideans, OutputTensor: TensorRef<Scalar, R>,

Source§

fn try_euclideans_symmetric( &self, ) -> Result<Tensor<Scalar::SpatialResult, Global, MAX_RANK>, TensorError>

Source§

fn try_euclideans_symmetric_into<Out, const OUTPUT_MAX_RANK: usize>( &self, c: &mut Out, ) -> Result<(), TensorError>
where Out: TensorMut<Scalar::SpatialResult, OUTPUT_MAX_RANK>,

Writes the symmetric euclidean-distance matrix into pre-allocated output. Only the upper triangle is written.
Source§

impl<Scalar, const R: usize, OutputTensor> SymmetricHammings<Scalar, R> for OutputTensor
where Scalar: Hammings, OutputTensor: TensorRef<Scalar, R>,

Source§

fn try_hammings_symmetric( &self, ) -> Result<Tensor<u32, Global, MAX_RANK>, TensorError>

Source§

fn try_hammings_symmetric_into<Out, const OUTPUT_MAX_RANK: usize>( &self, c: &mut Out, ) -> Result<(), TensorError>
where Out: TensorMut<u32, OUTPUT_MAX_RANK>,

Writes the symmetric Hamming-distance matrix into pre-allocated output. Only the upper triangle is written.
Source§

impl<Scalar, const R: usize, OutputTensor> SymmetricJaccards<Scalar, R> for OutputTensor
where Scalar: Jaccards, OutputTensor: TensorRef<Scalar, R>,

Source§

fn try_jaccards_symmetric( &self, ) -> Result<Tensor<Scalar::JaccardResult, Global, MAX_RANK>, TensorError>

Source§

fn try_jaccards_symmetric_into<Out, const OUTPUT_MAX_RANK: usize>( &self, c: &mut Out, ) -> Result<(), TensorError>
where Out: TensorMut<Scalar::JaccardResult, OUTPUT_MAX_RANK>,

Writes the symmetric Jaccard-distance matrix into pre-allocated output. Only the upper triangle is written.
Source§

impl<Scalar, const R: usize, C> TrigAtanOps<Scalar, R> for C
where Scalar: Clone + EachATan, C: TensorRef<Scalar, R>,

Source§

fn try_atan(&self) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source§

impl<Scalar, const R: usize, C> TrigCosOps<Scalar, R> for C
where Scalar: Clone + EachCos, C: TensorRef<Scalar, R>,

Source§

fn try_cos(&self) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source§

impl<Scalar, const R: usize, C> TrigSinOps<Scalar, R> for C
where Scalar: Clone + EachSin, C: TensorRef<Scalar, R>,

Source§

fn try_sin(&self) -> Result<Tensor<Scalar, Global, MAX_RANK>, TensorError>

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.