Struct Tensor

Source
pub struct Tensor<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize>
where [(); { _ }]:,
{ pub data: [E; { _ }], pub _phantom: PhantomData<D>, }

Fields§

§data: [E; { _ }]§_phantom: PhantomData<D>

Implementations§

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn new<U: Unit<Dimension = D>>(values: [E; { _ }]) -> Self

Source

pub fn zero() -> Self

Source

pub fn random<U: Unit<Dimension = D>>(min: E, max: E) -> Self

Source

pub fn get<S: Unit<Dimension = D>>(&self) -> [E; { _ }]

Source

pub fn get_at(&self, layer: usize, row: usize, col: usize) -> Scalar<E, D>

Source

pub fn set_at( &mut self, layer: usize, row: usize, col: usize, value: Scalar<E, D>, )

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn dtype(&self) -> &'static str

Source

pub fn cast<T>(&self) -> Tensor<T, D, LAYERS, ROWS, COLS>
where T: TensorElement,

Source§

impl<E: TensorElement, D> Tensor<E, D, 1, 2, 1>

Source

pub fn raw_tuple(&self) -> (E, E)
where E: TensorElement,

Source

pub fn raw_tuple_as<T: From<E>>(&self) -> (T, T)
where E: TensorElement,

Source§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:, E: TensorElement,

Source

pub fn raw_vec(&self) -> Vec<E>

Source

pub fn raw_vec_as<T: From<E>>(&self) -> Vec<T>

Source§

impl<E, D> Tensor<E, D, 1, 2, 1>
where E: TensorElement,

Source

pub fn x(&self) -> Scalar<E, D>

Source

pub fn y(&self) -> Scalar<E, D>

Source§

impl<E, D> Tensor<E, D, 1, 3, 1>
where E: TensorElement,

Source

pub fn x(&self) -> Scalar<E, D>

Source

pub fn y(&self) -> Scalar<E, D>

Source

pub fn z(&self) -> Scalar<E, D>

Source§

impl<E: TensorElement + Mul<Output = E> + Add<Output = E> + Copy, const LAYERS: usize, const L1: i32, const M1: i32, const T1: i32, const Θ1: i32, const I1: i32, const N1: i32, const J1: i32, const ROWS: usize, const COMMON: usize> Tensor<E, Dimension<L1, M1, T1, Θ1, I1, N1, J1>, LAYERS, ROWS, COMMON>
where [(); { _ }]:,

Source

pub fn matmul<const L2: i32, const M2: i32, const T2: i32, const Θ2: i32, const I2: i32, const N2: i32, const J2: i32, const COLS: usize>( self, other: Tensor<E, Dimension<L2, M2, T2, Θ2, I2, N2, J2>, LAYERS, COMMON, COLS>, ) -> Tensor<E, <Dimension<L1, M1, T1, Θ1, I1, N1, J1> as MultiplyDimensions<Dimension<L2, M2, T2, Θ2, I2, N2, J2>>>::Output, LAYERS, ROWS, COLS>
where Dimension<L1, M1, T1, Θ1, I1, N1, J1>: MultiplyDimensions<Dimension<L2, M2, T2, Θ2, I2, N2, J2>>, [(); { _ }]:, [(); COLS]:,

Performs matrix multiplication between two tensors.

Source§

impl<E: TensorElement + Mul<Output = E> + Copy, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn scale<DS>( self, scalar: Tensor<E, DS, 1, 1, 1>, ) -> Tensor<E, <D as MultiplyDimensions<DS>>::Output, LAYERS, ROWS, COLS>
where D: MultiplyDimensions<DS>, <D as MultiplyDimensions<DS>>::Output:,

Multiplies every element of the tensor by a scalar.

Source§

impl<E: TensorElement + Div<Output = E> + Copy + PartialEq, D> Tensor<E, D, 1, 1, 1>
where [(); 1]:,

Source

pub fn inv(self) -> Tensor<E, <D as InvertDimension>::Output, 1, 1, 1>
where D: InvertDimension,

Source§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where E: TensorElement + Into<c64> + Copy, [(); { _ }]:,

Source

pub fn to_c64(&self) -> Tensor<c64, D, LAYERS, ROWS, COLS>

Converts the tensor to one with c64 elements by mapping each element via Into.

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn conjugate(self) -> Self

Source

pub fn conjugate_transpose(self) -> Tensor<E, D, LAYERS, COLS, ROWS>
where [(); { _ }]:,

Returns the conjugate transpose of this tensor.

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn transpose(self) -> Tensor<E, D, LAYERS, COLS, ROWS>
where [(); { _ }]:,

Returns the transpose of this tensor.

Source§

impl<E: TensorElement + Into<f64> + Copy, const L: i32, const M: i32, const T: i32, const Θ: i32, const I: i32, const N: i32, const J: i32, const ROWS: usize> Tensor<E, Dimension<L, M, T, Θ, I, N, J>, 1, ROWS, 1>
where [(); { _ }]:,

Source

pub fn norm(self) -> Tensor<f64, Dimension<L, M, T, Θ, I, N, J>, 1, 1, 1>
where [(); { _ }]:,

Source

pub fn dist( self, other: Self, ) -> Tensor<f64, Dimension<L, M, T, Θ, I, N, J>, 1, 1, 1>
where [(); { _ }]:,

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn size(&self) -> usize

Returns the number of elements in the tensor.

Source

pub fn shape(&self) -> (usize, usize, usize)

Source

pub fn layers(&self) -> usize

Returns the number of layers in the tensor.

Source

pub fn rows(&self) -> usize

Returns the number of rows in the tensor.

Source

pub fn cols(&self) -> usize

Returns the number of columns in the tensor.

Source

pub fn data(&self) -> &[E]

Returns the data as a slice.

Source

pub fn reshape<const L: usize, const R: usize, const C: usize>( &self, ) -> Tensor<E, D, L, R, C>
where [(); { _ }]:,

Source

pub fn flatten(&self) -> Tensor<E, D, 1, 1, { _ }>
where [(); { _ }]:,

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn and(self, other: Self) -> Self

Source§

impl<E: TensorElement + PartialEq + Copy, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn or(self, other: Self) -> Self

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn eq(self, other: Self) -> Self

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn ne(self, other: Self) -> Self

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn gt(self, other: Self) -> Self

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source

pub fn ge(self, other: Self) -> Self

Source§

impl<E: TensorElement, D> Tensor<E, D, 1, 1, 1>

Source

pub const EPSILON: Scalar<E, D>

Source

pub fn from<U: Unit<Dimension = D>>(value: E) -> Self

Source

pub fn raw(&self) -> E

Source

pub fn raw_as<T: From<E>>(&self) -> T

Source

pub fn mag(&self) -> Scalar<f64, D>

Source§

impl<E: TensorElement, D> Tensor<E, D, 1, 1, 1>

Source

pub fn epsilon(&self) -> Self

Source§

impl<const L: usize, const R: usize, const C: usize> Tensor<c64, Dimensionless, L, R, C>
where [(); { _ }]:,

Source

pub fn nat(values: [c64; { _ }]) -> Self

Source

pub fn randnat(min: c64, max: c64) -> Self

Source§

impl Tensor<c64, Dimensionless, 1, 1, 1>

Source

pub fn item(&self) -> c64

Trait Implementations§

Source§

impl<E: TensorElement + Add<Output = E> + Copy, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Add for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source§

type Output = Tensor<E, D, LAYERS, ROWS, COLS>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> AddAssign for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:, E: TensorElement + AddAssign,

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<E: Clone + TensorElement, D: Clone, const LAYERS: usize, const ROWS: usize, const COLS: usize> Clone for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source§

fn clone(&self) -> Tensor<E, D, LAYERS, ROWS, COLS>

Returns a copy 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<E: TensorElement, D: Debug + Default, const LAYERS: usize, const ROWS: usize, const COLS: usize> Debug for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source§

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

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

impl<E: TensorElement, D: Display + Default, const LAYERS: usize, const ROWS: usize, const COLS: usize> Display for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source§

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

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

impl<E, D, DS, const LAYERS: usize, const ROWS: usize, const COLS: usize> Div<Tensor<E, DS, 1, 1, 1>> for Tensor<E, D, LAYERS, ROWS, COLS>
where E: TensorElement + Div<Output = E> + Copy, DS: InvertDimension, D: MultiplyDimensions<<DS as InvertDimension>::Output>, [(); { _ }]:,

Source§

type Output = Tensor<E, <D as MultiplyDimensions<<DS as InvertDimension>::Output>>::Output, LAYERS, ROWS, COLS>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Tensor<E, DS, 1, 1, 1>) -> Self::Output

Performs the / operation. Read more
Source§

impl<E, D, DS, const LAYERS: usize, const ROWS: usize, const COLS: usize> Mul<Tensor<E, DS, 1, 1, 1>> for Tensor<E, D, LAYERS, ROWS, COLS>
where E: TensorElement + Mul<Output = E> + Copy, D: MultiplyDimensions<DS>, [(); { _ }]:,

Source§

type Output = Tensor<E, <D as MultiplyDimensions<DS>>::Output, LAYERS, ROWS, COLS>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Tensor<E, DS, 1, 1, 1>) -> Self::Output

Performs the * operation. Read more
Source§

impl<E: TensorElement + Neg<Output = E> + Copy, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Neg for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source§

type Output = Tensor<E, D, LAYERS, ROWS, COLS>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> PartialEq for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source§

fn eq(&self, other: &Self) -> 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<E: TensorElement, D> PartialOrd for Tensor<E, D, 1, 1, 1>
where [(); 1]:,

Source§

fn partial_cmp(&self, other: &Self) -> 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<E: TensorElement + Sub<Output = E> + Copy, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Sub for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source§

type Output = Tensor<E, D, LAYERS, ROWS, COLS>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<E: Copy + TensorElement, D: Copy, const LAYERS: usize, const ROWS: usize, const COLS: usize> Copy for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:,

Source§

impl<E: TensorElement, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Eq for Tensor<E, D, LAYERS, ROWS, COLS>
where [(); { _ }]:, c64: Eq,

Auto Trait Implementations§

§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Freeze for Tensor<E, D, LAYERS, ROWS, COLS>
where E: Freeze,

§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> RefUnwindSafe for Tensor<E, D, LAYERS, ROWS, COLS>

§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Send for Tensor<E, D, LAYERS, ROWS, COLS>
where E: Send, D: Send,

§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Sync for Tensor<E, D, LAYERS, ROWS, COLS>
where E: Sync, D: Sync,

§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> Unpin for Tensor<E, D, LAYERS, ROWS, COLS>
where E: Unpin, D: Unpin,

§

impl<E, D, const LAYERS: usize, const ROWS: usize, const COLS: usize> UnwindSafe for Tensor<E, D, LAYERS, ROWS, COLS>
where E: UnwindSafe, D: UnwindSafe,

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V