Struct Dual

Source
pub struct Dual { /* private fields */ }
Expand description

A dual number data type supporting first order derivatives.

Implementations§

Source§

impl Dual

Source

pub fn new(real: f64, vars: Vec<String>) -> Self

Constructs a new Dual.

  • vars should 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]>
Source

pub fn try_new( real: f64, vars: Vec<String>, dual: Vec<f64>, ) -> Result<Self, PyErr>

Constructs a new Dual.

  • vars should be unique; duplicates will be removed by the IndexSet.
  • dual can be empty; if so each gradient with respect to each vars is 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]>
Source

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);
Source

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);
Source

pub fn clone_from<T: Vars>(other: &T, real: f64, dual: Array1<f64>) -> Self

Construct a new Dual cloning the vars Arc pointer from another.

Source

pub fn real(&self) -> f64

Get the real component value of the struct.

Source§

impl Dual

Source

pub fn __getnewargs__(&self) -> PyResult<(f64, Vec<String>, Vec<f64>)>

Trait Implementations§

Source§

impl Add<&Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Dual) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Dual) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&Dual> for Dual

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Dual) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&Dual> for f64

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Dual) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &f64) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&f64> for Dual

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &f64) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Dual) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Dual) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Dual> for f64

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Dual) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<f64> for Dual

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self::Output

Performs the + operation. Read more
Source§

impl Add for Dual

Source§

type Output = Dual

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Dual) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for Dual

Source§

fn clone(&self) -> Dual

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Dual

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Dual

Source§

fn default() -> Dual

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

impl<'de> Deserialize<'de> for Dual

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Div<&Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Dual) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Dual) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&Dual> for Dual

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Dual) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&Dual> for f64

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &Dual) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &f64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&f64> for Dual

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: &f64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Dual) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Dual) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<Dual> for f64

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Dual) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<f64> for Dual

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for Dual

Source§

type Output = Dual

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Dual) -> Self::Output

Performs the / operation. Read more
Source§

impl Element for Dual

Source§

const IS_COPY: bool = false

Flag that indicates whether this type is trivially copyable. Read more
Source§

fn get_dtype(py: Python<'_>) -> Bound<'_, PyArrayDescr>

Returns the associated type descriptor (“dtype”) for the given element type.
Source§

fn clone_ref(&self, _py: Python<'_>) -> Self

Create a clone of the value while the GIL is guaranteed to be held.
§

fn vec_from_slice(py: Python<'_>, slc: &[Self]) -> Vec<Self>

Create an owned copy of the slice while the GIL is guaranteed to be held. Read more
§

fn array_from_view<D>( py: Python<'_>, view: ArrayBase<ViewRepr<&Self>, D>, ) -> ArrayBase<OwnedRepr<Self>, D>
where D: Dimension,

Create an owned copy of the array while the GIL is guaranteed to be held. Read more
Source§

impl From<&Dual> for Dual2

Source§

fn from(value: &Dual) -> Self

Converts to this type from the input type.
Source§

impl From<&Dual> for Number

Source§

fn from(value: &Dual) -> Self

Converts to this type from the input type.
Source§

impl From<&Dual> for f64

Source§

fn from(value: &Dual) -> Self

Converts to this type from the input type.
Source§

impl From<&Dual2> for Dual

Source§

fn from(value: &Dual2) -> Self

Converts to this type from the input type.
Source§

impl From<&Number> for Dual

Source§

fn from(value: &Number) -> Self

Converts to this type from the input type.
Source§

impl From<Dual> for Dual2

Source§

fn from(value: Dual) -> Self

Converts to this type from the input type.
Source§

impl From<Dual> for Number

Source§

fn from(value: Dual) -> Self

Converts to this type from the input type.
Source§

impl From<Dual> for f64

Source§

fn from(value: Dual) -> Self

Converts to this type from the input type.
Source§

impl From<Dual2> for Dual

Source§

fn from(value: Dual2) -> Self

Converts to this type from the input type.
Source§

impl From<Number> for Dual

Source§

fn from(value: Number) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Dual

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl Gradient1 for Dual

Source§

fn dual(&self) -> &Array1<f64>

Get a reference to the Array containing the first order gradients.
Source§

fn gradient1(&self, vars: Vec<String>) -> Array1<f64>

Return a set of first order gradients ordered by the given vector. Read more
Source§

impl<'py> IntoPyObject<'py> for Dual

Source§

type Target = Dual

The Python output type
Source§

type Output = Bound<'py, <Dual as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

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

fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>

Performs the conversion.
Source§

impl MathFuncs for Dual

Source§

fn exp(&self) -> Self

Return the exponential of a value.
Source§

fn log(&self) -> Self

Return the natural logarithm of a value.
Source§

fn norm_cdf(&self) -> Self

Return the standard normal cumulative distribution function of a value.
Source§

fn inv_norm_cdf(&self) -> Self

Return the inverse standard normal cumulative distribution function of a value.
Source§

impl Mul<&Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Dual) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Dual) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Dual> for Dual

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Dual) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Dual> for f64

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Dual) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &f64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&f64> for Dual

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &f64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dual) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dual) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Dual> for f64

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dual) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f64> for Dual

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul for Dual

Source§

type Output = Dual

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Dual) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for &Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Neg for Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Num for Dual

Source§

type FromStrRadixErr = String

Source§

fn from_str_radix( _src: &str, _radix: u32, ) -> Result<Self, Self::FromStrRadixErr>

Convert from a string and radix (typically 2..=36). Read more
Source§

impl One for Dual

Source§

fn one() -> Dual

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl PartialEq<Dual> for f64

Source§

fn eq(&self, other: &Dual) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<f64> for Dual

Source§

fn eq(&self, other: &f64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Dual

Measures value equivalence of Dual.

Returns true if:

  • real components are equal: lhs.real == rhs.real.
  • dual components are equal after aligning vars.
Source§

fn eq(&self, other: &Dual) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd<Dual> for f64

Source§

fn partial_cmp(&self, other: &Dual) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<f64> for Dual

Source§

fn partial_cmp(&self, other: &f64) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd for Dual

Compares Dual by real component only.

Source§

fn partial_cmp(&self, other: &Dual) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Pow<&Dual> for &Dual

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: &Dual) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<&Dual> for &f64

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: &Dual) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<&Dual> for Dual

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: &Dual) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<&Dual> for f64

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: &Dual) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<&f64> for &Dual

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: &f64) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<&f64> for Dual

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: &f64) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<Dual> for &Dual

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: Dual) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<Dual> for &f64

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: Dual) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<Dual> for Dual

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: Dual) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<Dual> for f64

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: Dual) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<f64> for &Dual

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: f64) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl Pow<f64> for Dual

Source§

type Output = Dual

The result after applying the operator.
Source§

fn pow(self, power: f64) -> Self::Output

Returns self to the power rhs. Read more
Source§

impl PyClass for Dual

Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for Dual

Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

const IS_IMMUTABLE_TYPE: bool = false

#[pyclass(immutable_type)]
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = SendablePyClass<Dual>

This handles following two situations: Read more
Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

§

fn dict_offset() -> Option<isize>

§

fn weaklist_offset() -> Option<isize>

Source§

impl PyClassNewTextSignature<Dual> for PyClassImplCollector<Dual>

Source§

fn new_text_signature(self) -> Option<&'static str>

Source§

impl PyClass__add__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __add__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__eq__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __eq__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__ge__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __ge__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__gt__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __gt__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__le__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __le__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__lt__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __lt__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__mul__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __mul__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__pow__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __pow__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, arg1: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__radd__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __radd__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__rmul__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __rmul__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__rpow__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __rpow__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, arg1: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__rsub__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __rsub__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__rtruediv__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __rtruediv__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__sub__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __sub__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl PyClass__truediv__SlotFragment<Dual> for PyClassImplCollector<Dual>

Source§

unsafe fn __truediv__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a Dual

Source§

type Holder = Option<PyRef<'py, Dual>>

Source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut Dual

Source§

type Holder = Option<PyRefMut<'py, Dual>>

Source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

Source§

impl PyMethods<Dual> for PyClassImplCollector<Dual>

Source§

fn py_methods(self) -> &'static PyClassItems

Source§

impl PyTypeInfo for Dual

Source§

const NAME: &'static str = "Dual"

Class name.
Source§

const MODULE: Option<&'static str>

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
§

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
§

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
§

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.
Source§

impl Rem<&Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &Dual) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &Dual) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&Dual> for Dual

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &Dual) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&Dual> for f64

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &Dual) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &f64) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&f64> for Dual

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: &f64) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Dual) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Dual) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<Dual> for f64

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Dual) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: f64) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<f64> for Dual

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: f64) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem for Dual

Source§

type Output = Dual

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Dual) -> Self::Output

Performs the % operation. Read more
Source§

impl Serialize for Dual

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Signed for Dual

Sign for Dual is evaluated in terms of the real component.

Source§

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.

This behaviour is undefined at zero. The derivative of the `abs` function is not defined there and care needs to be taken when implying gradients.
Source§

fn abs_sub(&self, other: &Self) -> Self

The positive difference of two numbers. Read more
Source§

fn signum(&self) -> Self

Returns the sign of the number. Read more
Source§

fn is_positive(&self) -> bool

Returns true if the number is positive and false if the number is zero or negative.
Source§

fn is_negative(&self) -> bool

Returns true if the number is negative and false if the number is zero or positive.
Source§

impl Sub<&Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Dual) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Dual) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&Dual> for Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Dual) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&Dual> for f64

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Dual) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &f64) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&f64> for Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &f64) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Dual> for &Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Dual) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Dual> for &f64

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Dual) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Dual> for f64

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Dual) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<f64> for &Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<f64> for Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Dual

Source§

type Output = Dual

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Dual) -> Self::Output

Performs the - operation. Read more
Source§

impl Sum for Dual

Source§

fn sum<I>(iter: I) -> Self
where I: Iterator<Item = Dual>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Vars for Dual

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

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

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

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

Compare if two Dual structs share the same vars by Arc pointer equivalence. Read more
Source§

impl Zero for Dual

Source§

fn zero() -> Dual

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl DerefToPyAny for Dual

Source§

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> 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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromPyObject<'_> for T
where T: PyClass + Clone,

§

fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,

§

fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
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
§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts 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>

Converts self into a Python object. Read more
§

impl<T> PyErrArguments for T
where T: for<'py> IntoPyObject<'py> + Send + Sync,

§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

§

const NAME: &'static str = <T as PyTypeInfo>::NAME

Name of self. This is used in error messages, for example.
§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

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

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

§

fn vzip(self) -> V

§

impl<T> ClosedNeg for T
where T: Neg<Output = T>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,

Source§

impl<T> NumRef for T
where T: Num + for<'r> NumOps<&'r T>,

Source§

impl<T, Base> RefNum<Base> for T
where T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

§

impl<T> Ungil for T
where T: Send,