[][src]Struct peroxide::structure::ad::ADLift

pub struct ADLift<F, T> { /* fields omitted */ }

Lift AD functions

Description

To lift AD functions

Implementation

  • All Fn(T) -> T where T:AD functions can be lift to Fn(f64) -> f64
  • If j > i, then Fn(AD{j}) -> AD{j} can be lift to Fn(AD{i}) -> AD{i}

Usage

extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let ad0 = 2f64;
    let ad1 = AD1::new(2f64, 1f64);
     
    let lift1 = ADLift::<_, AD1>::new(f_ad);
    let lift2 = ADLift::<_, AD2>::new(f_ad2);

    let ans_ad0 = ad0.powi(2);
    let ans_ad1 = ad1.powi(2);

    // All AD function can be lift to f64
    assert_eq!(ans_ad0, lift1.call_stable(ad0));
    assert_eq!(ans_ad0, lift2.call_stable(ad0));

    // AD2 is higher than AD1 (AD2 -> AD1 lifting is allowed)
    assert_eq!(ans_ad1, lift2.call_stable(ad1));
}

fn f_ad<T: AD>(x: T) -> T {
    x.powi(2)
}

fn f_ad2(x: AD2) -> AD2 {
    x.powi(2)
}

Implementations

impl<F: Fn(T) -> T, T> ADLift<F, T>[src]

pub fn new(f: F) -> Self[src]

pub fn f(&self, t: T) -> T[src]

Trait Implementations

impl<F: Fn(T) -> T, T: AD> StableFn<AD1> for ADLift<F, T>[src]

type Output = AD1

impl<F: Fn(AD2) -> AD2> StableFn<AD2> for ADLift<F, AD2>[src]

type Output = AD2

impl<F: Fn(AD3) -> AD3> StableFn<AD2> for ADLift<F, AD3>[src]

type Output = AD2

impl<F: Fn(AD4) -> AD4> StableFn<AD2> for ADLift<F, AD4>[src]

type Output = AD2

impl<F: Fn(AD5) -> AD5> StableFn<AD2> for ADLift<F, AD5>[src]

type Output = AD2

impl<F: Fn(AD3) -> AD3> StableFn<AD3> for ADLift<F, AD3>[src]

type Output = AD3

impl<F: Fn(AD4) -> AD4> StableFn<AD3> for ADLift<F, AD4>[src]

type Output = AD3

impl<F: Fn(AD5) -> AD5> StableFn<AD3> for ADLift<F, AD5>[src]

type Output = AD3

impl<F: Fn(AD4) -> AD4> StableFn<AD4> for ADLift<F, AD4>[src]

type Output = AD4

impl<F: Fn(AD5) -> AD5> StableFn<AD4> for ADLift<F, AD5>[src]

type Output = AD4

impl<F: Fn(AD5) -> AD5> StableFn<AD5> for ADLift<F, AD5>[src]

type Output = AD5

impl<F: Fn(T) -> T, T: AD> StableFn<f64> for ADLift<F, T>[src]

type Output = f64

Auto Trait Implementations

impl<F, T> RefUnwindSafe for ADLift<F, T> where
    F: RefUnwindSafe,
    T: RefUnwindSafe

impl<F, T> Send for ADLift<F, T> where
    F: Send,
    T: Send

impl<F, T> Sync for ADLift<F, T> where
    F: Sync,
    T: Sync

impl<F, T> Unpin for ADLift<F, T> where
    T: Unpin

impl<F, T> UnwindSafe for ADLift<F, T> where
    F: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,