Skip to main content

SymMat

Struct SymMat 

Source
pub struct SymMat {
    pub rows: usize,
    pub cols: usize,
    pub data: Vec<E>,
}
Expand description

Symbolic matrix of expressions.

Stored in row-major order. Supports transpose, matrix multiplication, matrix-vector product, element-wise differentiation, and code generation.

Fields§

§rows: usize

Number of rows.

§cols: usize

Number of columns.

§data: Vec<E>

Row-major element data.

Implementations§

Source§

impl SymMat

Source

pub fn new<I>(rows: usize, cols: usize, data: I) -> Self
where I: IntoIterator, I::Item: Into<E>,

Create a matrix from dimensions and row-major data. Accepts any iterable of Into<E> so you can pass bare numeric literals: SymMat::new(2, 2, [1.0, 2.0, 3.0, 4.0]).

Source

pub fn zeros(rows: usize, cols: usize) -> Self

Create a zero matrix of the given dimensions.

Source

pub fn identity(n: usize) -> Self

Create an n-by-n identity matrix.

Source

pub fn get(&self, i: usize, j: usize) -> &E

Get a reference to the element at row i, column j.

Source

pub fn set(&mut self, i: usize, j: usize, val: E)

Set the element at row i, column j.

Source

pub fn transpose(&self) -> SymMat

Return the transpose of this matrix.

Source

pub fn diff(&self, var: impl AsVarName) -> SymMat

Differentiate every element with respect to a variable.

Source

pub fn eval(&self, vars: &HashMap<&str, f64>) -> Result<Vec<Vec<f64>>, String>

Evaluate every element numerically, returning a nested Vec<Vec<f64>>.

Source

pub fn simplify(&self) -> SymMat

Simplify every element.

Source

pub fn expand(&self) -> SymMat

Expand every element (distribute products over sums).

Source

pub fn subs(&self, var: impl AsVarName, replacement: &E) -> SymMat

Substitute a variable in every element.

Source

pub fn to_latex(&self) -> String

Format the matrix as a LaTeX pmatrix.

Source

pub fn to_rust(&self, ft: &str) -> String

Generate Rust source code for the matrix as a nested array literal.

Trait Implementations§

Source§

impl Add for SymMat

Source§

type Output = SymMat

The resulting type after applying the + operator.
Source§

fn add(self, rhs: SymMat) -> SymMat

Performs the + operation. Read more
Source§

impl Clone for SymMat

Source§

fn clone(&self) -> SymMat

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 Debug for SymMat

Source§

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

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

impl Display for SymMat

Source§

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

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

impl Mul<E> for SymMat

Source§

type Output = SymMat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: E) -> SymMat

Performs the * operation. Read more
Source§

impl Mul<SymMat> for E

Source§

type Output = SymMat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SymMat) -> SymMat

Performs the * operation. Read more
Source§

impl Mul<SymVec> for SymMat

Source§

type Output = SymVec

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SymVec) -> SymVec

Performs the * operation. Read more
Source§

impl Mul for SymMat

Source§

type Output = SymMat

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: SymMat) -> SymMat

Performs the * operation. Read more
Source§

impl PartialEq for SymMat

Source§

fn eq(&self, other: &SymMat) -> 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 StructuralPartialEq for SymMat

Auto Trait Implementations§

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.