Trait Vars

Source
pub trait Vars
where Self: Clone,
{ // Required methods fn vars(&self) -> &Arc<IndexSet<String>>; fn to_new_vars( &self, arc_vars: &Arc<IndexSet<String>>, state: Option<VarsRelationship>, ) -> Self; // Provided methods fn vars_cmp(&self, arc_vars: &Arc<IndexSet<String>>) -> VarsRelationship { ... } fn to_union_vars( &self, other: &Self, state: Option<VarsRelationship>, ) -> (Self, Self) where Self: Sized { ... } fn to_combined_vars(&self, other: &Self) -> (Self, Self) where Self: Sized { ... } fn ptr_eq(&self, other: &Self) -> bool { ... } }
Expand description

Manages the vars of the manifold associated with a dual number.

Required Methods§

Source

fn vars(&self) -> &Arc<IndexSet<String>>

Get a reference to the Arc pointer for the IndexSet containing the struct’s variables.

Source

fn to_new_vars( &self, arc_vars: &Arc<IndexSet<String>>, state: Option<VarsRelationship>, ) -> Self

Create a new dual number with vars aligned with given new Arc pointer.

This method compares the existing vars with the new and reshuffles manifold gradient values in memory. For large numbers of variables this is one of the least efficient operations relating different dual numbers and should be avoided where possible.

Provided Methods§

Source

fn vars_cmp(&self, arc_vars: &Arc<IndexSet<String>>) -> VarsRelationship

Compare the vars on a Dual with a given Arc pointer.

Source

fn to_union_vars( &self, other: &Self, state: Option<VarsRelationship>, ) -> (Self, Self)
where Self: Sized,

Construct a tuple of 2 Self types whose vars are linked by an Arc pointer.

Gradient values contained in fields may be shuffled in memory if necessary according to the calculated VarsRelationship. Do not use state directly unless you have performed a pre-check.

§Examples
let x = Dual::new(1.0, vec!["x".to_string()]);
let y = Dual::new(1.5, vec!["y".to_string()]);
let (a, b) = x.to_union_vars(&y, Some(VarsRelationship::Difference));
// a: <Dual: 1.0, (x, y), [1.0, 0.0]>
// b: <Dual: 1.5, (x, y), [0.0, 1.0]>
Source

fn to_combined_vars(&self, other: &Self) -> (Self, Self)
where Self: Sized,

Construct a tuple of 2 Self types whose vars are linked by the explicit union of their own variables.

Gradient values contained in fields will be shuffled in memory.

Source

fn ptr_eq(&self, other: &Self) -> bool

Compare if two Dual structs share the same vars by Arc pointer equivalence.

§Examples
let x1 = Dual::new(1.5, vec!["x".to_string()]);
let x2 = Dual::new(2.5, vec!["x".to_string()]);
assert_eq!(x1.ptr_eq(&x2), false); // Vars are the same but not a shared Arc pointer

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§