[−][src]Struct descent::expr::dynam::Expr
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]
R: Retrieve,
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.
fn add(self, other: &'a Expr) -> Expr
[src]
impl<'a> Add<&'a Expr> for Par
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: &'a Expr) -> Expr
[src]
impl Add<Expr> for ExprDynSum
[src]
type Output = ExprDynSum
The resulting type after applying the +
operator.
fn add(mut self: Self, other: Expr) -> ExprDynSum
[src]
impl Add<Expr> for Var
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: Expr) -> Expr
[src]
impl Add<Expr> for Par
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: Expr) -> Expr
[src]
impl Add<Expr> for Expr
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(mut self: Self, mut other: Expr) -> Expr
[src]
impl Add<Par> for Expr
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: Par) -> Expr
[src]
impl<'a> Add<Par> for &'a Expr
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: Par) -> Expr
[src]
impl Add<Var> for Expr
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: Var) -> Expr
[src]
impl<'a> Add<Var> for &'a Expr
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: Var) -> Expr
[src]
impl Add<Vec<ExprDyn, Global>> for Expr
[src]
type Output = ExprDynSum
The resulting type after applying the +
operator.
fn add(self, mut other: ExprDynSum) -> ExprDynSum
[src]
impl Add<f64> for Expr
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: f64) -> Expr
[src]
impl<'a> Add<f64> for &'a Expr
[src]
type Output = Expr
The resulting type after applying the +
operator.
fn add(self, other: f64) -> Expr
[src]
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.
fn mul(self, other: &'a Expr) -> Expr
[src]
impl<'a> Mul<&'a Expr> for Par
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: &'a Expr) -> Expr
[src]
impl Mul<Expr> for Var
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: Expr) -> Expr
[src]
impl Mul<Expr> for Par
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: Expr) -> Expr
[src]
impl Mul<Expr> for Expr
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(mut self: Self, other: Expr) -> Expr
[src]
impl Mul<Par> for Expr
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: Par) -> Expr
[src]
impl<'a> Mul<Par> for &'a Expr
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: Par) -> Expr
[src]
impl Mul<Var> for Expr
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: Var) -> Expr
[src]
impl<'a> Mul<Var> for &'a Expr
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: Var) -> Expr
[src]
impl Mul<f64> for Expr
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: f64) -> Expr
[src]
impl<'a> Mul<f64> for &'a Expr
[src]
type Output = Expr
The resulting type after applying the *
operator.
fn mul(self, other: f64) -> Expr
[src]
impl NumOps for Expr
[src]
fn powi(mut self: Self, p: i32) -> Expr
[src]
fn sin(mut self: Self) -> Expr
[src]
fn cos(mut self: Self) -> Expr
[src]
impl<'a> Sub<&'a Expr> for Var
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: &'a Expr) -> Expr
[src]
impl<'a> Sub<&'a Expr> for Par
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: &'a Expr) -> Expr
[src]
impl Sub<Expr> for Var
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: Expr) -> Expr
[src]
impl Sub<Expr> for Par
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: Expr) -> Expr
[src]
impl Sub<Expr> for Expr
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(mut self: Self, mut other: Expr) -> Expr
[src]
impl Sub<Par> for Expr
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: Par) -> Expr
[src]
impl<'a> Sub<Par> for &'a Expr
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: Par) -> Expr
[src]
impl Sub<Var> for Expr
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: Var) -> Expr
[src]
impl<'a> Sub<Var> for &'a Expr
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: Var) -> Expr
[src]
impl Sub<f64> for Expr
[src]
type Output = Expr
The resulting type after applying the -
operator.
fn sub(self, other: f64) -> Expr
[src]
impl<'a> Sub<f64> for &'a Expr
[src]
Auto Trait Implementations
impl RefUnwindSafe for Expr
[src]
impl Send for Expr
[src]
impl Sync for Expr
[src]
impl Unpin for Expr
[src]
impl UnwindSafe for Expr
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,