pub struct ADFn<F> { /* private fields */ }
Expand description
Generic AD functions
§Description
To lift AD
functions
§Implementation
- All
Fn(AD) -> AD
functions can be lift toFn(f64) -> f64
viaStableFn<f64>
grad(&self) -> Self
gives gradient of original function- But still can use
Fn(AD) -> AD
viaStableFn<AD>
§Usage
extern crate peroxide;
use peroxide::fuga::*;
fn main() {
let ad0 = 2f64;
let ad1 = AD1(2f64, 1f64);
let ad2 = AD2(2f64, 1f64, 0f64);
let f_ad = ADFn::new(f);
let ans0 = ad0.powi(2);
let ans1 = ad1.powi(2).dx();
let ans2 = ad2.powi(2).ddx();
assert_eq!(ans0, f_ad.call_stable(ad0));
let df = f_ad.grad();
assert_eq!(ans1, df.call_stable(ad0));
let ddf = df.grad();
assert_eq!(ans2, ddf.call_stable(ad0));
let ad1_output = f_ad.call_stable(ad1);
assert_eq!(ad1_output, AD1(4f64, 4f64));
let ad2_output = f_ad.call_stable(ad2);
assert_eq!(ad2_output, AD2(4f64, 4f64, 2f64));
}
fn f(x: AD) -> AD {
x.powi(2)
}
Implementations§
Trait Implementations§
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