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>
impl<T: Float + Debug + Default + Clone + Send + Sync + Sum + 'static> ForwardModeEngine<T>
Sourcepub fn enable_higher_order(&mut self, enabled: bool)
pub fn enable_higher_order(&mut self, enabled: bool)
Enable higher-order derivatives
Sourcepub fn higher_order_enabled(&self) -> bool
pub fn higher_order_enabled(&self) -> bool
Whether higher-order derivative tracking is enabled
Sourcepub fn set_seed_vectors(&mut self, seeds: Vec<Array1<T>>)
pub fn set_seed_vectors(&mut self, seeds: Vec<Array1<T>>)
Set seed vectors for computing directional derivatives
Sourcepub fn seed_vectors(&self) -> &[Array1<T>] ⓘ
pub fn seed_vectors(&self) -> &[Array1<T>] ⓘ
Seed vectors previously registered with Self::set_seed_vectors
Sourcepub fn variable_order(&self) -> &[String]
pub fn variable_order(&self) -> &[String]
Variable names in creation order (the seed-space layout)
Sourcepub fn declared_shape(&self, node_id: usize) -> Result<Option<&[usize]>>
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.
Sourcepub fn create_variable(&mut self, name: &str, value: Array1<T>) -> usize
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.
Sourcepub fn create_constant(&mut self, value: Array1<T>) -> usize
pub fn create_constant(&mut self, value: Array1<T>) -> usize
Create a constant
Sourcepub fn input_dimension(
&self,
inputs: &HashMap<String, Array1<T>>,
) -> Result<usize>
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.
Sourcepub fn matmul(
&mut self,
lhs: usize,
rhs: usize,
dims: (usize, usize, usize),
) -> Result<usize>
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.
Sourcepub fn sum(&mut self, input: usize, _axis: Option<usize>) -> Result<usize>
pub fn sum(&mut self, input: usize, _axis: Option<usize>) -> Result<usize>
Sum reduction over all elements
Sourcepub fn mean(&mut self, input: usize, _axis: Option<usize>) -> Result<usize>
pub fn mean(&mut self, input: usize, _axis: Option<usize>) -> Result<usize>
Mean reduction over all elements
Sourcepub fn forward_pass(
&self,
inputs: &HashMap<String, Array1<T>>,
seed_direction: &Array1<T>,
) -> Result<Vec<VectorDual<T>>>
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.
Sourcepub fn jacobian_vector_product(
&self,
inputs: &HashMap<String, Array1<T>>,
output_id: usize,
direction: &Array1<T>,
) -> Result<Array1<T>>
pub fn jacobian_vector_product( &self, inputs: &HashMap<String, Array1<T>>, output_id: usize, direction: &Array1<T>, ) -> Result<Array1<T>>
Compute Jacobian-vector product
Sourcepub fn jacobian_matrix(
&self,
inputs: &HashMap<String, Array1<T>>,
output_id: usize,
input_size: usize,
) -> Result<Array2<T>>
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.
Sourcepub fn get_graph_stats(&self) -> ForwardModeStats
pub fn get_graph_stats(&self) -> ForwardModeStats
Get computation graph statistics
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ForwardModeEngine<T>
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>
impl<T> Sync for ForwardModeEngine<T>
impl<T> Unpin for ForwardModeEngine<T>
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> 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.