Expand description
A statically allocated MxN matrix. The struct is used in the vector (hyper) dual numbers and provides utilities for the calculation of Jacobians.
Implementations
sourceimpl<T: One + Zero + Copy + AddAssign, F, const M: usize, const N: usize> StaticMat<T, 1_usize, N>
impl<T: One + Zero + Copy + AddAssign, F, const M: usize, const N: usize> StaticMat<T, 1_usize, N>
sourcepub fn jacobian(&self) -> StaticMat<T, M, N>
pub fn jacobian(&self) -> StaticMat<T, M, N>
Extract the Jacobian from a vector of Dual numbers.
let xy = StaticVec::new_vec([5.0, 3.0]).map(DualVec64::<2>::from).derive();
let j = StaticVec::new_vec([xy[0] * xy[1].powi(3), xy[0].powi(2) * xy[1]]).jacobian();
assert_eq!(j[(0,0)], 27.0); // y³
assert_eq!(j[(0,1)], 135.0); // 3xy²
assert_eq!(j[(1,0)], 30.0); // 2xy
assert_eq!(j[(1,1)], 25.0); // x²
sourceimpl<T: One, F, const N: usize> StaticMat<T, 1_usize, N>
impl<T: One, F, const N: usize> StaticMat<T, 1_usize, N>
sourcepub fn derive(self) -> Self
pub fn derive(self) -> Self
Derive a vector of second order dual numbers.
let v = StaticVec::new_vec([4.0, 3.0]).map(Dual2Vec64::<2>::from_re).derive();
let n = (v[0].powi(2) + v[1].powi(2)).sqrt();
assert_eq!(n.re, 5.0);
assert_relative_eq!(n.v1[0], 0.8);
assert_relative_eq!(n.v1[1], 0.6);
assert_relative_eq!(n.v2[(0,0)], 0.072);
assert_relative_eq!(n.v2[(0,1)], -0.096);
assert_relative_eq!(n.v2[(1,0)], -0.096);
assert_relative_eq!(n.v2[(1,1)], 0.128);
sourceimpl<T: One, F, const M: usize, const N: usize> StaticMat<T, 1_usize, N>
impl<T: One, F, const M: usize, const N: usize> StaticMat<T, 1_usize, N>
sourcepub fn derive2(self) -> Self
pub fn derive2(self) -> Self
Derive a vector of hyper dual numbers w.r.t. to the second set of variables.
let x = HyperDualVec64::<1, 2>::from_re(2.0).derive1();
let v = StaticVec::new_vec([2.0, 3.0]).map(HyperDualVec64::<1, 2>::from_re).derive2();
let n = (x.powi(2)*v[0].powi(2) + v[1].powi(2)).sqrt();
assert_eq!(n.re, 5.0);
assert_relative_eq!(n.eps1[0], 1.6);
assert_relative_eq!(n.eps2[0], 1.6);
assert_relative_eq!(n.eps2[1], 0.6);
assert_relative_eq!(n.eps1eps2[(0,0)], 1.088);
assert_relative_eq!(n.eps1eps2[(0,1)], -0.192);
sourceimpl<T: Copy, const M: usize, const N: usize> StaticMat<T, M, N>
impl<T: Copy, const M: usize, const N: usize> StaticMat<T, M, N>
sourcepub fn map<B, F>(&self, f: F) -> StaticMat<B, M, N> where
B: Copy + Zero,
F: Fn(T) -> B,
pub fn map<B, F>(&self, f: F) -> StaticMat<B, M, N> where
B: Copy + Zero,
F: Fn(T) -> B,
Apply a function elementwise to all elements of the matrix and return a new matrix with the results.
sourcepub fn map_zip<B, C, F>(
&self,
other: &StaticMat<B, M, N>,
f: F
) -> StaticMat<C, M, N> where
B: Copy,
C: Copy + Zero,
F: Fn(T, B) -> C,
pub fn map_zip<B, C, F>(
&self,
other: &StaticMat<B, M, N>,
f: F
) -> StaticMat<C, M, N> where
B: Copy,
C: Copy + Zero,
F: Fn(T, B) -> C,
Apply a function elementwise to all elements of the matrix and a second matrix. Return a new matrix with the results.
sourcepub fn matmul<B: Copy, C, const O: usize>(
&self,
other: &StaticMat<B, N, O>
) -> StaticMat<C, M, O> where
C: Copy + Zero + AddAssign,
T: Mul<B, Output = C>,
pub fn matmul<B: Copy, C, const O: usize>(
&self,
other: &StaticMat<B, N, O>
) -> StaticMat<C, M, O> where
C: Copy + Zero + AddAssign,
T: Mul<B, Output = C>,
Perform a matrix-matrix multiplication.
use num_dual::StaticMat;
let a = StaticMat::new([[1, 2], [3, 4]]);
let b = StaticMat::new([[2, 1], [4, 3]]);
let x = a.matmul(&b);
assert_eq!(x[(0,0)], 10);
assert_eq!(x[(0,1)], 7);
assert_eq!(x[(1,0)], 22);
assert_eq!(x[(1,1)], 15);
sourcepub fn transpose_matmul<B: Copy, C, const O: usize>(
&self,
other: &StaticMat<B, M, O>
) -> StaticMat<C, N, O> where
C: Copy + Zero + AddAssign,
T: Mul<B, Output = C>,
pub fn transpose_matmul<B: Copy, C, const O: usize>(
&self,
other: &StaticMat<B, M, O>
) -> StaticMat<C, N, O> where
C: Copy + Zero + AddAssign,
T: Mul<B, Output = C>,
Perform a matrix-matrix multiplication in which the first matrix is transposed.
use num_dual::StaticVec;
let a = StaticVec::new_vec([1, 2]);
let b = StaticVec::new_vec([2, 1]);
let x = a.transpose_matmul(&b);
assert_eq!(x[(0,0)], 2);
assert_eq!(x[(0,1)], 1);
assert_eq!(x[(1,0)], 4);
assert_eq!(x[(1,1)], 2);
sourcepub fn matmul_transpose<B: Copy, C, const O: usize>(
&self,
other: &StaticMat<B, O, N>
) -> StaticMat<C, M, O> where
C: Copy + Zero + AddAssign,
T: Mul<B, Output = C>,
pub fn matmul_transpose<B: Copy, C, const O: usize>(
&self,
other: &StaticMat<B, O, N>
) -> StaticMat<C, M, O> where
C: Copy + Zero + AddAssign,
T: Mul<B, Output = C>,
Perform a matrix-matrix multiplication in which the second matrix is transposed.
use num_dual::{StaticMat, StaticVec};
let a = StaticMat::new([[1, 2], [3, 4]]);
let b = StaticVec::new_vec([2, 1]);
let x = a.matmul_transpose(&b);
assert_eq!(x[(0, 0)], 4);
assert_eq!(x[(1, 0)], 10);
sourceimpl<T: Copy + Zero, const N: usize> StaticMat<T, 1_usize, N>
impl<T: Copy + Zero, const N: usize> StaticMat<T, 1_usize, N>
Trait Implementations
sourceimpl<T: Copy + AddAssign, const M: usize, const N: usize> Add<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + AddAssign, const M: usize, const N: usize> Add<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourceimpl<T: Copy + AddAssign, const M: usize, const N: usize> AddAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + AddAssign, const M: usize, const N: usize> AddAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourcefn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the +=
operation. Read more
sourceimpl<T: Copy + AddAssign, const M: usize, const N: usize> AddAssign<T> for StaticMat<T, M, N>
impl<T: Copy + AddAssign, const M: usize, const N: usize> AddAssign<T> for StaticMat<T, M, N>
sourcefn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
Performs the +=
operation. Read more
sourceimpl<T: Copy + DivAssign, const M: usize, const N: usize> Div<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + DivAssign, const M: usize, const N: usize> Div<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourceimpl<T: Copy + DivAssign, const M: usize, const N: usize> DivAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + DivAssign, const M: usize, const N: usize> DivAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourcefn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
Performs the /=
operation. Read more
sourceimpl<T: Copy + DivAssign, const M: usize, const N: usize> DivAssign<T> for StaticMat<T, M, N>
impl<T: Copy + DivAssign, const M: usize, const N: usize> DivAssign<T> for StaticMat<T, M, N>
sourcefn div_assign(&mut self, other: T)
fn div_assign(&mut self, other: T)
Performs the /=
operation. Read more
sourceimpl<T: Copy + MulAssign, const M: usize, const N: usize> Mul<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + MulAssign, const M: usize, const N: usize> Mul<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourceimpl<T: Copy + MulAssign, const M: usize, const N: usize> MulAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + MulAssign, const M: usize, const N: usize> MulAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourcefn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs the *=
operation. Read more
sourceimpl<T: Copy + MulAssign, const M: usize, const N: usize> MulAssign<T> for StaticMat<T, M, N>
impl<T: Copy + MulAssign, const M: usize, const N: usize> MulAssign<T> for StaticMat<T, M, N>
sourcefn mul_assign(&mut self, other: T)
fn mul_assign(&mut self, other: T)
Performs the *=
operation. Read more
sourceimpl<T: PartialEq, const M: usize, const N: usize> PartialEq<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: PartialEq, const M: usize, const N: usize> PartialEq<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourceimpl<T: Copy + RemAssign, const M: usize, const N: usize> Rem<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + RemAssign, const M: usize, const N: usize> Rem<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourceimpl<T: Copy + RemAssign, const M: usize, const N: usize> RemAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + RemAssign, const M: usize, const N: usize> RemAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourcefn rem_assign(&mut self, other: Self)
fn rem_assign(&mut self, other: Self)
Performs the %=
operation. Read more
sourceimpl<T: Copy + RemAssign, const M: usize, const N: usize> RemAssign<T> for StaticMat<T, M, N>
impl<T: Copy + RemAssign, const M: usize, const N: usize> RemAssign<T> for StaticMat<T, M, N>
sourcefn rem_assign(&mut self, other: T)
fn rem_assign(&mut self, other: T)
Performs the %=
operation. Read more
sourceimpl<T: Copy + SubAssign, const M: usize, const N: usize> Sub<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + SubAssign, const M: usize, const N: usize> Sub<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourceimpl<T: Copy + SubAssign, const M: usize, const N: usize> SubAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
impl<T: Copy + SubAssign, const M: usize, const N: usize> SubAssign<StaticMat<T, M, N>> for StaticMat<T, M, N>
sourcefn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the -=
operation. Read more
sourceimpl<T: Copy + SubAssign, const M: usize, const N: usize> SubAssign<T> for StaticMat<T, M, N>
impl<T: Copy + SubAssign, const M: usize, const N: usize> SubAssign<T> for StaticMat<T, M, N>
sourcefn sub_assign(&mut self, other: T)
fn sub_assign(&mut self, other: T)
Performs the -=
operation. Read more
impl<T: Copy, const M: usize, const N: usize> Copy for StaticMat<T, M, N>
impl<T, const M: usize, const N: usize> StructuralPartialEq for StaticMat<T, M, N>
Auto Trait Implementations
impl<T, const M: usize, const N: usize> RefUnwindSafe for StaticMat<T, M, N> where
T: RefUnwindSafe,
impl<T, const M: usize, const N: usize> Send for StaticMat<T, M, N> where
T: Send,
impl<T, const M: usize, const N: usize> Sync for StaticMat<T, M, N> where
T: Sync,
impl<T, const M: usize, const N: usize> Unpin for StaticMat<T, M, N> where
T: Unpin,
impl<T, const M: usize, const N: usize> UnwindSafe for StaticMat<T, M, N> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more