Skip to main content

ForwardModeEngine

Struct ForwardModeEngine 

Source
pub struct ForwardModeEngine<T: Float + Debug + Default + Clone + Send + Sync + Sum + 'static> { /* private fields */ }
Expand description

Forward-mode AD engine

Implementations§

Source§

impl<T: Float + Debug + Default + Clone + Send + Sync + Sum + 'static> ForwardModeEngine<T>

Source

pub fn new() -> Self

Create a new forward-mode AD engine

Source

pub fn enable_higher_order(&mut self, enabled: bool)

Enable higher-order derivatives

Source

pub fn higher_order_enabled(&self) -> bool

Whether higher-order derivative tracking is enabled

Source

pub fn set_seed_vectors(&mut self, seeds: Vec<Array1<T>>)

Set seed vectors for computing directional derivatives

Source

pub fn seed_vectors(&self) -> &[Array1<T>] ⓘ

Seed vectors previously registered with Self::set_seed_vectors

Source

pub fn variable_order(&self) -> &[String]

Variable names in creation order (the seed-space layout)

Source

pub fn declared_shape(&self, node_id: usize) -> Result<Option<&[usize]>>

Declared logical shape of a tape node, when the builder recorded one.

Leaves and matrix products carry an explicit shape; element-wise operations infer theirs from their operands during the forward pass and therefore report None.

Source

pub fn create_variable(&mut self, name: &str, value: Array1<T>) -> usize

Create a variable.

Re-creating a variable under an existing name rebinds the name to the new tape node but keeps its original seed ordinal.

Source

pub fn create_constant(&mut self, value: Array1<T>) -> usize

Create a constant

Source

pub fn input_dimension( &self, inputs: &HashMap<String, Array1<T>>, ) -> Result<usize>

Total dimension of the seed / tangent space for the given inputs.

This is the sum of the input lengths taken in variable-creation order.

Source

pub fn add(&mut self, lhs: usize, rhs: usize) -> Result<usize>

Add two variables

Source

pub fn subtract(&mut self, lhs: usize, rhs: usize) -> Result<usize>

Subtract two variables

Source

pub fn multiply(&mut self, lhs: usize, rhs: usize) -> Result<usize>

Multiply two variables

Source

pub fn divide(&mut self, lhs: usize, rhs: usize) -> Result<usize>

Divide two variables

Source

pub fn power(&mut self, base: usize, exponent: T) -> Result<usize>

Raise to power

Source

pub fn exp(&mut self, input: usize) -> Result<usize>

Exponential function

Source

pub fn log(&mut self, input: usize) -> Result<usize>

Natural logarithm

Source

pub fn sin(&mut self, input: usize) -> Result<usize>

Sine function

Source

pub fn cos(&mut self, input: usize) -> Result<usize>

Cosine function

Source

pub fn tanh(&mut self, input: usize) -> Result<usize>

Hyperbolic tangent

Source

pub fn sigmoid(&mut self, input: usize) -> Result<usize>

Sigmoid function

Source

pub fn relu(&mut self, input: usize) -> Result<usize>

ReLU function

Source

pub fn matmul( &mut self, lhs: usize, rhs: usize, dims: (usize, usize, usize), ) -> Result<usize>

Matrix multiplication.

dims is (m, k, n): the left operand is the row-major flattening of an m x k matrix, the right operand of a k x n matrix, and the output is m x n.

Source

pub fn dot(&mut self, lhs: usize, rhs: usize) -> Result<usize>

Dot product

Source

pub fn sum(&mut self, input: usize, _axis: Option<usize>) -> Result<usize>

Sum reduction over all elements

Source

pub fn mean(&mut self, input: usize, _axis: Option<usize>) -> Result<usize>

Mean reduction over all elements

Source

pub fn norm(&mut self, input: usize) -> Result<usize>

L2 norm

Source

pub fn forward_pass( &self, inputs: &HashMap<String, Array1<T>>, seed_direction: &Array1<T>, ) -> Result<Vec<VectorDual<T>>>

Compute the forward pass with dual numbers.

seed_direction is a vector in the concatenated input space: its length must equal Self::input_dimension, and the slice belonging to a variable seeds that variable’s tangent component-wise.

Source

pub fn jacobian_vector_product( &self, inputs: &HashMap<String, Array1<T>>, output_id: usize, direction: &Array1<T>, ) -> Result<Array1<T>>

Compute Jacobian-vector product

Source

pub fn jacobian_matrix( &self, inputs: &HashMap<String, Array1<T>>, output_id: usize, input_size: usize, ) -> Result<Array2<T>>

Compute the full Jacobian of output_id with respect to the inputs.

The result has shape (output_dim, input_dim) where output_dim is the number of elements of the selected output node and input_dim is Self::input_dimension. input_size must agree with input_dim.

Source

pub fn get_graph_stats(&self) -> ForwardModeStats

Get computation graph statistics

Trait Implementations§

Source§

impl<T: Float + Debug + Default + Clone + Send + Sync + Sum + 'static> Default for ForwardModeEngine<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ForwardModeEngine<T>
where Vec<ForwardOperation<T>>: Freeze, Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: Freeze,

§

impl<T> RefUnwindSafe for ForwardModeEngine<T>
where Vec<ForwardOperation<T>>: RefUnwindSafe, Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: RefUnwindSafe,

§

impl<T> Send for ForwardModeEngine<T>
where Vec<ForwardOperation<T>>: Send, Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: Send,

§

impl<T> Sync for ForwardModeEngine<T>
where Vec<ForwardOperation<T>>: Sync, Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: Sync,

§

impl<T> Unpin for ForwardModeEngine<T>
where Vec<ForwardOperation<T>>: Unpin, Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: Unpin,

§

impl<T> UnsafeUnpin for ForwardModeEngine<T>
where Vec<ForwardOperation<T>>: UnsafeUnpin, Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: UnsafeUnpin,

§

impl<T> UnwindSafe for ForwardModeEngine<T>
where Vec<ForwardOperation<T>>: UnwindSafe, Vec<ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>: 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> 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<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V