Type Alias Tensor5

Source
pub type Tensor5<const X: usize, const Y: usize, const Z: usize, const W: usize, const V: usize> = Tensor<Dim5<X, Y, Z, W, V>>;
Expand description

A 5-th order tensor.

Aliased Type§

pub struct Tensor5<const X: usize, const Y: usize, const Z: usize, const W: usize, const V: usize> {
    pub inner: <Dim5<X, Y, Z, W, V> as Dimension>::ArrayForm,
}

Fields§

§inner: <Dim5<X, Y, Z, W, V> as Dimension>::ArrayForm

Implementations§

Source§

impl<const X: usize, const Y: usize, const Z: usize, const W: usize, const V: usize> Tensor5<X, Y, Z, W, V>
where [f32; { _ }]: Sized,

Source

pub fn convolution<const KX: usize, const BX: usize, const KY: usize, const BY: usize, const KZ: usize, const BZ: usize, const KW: usize, const BW: usize, const KV: usize, const BV: usize>( &self, kernel: &Tensor5<KX, KY, KZ, KW, KV>, stride: &[usize], ) -> Tensor5<BX, BY, BZ, BW, BV>
where [f32; { _ }]: Sized,

Computes the convolution with padded 0.

§Stride

The stride parameter controls the amount that kernel moves in each iteration. Note that it panics when any elememt in stride[..5] is 0 or stride.len() < 5. If unsure, use &[1; 5]

§Note

Each dimension of the output must be ceil((self + kernel) / stride) - 1 or else there will be a runtime panic. It is not checked during compile time due to Rust type bound limits.

Source§

impl<D: Dimension> Tensor<D>

Source

pub fn index_of(index: &[usize]) -> usize

Gets the index of a specific element to Self::inner.

Source§

impl<D: Dimension> Tensor<D>

Source

pub fn new_filled(value: f32) -> Self

Create a new Tensor with values filled from value.

Source

pub fn map_each<F: Fn(f32) -> f32>(self, f: F) -> Self

Source

pub fn map_zip_ref<F: Fn(f32, f32) -> f32>(self, r: &Self, f: F) -> Self

Source

pub fn map_each_in_place<F: Fn(f32) -> f32>(&mut self, f: F)

Source

pub fn map_zip_ref_in_place<F: Fn(f32, f32) -> f32>(&mut self, r: &Self, f: F)

Source

pub fn reshape<E>(self) -> Tensor<E>
where E: SameSized<D> + Dimension,

Source§

impl<D: Dimension> Tensor<D>

Source

pub fn hadamard_product(self, rhs: &Self) -> Self

Computes the Hadamard product (aka. element-wise multiplication)

Source

pub fn dot(&self, b: &Self) -> f32

Computes the inner product of the given tensors.

Source§

impl<D: VectorDim> Tensor<D>

Source

pub fn x(&self) -> f32

Get the 1st component.

Source

pub fn y(&self) -> f32

Get the 2nd component.

Source

pub fn z(&self) -> f32

Get the 3rd component.

Source

pub fn w(&self) -> f32

Get the 4th component.

Source

pub fn x_ref(&self) -> &f32

Get the 1st component by reference.

Source

pub fn y_ref(&self) -> &f32

Get the 2nd component by reference.

Source

pub fn z_ref(&self) -> &f32

Get the 3rd component by reference.

Source

pub fn w_ref(&self) -> &f32

Get the 4th component by reference.

Source

pub fn x_mut(&mut self) -> &mut f32

Get the 1st component by a mutable reference.

Source

pub fn y_mut(&mut self) -> &mut f32

Get the 2nd component by a mutable reference.

Source

pub fn z_mut(&mut self) -> &mut f32

Get the 3rd component by a mutable reference.

Source

pub fn w_mut(&mut self) -> &mut f32

Get the 4th component by a mutable reference.

Source

pub fn length(&self) -> f32

Computes the length from self to [0, …].

Source

pub fn length_squared(&self) -> f32

Computes the squared length from self to [0, …].

Source

pub fn unit(self) -> Self

Computes the normalized vector of self where Self::length is ≈1.

Source§

impl<D: VectorDim3> Tensor<D>

Source

pub fn cross(&self, b: &Self) -> Self

Computes the cross product between 2 vectors of length 3.

Source§

impl<const X: usize, const Y: usize, const Z: usize, const W: usize> Tensor<Dim5<X, Y, Z, W, 1>>
where Dim4<X, Y, Z, W>: SameSized<Dim5<X, Y, Z, W, 1>>, Dim5<X, Y, Z, W, 1>: Dimension<ArrayForm = [f32; { _ }]>,

Source

pub fn down_conv(self) -> Tensor<Dim4<X, Y, Z, W>>

Convert a tensor down an order if its last dimension is 1.

§Example
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use smolmatrix::*;

let a = hvector!(1 [1.2]).down_conv();
assert_eq!(a, Scalar { inner: [1.2] });
Source§

impl<const X: usize, const Y: usize, const Z: usize, const W: usize, const V: usize> Tensor<Dim5<X, Y, Z, W, V>>
where Dim6<X, Y, Z, W, V, 1>: Dimension<ArrayForm = [f32; { _ }]> + SameSized<Dim5<X, Y, Z, W, V>>,

Source

pub fn up_conv(self) -> Tensor<Dim6<X, Y, Z, W, V, 1>>

Convert a tensor up an order.

§Example
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use smolmatrix::*;

let a = Scalar::new_filled(1.2).up_conv();
assert_eq!(a, HVector { inner: [1.2] });
Source

pub fn join<const N: usize>(list: [&Self; N]) -> Tensor<Dim6<X, Y, Z, W, V, N>>
where [f32; { _ }]: Sized,

Join multiple tensors into a tensor with an order higher by copying each element.

§Example
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use smolmatrix::*;

let a = HVector::join([
    &hvector!(3 [1.0, 2.0, 3.0]),
    &hvector!(3 [4.0, 5.0, 6.0]),
    &hvector!(3 [7.0, 8.0, 9.0]),
]);
assert_eq!(a, matrix!(3 x 3
    [1.0, 2.0, 3.0]
    [4.0, 5.0, 6.0]
    [7.0, 8.0, 9.0]
));

Trait Implementations

Source§

impl<D: Dimension> Add<&Tensor<D>> for Tensor<D>

Source§

type Output = Tensor<D>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<D: Dimension> Add<f32> for Tensor<D>

Source§

type Output = Tensor<D>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<D: Dimension> AddAssign<&Tensor<D>> for Tensor<D>

Source§

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

Performs the += operation. Read more
Source§

impl<D: Dimension> AddAssign<f32> for Tensor<D>

Source§

fn add_assign(&mut self, rhs: f32)

Performs the += operation. Read more
Source§

impl<D: Dimension> AsMut<<D as Dimension>::ArrayForm> for Tensor<D>

Source§

fn as_mut(&mut self) -> &mut D::ArrayForm

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<D: Dimension> AsRef<<D as Dimension>::ArrayForm> for Tensor<D>

Source§

fn as_ref(&self) -> &D::ArrayForm

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<D: Clone + Dimension> Clone for Tensor<D>
where D::ArrayForm: Clone,

Source§

fn clone(&self) -> Tensor<D>

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<D: Debug + Dimension> Debug for Tensor<D>
where D::ArrayForm: Debug,

Source§

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

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

impl<D: Dimension> Deref for Tensor<D>

Source§

type Target = <D as Dimension>::ArrayForm

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<D: Dimension> DerefMut for Tensor<D>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<D: Dimension> Div<&Tensor<D>> for Tensor<D>

Source§

type Output = Tensor<D>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<D: Dimension> Div<f32> for Tensor<D>

Source§

type Output = Tensor<D>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<D: Dimension> DivAssign<&Tensor<D>> for Tensor<D>

Source§

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

Performs the /= operation. Read more
Source§

impl<D: Dimension> DivAssign<f32> for Tensor<D>

Source§

fn div_assign(&mut self, rhs: f32)

Performs the /= operation. Read more
Source§

impl<const X: usize, const Y: usize, const Z: usize, const W: usize> From<Tensor<Dim4<X, Y, Z, W>>> for Tensor<Dim5<X, Y, Z, W, 1>>
where Dim5<X, Y, Z, W, 1>: Dimension<ArrayForm = [f32; { _ }]> + SameSized<Dim4<X, Y, Z, W>>,

Source§

fn from(value: Tensor<Dim4<X, Y, Z, W>>) -> Self

Converts to this type from the input type.
Source§

impl<const X: usize, const Y: usize, const Z: usize, const W: usize, const V: usize> From<Tensor<Dim6<X, Y, Z, W, V, 1>>> for Tensor<Dim5<X, Y, Z, W, V>>
where Dim5<X, Y, Z, W, V>: SameSized<Dim6<X, Y, Z, W, V, 1>>, Dim6<X, Y, Z, W, V, 1>: Dimension<ArrayForm = [f32; { _ }]>,

Source§

fn from(value: Tensor<Dim6<X, Y, Z, W, V, 1>>) -> Self

Converts to this type from the input type.
Source§

impl<D: Dimension> FromIterator<f32> for Tensor<D>

Source§

fn from_iter<T: IntoIterator<Item = f32>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<const X: usize, const Y: usize, const Z: usize, const W: usize, const V: usize> Index<[usize; 5]> for Tensor<Dim5<X, Y, Z, W, V>>
where [f32; { _ }]: Sized,

Source§

type Output = f32

The returned type after indexing.
Source§

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

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

impl<D: VectorDim> Index<usize> for Tensor<D>

Source§

type Output = f32

The returned type after indexing.
Source§

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

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

impl<const X: usize, const Y: usize, const Z: usize, const W: usize, const V: usize> IndexMut<[usize; 5]> for Tensor<Dim5<X, Y, Z, W, V>>
where [f32; { _ }]: Sized,

Source§

fn index_mut(&mut self, index: [usize; 5]) -> &mut Self::Output

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

impl<D: VectorDim> IndexMut<usize> for Tensor<D>

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

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

impl<D: Dimension> Mul<f32> for Tensor<D>

Source§

type Output = Tensor<D>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl<D: Dimension> MulAssign<f32> for Tensor<D>

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl<D: Dimension> Neg for Tensor<D>

Source§

type Output = Tensor<D>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<D: PartialEq + Dimension> PartialEq for Tensor<D>
where D::ArrayForm: PartialEq,

Source§

fn eq(&self, other: &Tensor<D>) -> 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<D: Dimension> Sub<&Tensor<D>> for Tensor<D>

Source§

type Output = Tensor<D>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<D: Dimension> Sub<f32> for Tensor<D>

Source§

type Output = Tensor<D>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<D: Dimension> SubAssign<&Tensor<D>> for Tensor<D>

Source§

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

Performs the -= operation. Read more
Source§

impl<D: Dimension> SubAssign<f32> for Tensor<D>

Source§

fn sub_assign(&mut self, rhs: f32)

Performs the -= operation. Read more
Source§

impl<D: Dimension, E: Dimension + SameSized<D>> SameSized<Tensor<E>> for Tensor<D>

Source§

impl<D: Dimension> StructuralPartialEq for Tensor<D>