[][src]Struct descent::expr::dynam::Expr

pub struct Expr { /* fields omitted */ }

An expression that can be dynamically constructed.

Operator overloading is implemented for this struct alongside Var, Par and f64. Once the final expression has been constructed, it can be converted into a ExprDyn, which locks down the final form of the expression, and calculates some additional information about its "sparsity" (which is expensive to do, some only done once).

An Expr shouldn't be directly constructed, instead it is produced by applying a valid operator (+, -, *, powi, sin, cos) to either an existing operator, or to a Var or Par value.

use descent::expr::{Var, Par};
use descent::expr::dynam::NumOps; // required to bring in powi usage
let x = Var(0);
let y = Var(1);
let p = Par(0);

let e = p * x - (5.0 * y.powi(2) + 4.0); // this produces an `Expr`

One exception to this is for convenience, e.g., summing a bunch of terms:

use descent::expr::Var;
use descent::expr::dynam::Expr;
let xs: Vec<Var> = (0..5).into_iter().map(|i| Var(i)).collect();

let mut e = Expr::from(0.0);
for &x in &xs {
    e = e + x;
}

Implementations

impl Expr[src]

pub fn eval<R>(&self, ret: &R, ns: &mut Vec<f64>) -> f64 where
    R: Retrieve
[src]

Value of the expression.

pub fn get_info(&self) -> ExprInfo[src]

Get information about the expression.

pub fn len(&self) -> usize[src]

pub fn is_empty(&self) -> bool[src]

Trait Implementations

impl<'a> Add<&'a Expr> for Var[src]

type Output = Expr

The resulting type after applying the + operator.

impl<'a> Add<&'a Expr> for Par[src]

type Output = Expr

The resulting type after applying the + operator.

impl Add<Expr> for ExprDynSum[src]

type Output = ExprDynSum

The resulting type after applying the + operator.

impl Add<Expr> for Var[src]

type Output = Expr

The resulting type after applying the + operator.

impl Add<Expr> for Par[src]

type Output = Expr

The resulting type after applying the + operator.

impl Add<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the + operator.

impl Add<Par> for Expr[src]

type Output = Expr

The resulting type after applying the + operator.

impl<'a> Add<Par> for &'a Expr[src]

type Output = Expr

The resulting type after applying the + operator.

impl Add<Var> for Expr[src]

type Output = Expr

The resulting type after applying the + operator.

impl<'a> Add<Var> for &'a Expr[src]

type Output = Expr

The resulting type after applying the + operator.

impl Add<Vec<ExprDyn, Global>> for Expr[src]

type Output = ExprDynSum

The resulting type after applying the + operator.

impl Add<f64> for Expr[src]

type Output = Expr

The resulting type after applying the + operator.

impl<'a> Add<f64> for &'a Expr[src]

type Output = Expr

The resulting type after applying the + operator.

impl Clone for Expr[src]

impl Debug for Expr[src]

impl From<Expr> for ExprDyn[src]

impl From<Expr> for Expression[src]

impl From<Par> for Expr[src]

impl From<Var> for Expr[src]

impl From<f64> for Expr[src]

impl From<i32> for Expr[src]

impl<'a> Mul<&'a Expr> for Var[src]

type Output = Expr

The resulting type after applying the * operator.

impl<'a> Mul<&'a Expr> for Par[src]

type Output = Expr

The resulting type after applying the * operator.

impl Mul<Expr> for Var[src]

type Output = Expr

The resulting type after applying the * operator.

impl Mul<Expr> for Par[src]

type Output = Expr

The resulting type after applying the * operator.

impl Mul<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the * operator.

impl Mul<Par> for Expr[src]

type Output = Expr

The resulting type after applying the * operator.

impl<'a> Mul<Par> for &'a Expr[src]

type Output = Expr

The resulting type after applying the * operator.

impl Mul<Var> for Expr[src]

type Output = Expr

The resulting type after applying the * operator.

impl<'a> Mul<Var> for &'a Expr[src]

type Output = Expr

The resulting type after applying the * operator.

impl Mul<f64> for Expr[src]

type Output = Expr

The resulting type after applying the * operator.

impl<'a> Mul<f64> for &'a Expr[src]

type Output = Expr

The resulting type after applying the * operator.

impl NumOps for Expr[src]

impl<'a> Sub<&'a Expr> for Var[src]

type Output = Expr

The resulting type after applying the - operator.

impl<'a> Sub<&'a Expr> for Par[src]

type Output = Expr

The resulting type after applying the - operator.

impl Sub<Expr> for Var[src]

type Output = Expr

The resulting type after applying the - operator.

impl Sub<Expr> for Par[src]

type Output = Expr

The resulting type after applying the - operator.

impl Sub<Expr> for Expr[src]

type Output = Expr

The resulting type after applying the - operator.

impl Sub<Par> for Expr[src]

type Output = Expr

The resulting type after applying the - operator.

impl<'a> Sub<Par> for &'a Expr[src]

type Output = Expr

The resulting type after applying the - operator.

impl Sub<Var> for Expr[src]

type Output = Expr

The resulting type after applying the - operator.

impl<'a> Sub<Var> for &'a Expr[src]

type Output = Expr

The resulting type after applying the - operator.

impl Sub<f64> for Expr[src]

type Output = Expr

The resulting type after applying the - operator.

impl<'a> Sub<f64> for &'a Expr[src]

type Output = Expr

The resulting type after applying the - operator.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.