Struct num_dual::StaticMat

source ·
pub struct StaticMat<T, const M: usize, const N: usize>(_);
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§

Derive a vector of dual numbers.

let v = StaticVec::new_vec([4.0, 3.0]).map(DualVec64::<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.eps[0], 0.8);
assert_relative_eq!(n.eps[1], 0.6);

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 first set of variables.

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);

Create a new StaticMat from an array of arrays.

Return a reference to the raw data in the StaticMat.

Create a new StaticVec from an array.

Return a reference to the raw data in the StaticVec.

Create a NxN unity matrix.

sum over all elements in the vector.

Calculate the Euclidian norm of the vector

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.

Iterate over all matrix elements.

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);

Transpose the matrix.

Return a new vector containing the first M elements of self.

Return a new vector containing the last M elements of self.

Calculate the dot product of two vectors.

use num_dual::StaticVec;
let a = StaticVec::new_vec([1, 2, 3, 4]);
let b = StaticVec::new_vec([2, 1, 4, 3]);
assert_eq!(a.dot(&b), 28);

multiply each matrix element with f in place.

Trait Implementations§

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
Returns the multiplicative identity element of Self, 1. Read more
Sets self to the multiplicative identity element of Self, 1.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Returns the additive identity element of Self, 0. Read more
Returns true if self is equal to the additive identity.
Sets self to the additive identity element of Self, 0.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.