pub struct GradientOperations;Expand description
Gradient vector operations
Implementations§
Source§impl GradientOperations
impl GradientOperations
Sourcepub fn compute(expr: &Expression, variables: Vec<Symbol>) -> Vec<Expression>
pub fn compute(expr: &Expression, variables: Vec<Symbol>) -> Vec<Expression>
Compute gradient vector
§Examples
use mathhook_core::simplify::Simplify;
use mathhook_core::calculus::derivatives::Derivative;
use mathhook_core::{Expression};
use mathhook_core::symbol;
use mathhook_core::calculus::derivatives::GradientOperations;
let x = symbol!(x);
let y = symbol!(y);
let expr = Expression::add(vec![
Expression::pow(Expression::symbol(x.clone()), Expression::integer(2)),
Expression::pow(Expression::symbol(y.clone()), Expression::integer(2))
]);
let gradient = GradientOperations::compute(&expr, vec![x, y]);Sourcepub fn compute_cached(
expr: &Expression,
variables: &[Symbol],
cache: &mut HashMap<Symbol, Expression>,
) -> Vec<Expression>
pub fn compute_cached( expr: &Expression, variables: &[Symbol], cache: &mut HashMap<Symbol, Expression>, ) -> Vec<Expression>
Compute gradient with caching for repeated computations
§Examples
use mathhook_core::{Expression};
use mathhook_core::symbol;
use mathhook_core::calculus::derivatives::GradientOperations;
use std::collections::HashMap;
let x = symbol!(x);
let y = symbol!(y);
let expr = Expression::mul(vec![
Expression::symbol(x.clone()),
Expression::symbol(y.clone())
]);
let mut cache = HashMap::new();
let gradient = GradientOperations::compute_cached(&expr, &[x, y], &mut cache);Auto Trait Implementations§
impl Freeze for GradientOperations
impl RefUnwindSafe for GradientOperations
impl Send for GradientOperations
impl Sync for GradientOperations
impl Unpin for GradientOperations
impl UnsafeUnpin for GradientOperations
impl UnwindSafe for GradientOperations
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more