pub struct ADFn<F> { /* private fields */ }Expand description
Generic AD function wrapper.
Lifts a function F: Fn(Jet<2>) -> Jet<2> to operate at multiple levels:
call_stable(f64)→f64: evaluate function value, first derivative, or second derivativecall_stable(Jet<2>)→Jet<2>: pass through
For vector functions, also lifts F: Fn(Vec<Jet<1>>) -> Vec<Jet<1>>.
§Examples
use peroxide::fuga::*;
let f_ad = ADFn::new(|x: Jet<2>| x.powi(2));
// Value: f(3) = 9
assert_eq!(f_ad.call_stable(3.0), 9.0);
// Gradient: f'(3) = 6 (2*3)
let df = f_ad.grad();
assert_eq!(df.call_stable(3.0), 6.0);
// Hessian: f''(3) = 2
let ddf = df.grad();
assert_eq!(ddf.call_stable(3.0), 2.0);Implementations§
Trait Implementations§
Source§impl<'a, F: Fn(&Vec<Jet<1>>) -> Vec<Jet<1>>> StableFn<&'a Vec<Jet<1>>> for ADFn<F>
Vector version: F works with &Vec<Jet<1>>, target is &Vec<Jet<1>>.
impl<'a, F: Fn(&Vec<Jet<1>>) -> Vec<Jet<1>>> StableFn<&'a Vec<Jet<1>>> for ADFn<F>
Vector version: F works with &Vec<Jet<1>>, target is &Vec<Jet<1>>.
Source§impl<'a, F: Fn(&Vec<Jet<1>>) -> Vec<Jet<1>>> StableFn<&'a Vec<f64>> for ADFn<F>
Vector version: F works with &Vec<Jet<1>>, target is &Vec<f64>.
impl<'a, F: Fn(&Vec<Jet<1>>) -> Vec<Jet<1>>> StableFn<&'a Vec<f64>> for ADFn<F>
Vector version: F works with &Vec<Jet<1>>, target is &Vec<f64>.
Source§impl<F: Fn(Jet<2>) -> Jet<2>> StableFn<Jet<2>> for ADFn<F>
Scalar version: F works with Jet<2>, target is Jet<2>.
impl<F: Fn(Jet<2>) -> Jet<2>> StableFn<Jet<2>> for ADFn<F>
Scalar version: F works with Jet<2>, target is Jet<2>.
Source§impl<F: Fn(Vec<Jet<1>>) -> Vec<Jet<1>>> StableFn<Vec<Jet<1>>> for ADFn<F>
Vector version: F works with Vec<Jet<1>>, target is Vec<Jet<1>>.
impl<F: Fn(Vec<Jet<1>>) -> Vec<Jet<1>>> StableFn<Vec<Jet<1>>> for ADFn<F>
Vector version: F works with Vec<Jet<1>>, target is Vec<Jet<1>>.
Auto Trait Implementations§
impl<F> Freeze for ADFn<F>
impl<F> RefUnwindSafe for ADFn<F>where
F: RefUnwindSafe,
impl<F> Send for ADFn<F>where
F: Send,
impl<F> Sync for ADFn<F>where
F: Sync,
impl<F> Unpin for ADFn<F>
impl<F> UnwindSafe for ADFn<F>where
F: UnwindSafe,
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