Struct num_dual::StaticMat [−][src]
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
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²
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);
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);
Apply a function elementwise to all elements of the matrix and return a new matrix with the results.
Apply a function elementwise to all elements of the matrix and a second matrix. Return a new matrix with the results.
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);
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);
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);
Return a new vector containing the first M elements of self.
Return a new vector containing the last M elements of self.
Trait Implementations
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Performs the /=
operation. Read more
Performs the /=
operation. Read more
Performs the *=
operation. Read more
Performs the *=
operation. Read more
Performs the %=
operation. Read more
Performs the %=
operation. Read more
Performs the -=
operation. Read more
Performs the -=
operation. Read more
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> UnwindSafe for StaticMat<T, M, N> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more