pub struct Expr { /* private fields */ }
Expand description
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
Trait Implementations
sourceimpl Add<Expr> for ExprDynSum
impl Add<Expr> for ExprDynSum
sourceimpl Add<Vec<ExprDyn, Global>> for Expr
impl Add<Vec<ExprDyn, Global>> for Expr
sourcefn add(self, other: ExprDynSum) -> ExprDynSum
fn add(self, other: ExprDynSum) -> ExprDynSum
Performs the
+
operation. Read moresourceimpl From<Expr> for Expression
impl From<Expr> for Expression
Auto Trait Implementations
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnwindSafe for Expr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more