Skip to main content

ForwardADMulti

Struct ForwardADMulti 

Source
pub struct ForwardADMulti<A: AD + ForwardADTrait> { /* private fields */ }
Expand description

Computes derivatives using Forward-mode Automatic Differentiation (Multi-Tangent).

This method allows for computing multiple columns of the Jacobian in a single pass by propagating a vector of tangents. This can significantly speed up computation by taking advantage of SIMD and reducing function overhead.

Implementations§

Source§

impl<A: AD + ForwardADTrait> ForwardADMulti<A>

Source

pub fn new() -> Self

Examples found in repository?
examples/example1.rs (line 63)
33fn main() {
34    let inputs = vec![1., 2.];
35
36    // Reverse AD //////////////////////////////////////////////////////////////////////////////////
37    let function_standard = Test { coeff: 2.0 };
38    let function_derivative = function_standard.to_other_ad_type::<adr>();
39    let differentiable_block = FunctionEngine::new(function_standard, function_derivative, ReverseAD::new());
40
41    let (f_res, derivative_res) = differentiable_block.derivative(&inputs);
42    println!("Reverse AD: ");
43    println!("  f_res: {}", f_res[0]);
44    println!("  derivative: {}", derivative_res);
45    println!("//////////////");
46    println!();
47
48    // Forward AD //////////////////////////////////////////////////////////////////////////////////
49    let function_standard = Test { coeff: 2.0 };
50    let function_derivative = function_standard.to_other_ad_type::<adfn<1>>();
51    let differentiable_block = FunctionEngine::new(function_standard, function_derivative, ForwardAD::new());
52
53    let (f_res, derivative_res) = differentiable_block.derivative(&inputs);
54    println!("Forward AD: ");
55    println!("  f_res: {}", f_res[0]);
56    println!("  derivative: {}", derivative_res);
57    println!("//////////////");
58    println!();
59
60    // Forward AD Multi ////////////////////////////////////////////////////////////////////////////
61    let function_standard = Test { coeff: 2.0 };
62    let function_derivative = function_standard.to_other_ad_type::<adfn<2>>();
63    let differentiable_block = FunctionEngine::new(function_standard, function_derivative, ForwardADMulti::new());
64
65    let (f_res, derivative_res) = differentiable_block.derivative(&inputs);
66    println!("Forward AD Multi: ");
67    println!("  f_res: {}", f_res[0]);
68    println!("  derivative: {}", derivative_res);
69    println!("//////////////");
70    println!();
71
72    // Finite Differencing /////////////////////////////////////////////////////////////////////////
73    let function_standard = Test { coeff: 2.0 };
74    let function_derivative = function_standard.clone();
75    let differentiable_block = FunctionEngine::new(function_standard, function_derivative, FiniteDifferencing::new());
76
77    let (f_res, derivative_res) = differentiable_block.derivative(&inputs);
78    println!("Finite Differencing: ");
79    println!("  f_res: {}", f_res[0]);
80    println!("  derivative: {}", derivative_res);
81    println!("//////////////");
82    println!();
83
84}

Trait Implementations§

Source§

impl<A: Clone + AD + ForwardADTrait> Clone for ForwardADMulti<A>

Source§

fn clone(&self) -> ForwardADMulti<A>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: AD + ForwardADTrait> DerivativeMethodTrait for ForwardADMulti<A>

Source§

type T = A

The AD type used by this method (e.g., f64, adr, adfn).
Source§

fn derivative<D: DifferentiableFunctionTrait<Self::T> + ?Sized>( &self, inputs: &[f64], function: &D, ) -> (Vec<f64>, DMatrix<f64>)

Computes the function’s value and its Jacobian matrix at the given input point. Read more

Auto Trait Implementations§

§

impl<A> Freeze for ForwardADMulti<A>

§

impl<A> RefUnwindSafe for ForwardADMulti<A>
where A: RefUnwindSafe,

§

impl<A> Send for ForwardADMulti<A>

§

impl<A> Sync for ForwardADMulti<A>

§

impl<A> Unpin for ForwardADMulti<A>
where A: Unpin,

§

impl<A> UnsafeUnpin for ForwardADMulti<A>

§

impl<A> UnwindSafe for ForwardADMulti<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
Source§

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

Source§

fn vzip(self) -> V