ArrTensor

Struct ArrTensor 

Source
pub struct ArrTensor<T, const N: usize, const D: usize, const LANES: usize = MAX_SIMD_SINGLE_PRECISION_LANES>{ /* private fields */ }
Expand description

A tensor made up of statically sized arrays.

Often the best choice for embedded tensor operations because it doesn’t use any OS-dependent features like heap allocators. If memory efficiency is the largest concern, the lack of dynamic heap allocation is a huge positive of ArrTensor.

However, when flexibility is put before memory efficiency and performance, this becomes obsolete; use DynTensor instead.

Implementations§

Source§

impl<T, const N: usize, const D: usize, const LANES: usize> ArrTensor<T, N, D, LANES>

Source

pub fn new(shape: [usize; D]) -> Self
where T: Default + Copy,

Instantiates a new Tensor which owns its data without allocating it.

§Panics

This constructor panics when the product of each dimension is not equal to the length of all the data.

Source

pub fn with_data(shape: [usize; D], data: [T; N]) -> Self

Instantiates a new Tensor with data.

§Panics

This constructor panics when the product of each dimension is not equal to the length of all the data.

Example:

use tensor_optim::ArrTensor;

const SHAPE: [usize; 2] = [2, 3];

let data = [0f64; 6];
let mut tensor = ArrTensor::with_data(SHAPE, data);

tensor += 42.0;
println!("First element: {}", tensor[&[0, 0]]);
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> ArrTensor<T, N, D, LANES>

Source

pub fn map<U, F>(&self, f: F) -> ArrTensor<U, N, D, LANES>
where F: FnMut(T) -> U, U: SimdElement + Primitive, [U; LANES]: AlignedSimd<[U; LANES], U, LANES>,

Map each element of ArrTensor<T, N, D, LANES> to ArrTensor<U, N, D> by applying f elementwise.

Source

pub fn zip_map<U, V, F>( &self, other: &ArrTensor<U, N, D, LANES>, f: F, ) -> ArrTensor<V, N, D, LANES>

Apply a function pairwise elementwise over two ArrTensors, mapping to a new tensor.

§Panics

Both tensors, self and other, must have the same shape or a panic will occur.

Source§

impl<T, const N: usize, const D: usize, const LANES: usize> ArrTensor<T, N, D, LANES>

Source

pub fn matmul<const M: usize, const O: usize>( &self, rhs: &ArrTensor<T, M, D, LANES>, out: &mut ArrTensor<T, O, D, LANES>, )

Batched matmul over arbitrary leading batch dims: Contracts last dim of self with second-last dim of rhs.

Matrix multiplication cannot be performed on ArrTensors when the dimensions exceed MAX_STATIC_RANK. To bypass this limit, DynTensor can be used which is allocated on the heap.

§Example
  • self shape: […, M, K]
  • rhs shape: […, K, N]
  • output shape: […, M, N]

Output buffer must be preallocated.

§Panics

This method panics when if any of these conditions are not met:

  • both tensors must have at least 2 dimensions
  • each tensors’ inner and batch dimensions must match
  • the output tensor must be the correct shape

Every one of those must be true.

Source§

impl<const N: usize, const D: usize> ArrTensor<f32, N, D>

Source

pub fn simd_matmul<const M: usize, const O: usize>( &self, rhs: &ArrTensor<f32, M, D>, out: &mut ArrTensor<f32, O, D>, )

SIMD-accelerated matrix multiplication like Self::matmul.

This is purely an enhanced version of regular matrix multiplication with the addition of SIMD acceleration. Implementation and details should be found consulting that documentation, not this function.

§Panics

Same preconditions as generic matmul.

Source§

impl<const N: usize, const D: usize> ArrTensor<f64, N, D>

Source

pub fn simd_matmul<const M: usize, const O: usize>( &self, rhs: &ArrTensor<f64, M, D>, out: &mut ArrTensor<f64, O, D>, )

SIMD-accelerated single-precision matrix multiplication like Self::matmul.

This is purely an enhanced version of regular matrix multiplication with the addition of SIMD acceleration. Implementation and details should be found consulting that documentation, not this function.

§Panics

Same preconditions as generic matmul.

Source§

impl<T, const N: usize, const D: usize, const LANES: usize> ArrTensor<T, N, D, LANES>

Source

pub fn transpose(&self) -> Self

Transposes the tensor using a default axis permutation:

  • For 2D tensors, swaps the two axes.
  • For higher-rank tensors, reverses the axes.
§Panics

Panics if D exceeds MAX_STATIC_RANK.

§Example
use tensor_optim::{ArrTensor, TensorOps};

let tensor = ArrTensor::<f32, 6, 2>::with_data([2, 3], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
let transposed = tensor.transpose();
assert_eq!(transposed.shape(), [3, 2]);
assert_eq!(transposed.data(), [1.0, 4.0, 2.0, 5.0, 3.0, 6.0]);
Source

pub fn transpose_axes(&self, perm: [usize; D]) -> Self

Returns a new ArrTensor with axes permuted according to perm.

§Panics
  • If perm is not a permutation of [0..D].
§Example
use tensor_optim::{ArrTensor, TensorOps};

let tensor = ArrTensor::<f32, 6, 2>::with_data([2, 3], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
let transposed = tensor.transpose_axes([1, 0]);
assert_eq!(transposed.shape(), [3, 2]);
assert_eq!(transposed.data(), [1.0, 4.0, 2.0, 5.0, 3.0, 6.0]);
Source

pub fn transpose_axes_unchecked(&self, perm: [usize; D]) -> Self

Permutes the axes of self assuming a valid permutation.

This is roughly equivalent, though marginally more efficient, compared to Self::transpose_axes.

Trait Implementations§

Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Add<&ArrTensor<T, N, D, LANES>> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Self) -> Self

Performs the + operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Add<&T> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &T) -> Self

Performs the + operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Add<T> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Self

Performs the + operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Add for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> AddAssign<&ArrTensor<T, N, D, LANES>> for ArrTensor<T, N, D, LANES>

Source§

fn add_assign(&mut self, rhs: &Self)

Performs the += operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> AddAssign<&T> for ArrTensor<T, N, D, LANES>

Source§

fn add_assign(&mut self, rhs: &T)

Performs the += operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> AddAssign<T> for ArrTensor<T, N, D, LANES>

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> AddAssign for ArrTensor<T, N, D, LANES>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Clone for ArrTensor<T, N, D, LANES>

Source§

fn clone(&self) -> ArrTensor<T, N, D, LANES>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> ConstTensorOps<T, N, D> for ArrTensor<T, N, D, LANES>

Source§

fn data_array(&self) -> &[T; N]

Provides the data of the current tensor in a slice of a generic T. Read more
Source§

fn data_mut_array(&mut self) -> &mut [T; N]

Provides the data of the current tensor in a slice of a generic T. Read more
Source§

fn shape_array(&self) -> &[usize; D]

Provides the shape of the current tensor as an array. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Debug for ArrTensor<T, N, D, LANES>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Div<&ArrTensor<T, N, D, LANES>> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Self) -> Self

Performs the / operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Div<&T> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &T) -> Self

Performs the / operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Div<T> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self

Performs the / operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Div for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self

Performs the / operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> DivAssign<&ArrTensor<T, N, D, LANES>> for ArrTensor<T, N, D, LANES>

Source§

fn div_assign(&mut self, rhs: &Self)

Performs the /= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> DivAssign<&T> for ArrTensor<T, N, D, LANES>

Source§

fn div_assign(&mut self, rhs: &T)

Performs the /= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> DivAssign<T> for ArrTensor<T, N, D, LANES>

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> DivAssign for ArrTensor<T, N, D, LANES>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Index<&[usize]> for ArrTensor<T, N, D, LANES>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: &[usize]) -> &Self::Output

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

impl<T, const N: usize, const D: usize, const LANES: usize> Mul<&ArrTensor<T, N, D, LANES>> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Self) -> Self

Performs the * operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Mul<&T> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &T) -> Self

Performs the * operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Mul<T> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self

Performs the * operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Mul for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> MulAssign<&ArrTensor<T, N, D, LANES>> for ArrTensor<T, N, D, LANES>

Source§

fn mul_assign(&mut self, rhs: &Self)

Performs the *= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> MulAssign<&T> for ArrTensor<T, N, D, LANES>

Source§

fn mul_assign(&mut self, rhs: &T)

Performs the *= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> MulAssign<T> for ArrTensor<T, N, D, LANES>

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> MulAssign for ArrTensor<T, N, D, LANES>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Ord for ArrTensor<T, N, D, LANES>

Source§

fn cmp(&self, other: &ArrTensor<T, N, D, LANES>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> PartialEq for ArrTensor<T, N, D, LANES>

Source§

fn eq(&self, other: &ArrTensor<T, N, D, LANES>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> PartialOrd for ArrTensor<T, N, D, LANES>

Source§

fn partial_cmp(&self, other: &ArrTensor<T, N, D, LANES>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Sub<&ArrTensor<T, N, D, LANES>> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Self) -> Self

Performs the - operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Sub<&T> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &T) -> Self

Performs the - operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Sub<T> for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: T) -> Self

Performs the - operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Sub for ArrTensor<T, N, D, LANES>

Source§

type Output = ArrTensor<T, N, D, LANES>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self

Performs the - operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> SubAssign<&ArrTensor<T, N, D, LANES>> for ArrTensor<T, N, D, LANES>

Source§

fn sub_assign(&mut self, rhs: &Self)

Performs the -= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> SubAssign<&T> for ArrTensor<T, N, D, LANES>

Source§

fn sub_assign(&mut self, rhs: &T)

Performs the -= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> SubAssign<T> for ArrTensor<T, N, D, LANES>

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> SubAssign for ArrTensor<T, N, D, LANES>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> TensorOps<T> for ArrTensor<T, N, D, LANES>

Source§

fn data(&self) -> &[T]

Provides the data of the current tensor in a slice of a generic T. Read more
Source§

fn data_mut(&mut self) -> &mut [T]

Provides the data of the current tensor in a slice of a generic T. Read more
Source§

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

Provides the shape of the current tensor as a slice. Read more
Source§

fn index_offset(&self, idx: &[usize]) -> Option<usize>

Finds the index in data given a slice with one entry/dimension.
Source§

impl<T, const N: usize, const D: usize, const LANES: usize> Eq for ArrTensor<T, N, D, LANES>

Source§

impl<T, const N: usize, const D: usize, const LANES: usize> StructuralPartialEq for ArrTensor<T, N, D, LANES>

Auto Trait Implementations§

§

impl<T, const N: usize, const D: usize, const LANES: usize> Freeze for ArrTensor<T, N, D, LANES>
where [T; LANES]: Sized, T: Freeze,

§

impl<T, const N: usize, const D: usize, const LANES: usize> RefUnwindSafe for ArrTensor<T, N, D, LANES>

§

impl<T, const N: usize, const D: usize, const LANES: usize> Send for ArrTensor<T, N, D, LANES>
where [T; LANES]: Sized, T: Send,

§

impl<T, const N: usize, const D: usize, const LANES: usize> Sync for ArrTensor<T, N, D, LANES>
where [T; LANES]: Sized, T: Sync,

§

impl<T, const N: usize, const D: usize, const LANES: usize> Unpin for ArrTensor<T, N, D, LANES>
where [T; LANES]: Sized, T: Unpin,

§

impl<T, const N: usize, const D: usize, const LANES: usize> UnwindSafe for ArrTensor<T, N, D, LANES>

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<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<T> SupersetOf<T> for T

Source§

fn from_subset(scalar: T) -> T

Copies scalar for all slots in an instance Self.
Source§

fn into_subset(self) -> T

Moves out a unit T from self.
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.
Source§

impl<S, T> ImplicitSubsetOf<T> for S
where T: ImplicitSupersetOf<S>,

Source§

impl<S, T> ImplicitSupersetOf<T> for S
where S: SupersetOf<T>,