pub struct Dual { /* private fields */ }Expand description
A dual number data type supporting first order derivatives.
Implementations§
Source§impl Dual
 
impl Dual
Sourcepub fn new(real: f64, vars: Vec<String>) -> Self
 
pub fn new(real: f64, vars: Vec<String>) -> Self
Constructs a new Dual.
- varsshould be unique; duplicates will be removed by the- IndexSet.
Gradient values for each of the provided vars is set to 1.0_f64.
§Examples
let x = Dual::new(2.5, vec!["x".to_string()]);
// x: <Dual: 2.5, (x), [1.0]>Sourcepub fn try_new(
    real: f64,
    vars: Vec<String>,
    dual: Vec<f64>,
) -> Result<Self, PyErr>
 
pub fn try_new( real: f64, vars: Vec<String>, dual: Vec<f64>, ) -> Result<Self, PyErr>
Constructs a new Dual.
- varsshould be unique; duplicates will be removed by the- IndexSet.
- dualcan be empty; if so each gradient with respect to each- varsis set to 1.0_f64.
try_new should be used instead of new when gradient values other than 1.0_f64 are to
be initialised.
§Errors
If the length of dual and of vars are not the same after parsing.
§Examples
let x = Dual::try_new(2.5, vec!["x".to_string()], vec![4.2]).unwrap();
// x: <Dual: 2.5, (x), [4.2]>Sourcepub fn new_from<T: Vars>(other: &T, real: f64, vars: Vec<String>) -> Self
 
pub fn new_from<T: Vars>(other: &T, real: f64, vars: Vec<String>) -> Self
Construct a new Dual cloning the vars Arc pointer from another.
§Examples
let x = Dual::try_new(2.5, vec!["x".to_string(), "y".to_string()], vec![1.0, 0.0]).unwrap();
let y1 = Dual::new_from(&x, 1.5, vec!["y".to_string()]);This is semantically the same as:
let y2 = Dual::new(1.5, vec!["y".to_string()]).to_new_vars(x.vars(), None);
assert_eq!(y1, y2);Sourcepub fn try_new_from<T: Vars>(
    other: &T,
    real: f64,
    vars: Vec<String>,
    dual: Vec<f64>,
) -> Result<Self, PyErr>
 
pub fn try_new_from<T: Vars>( other: &T, real: f64, vars: Vec<String>, dual: Vec<f64>, ) -> Result<Self, PyErr>
Construct a new Dual cloning the vars Arc pointer from another.
§Examples
let x = Dual::try_new(2.5, vec!["x".to_string(), "y".to_string()], vec![1.0, 0.0]).unwrap();
let y1 = Dual::try_new_from(&x, 1.5, vec!["y".to_string()], vec![3.2]).unwrap();This is semantically the same as:
let y2 = Dual::try_new(1.5, vec!["y".to_string()], vec![3.2]).unwrap().to_new_vars(x.vars(), None);
assert_eq!(y1, y2);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Dual
 
impl<'de> Deserialize<'de> for Dual
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
    __D: Deserializer<'de>,
 
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
    __D: Deserializer<'de>,
Source§impl Element for Dual
 
impl Element for Dual
Source§const IS_COPY: bool = false
 
const IS_COPY: bool = false
Source§fn get_dtype(py: Python<'_>) -> Bound<'_, PyArrayDescr>
 
fn get_dtype(py: Python<'_>) -> Bound<'_, PyArrayDescr>
Source§fn clone_ref(&self, _py: Python<'_>) -> Self
 
fn clone_ref(&self, _py: Python<'_>) -> Self
§fn vec_from_slice(py: Python<'_>, slc: &[Self]) -> Vec<Self>
 
fn vec_from_slice(py: Python<'_>, slc: &[Self]) -> Vec<Self>
Source§impl<'py> IntoPyObject<'py> for Dual
 
impl<'py> IntoPyObject<'py> for Dual
Source§impl MathFuncs for Dual
 
impl MathFuncs for Dual
Source§impl Num for Dual
 
impl Num for Dual
type FromStrRadixErr = String
Source§fn from_str_radix(
    _src: &str,
    _radix: u32,
) -> Result<Self, Self::FromStrRadixErr>
 
fn from_str_radix( _src: &str, _radix: u32, ) -> Result<Self, Self::FromStrRadixErr>
2..=36). Read moreSource§impl PartialEq for Dual
Measures value equivalence of Dual.
 
impl PartialEq for Dual
Measures value equivalence of Dual.
Returns true if:
- realcomponents are equal:- lhs.real == rhs.real.
- dualcomponents are equal after aligning- vars.
Source§impl PartialOrd<Dual> for f64
 
impl PartialOrd<Dual> for f64
Source§impl PartialOrd<f64> for Dual
 
impl PartialOrd<f64> for Dual
Source§impl PartialOrd for Dual
Compares Dual by real component only.
 
impl PartialOrd for Dual
Compares Dual by real component only.
Source§impl PyClassImpl for Dual
 
impl PyClassImpl for Dual
Source§const IS_BASETYPE: bool = false
 
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
 
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
 
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
 
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
 
const IS_IMMUTABLE_TYPE: bool = false
Source§type ThreadChecker = SendablePyClass<Dual>
 
type ThreadChecker = SendablePyClass<Dual>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
 
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
 
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature<Dual> for PyClassImplCollector<Dual>
 
impl PyClassNewTextSignature<Dual> for PyClassImplCollector<Dual>
fn new_text_signature(self) -> Option<&'static str>
Source§impl PyMethods<Dual> for PyClassImplCollector<Dual>
 
impl PyMethods<Dual> for PyClassImplCollector<Dual>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for Dual
 
impl PyTypeInfo for Dual
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
 
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
 
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
 
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
 
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.Source§impl Signed for Dual
Sign for Dual is evaluated in terms of the real component.
 
impl Signed for Dual
Sign for Dual is evaluated in terms of the real component.
Source§fn abs(&self) -> Self
 
fn abs(&self) -> Self
Determine the absolute value of Dual.
If real is negative the returned Dual will negate both its real value and
dual.
Source§fn is_positive(&self) -> bool
 
fn is_positive(&self) -> bool
Source§fn is_negative(&self) -> bool
 
fn is_negative(&self) -> bool
Source§impl Vars for Dual
 
impl Vars for Dual
Source§fn vars(&self) -> &Arc<IndexSet<String>>
 
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
 
fn to_new_vars( &self, arc_vars: &Arc<IndexSet<String>>, state: Option<VarsRelationship>, ) -> Self
Construct a new Dual with vars set as the given Arc pointer and gradients shuffled in memory.
Examples
let x = Dual::new(1.5, vec!["x".to_string()]);
let xy = Dual::new(2.5, vec!["x".to_string(), "y".to_string()]);
let x_y = x.to_new_vars(xy.vars(), None);
// x_y: <Dual: 1.5, (x, y), [1.0, 0.0]>
assert_eq!(x_y, Dual::try_new(1.5, vec!["x".to_string(), "y".to_string()], vec![1.0, 0.0]).unwrap());Source§fn vars_cmp(&self, arc_vars: &Arc<IndexSet<String>>) -> VarsRelationship
 
fn vars_cmp(&self, arc_vars: &Arc<IndexSet<String>>) -> VarsRelationship
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,
 
fn to_union_vars(
    &self,
    other: &Self,
    state: Option<VarsRelationship>,
) -> (Self, Self)where
    Self: Sized,
Source§fn to_combined_vars(&self, other: &Self) -> (Self, Self)where
    Self: Sized,
 
fn to_combined_vars(&self, other: &Self) -> (Self, Self)where
    Self: Sized,
Self types whose vars are linked by the explicit union
of their own variables. Read moreimpl DerefToPyAny for Dual
impl NumberOps<Dual> for Dual
Auto Trait Implementations§
impl Freeze for Dual
impl RefUnwindSafe for Dual
impl Send for Dual
impl Sync for Dual
impl Unpin for Dual
impl UnwindSafe for Dual
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
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
§impl<T> FromPyObject<'_> for Twhere
    T: PyClass + Clone,
 
impl<T> FromPyObject<'_> for Twhere
    T: PyClass + Clone,
§fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
 
fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>
§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
    T: FromPyObject<'py>,
 
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
    T: FromPyObject<'py>,
§fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
 
fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>
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 more§impl<'py, T> IntoPyObjectExt<'py> for Twhere
    T: IntoPyObject<'py>,
 
impl<'py, T> IntoPyObjectExt<'py> for Twhere
    T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
 
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
 
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
 
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read more§impl<T> PyErrArguments for T
 
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
    T: PyTypeInfo,
 
impl<T> PyTypeCheck for Twhere
    T: PyTypeInfo,
§impl<SS, SP> SupersetOf<SS> for SPwhere
    SS: SubsetOf<SP>,
 
impl<SS, SP> SupersetOf<SS> for SPwhere
    SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
 
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
 
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
 
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.