pub struct Dual2Vec<T, F, const N: usize> {
pub re: T,
pub v1: StaticVec<T, N>,
pub v2: StaticMat<T, N, N>,
/* private fields */
}Expand description
A second order dual number for the calculation of Hessians.
Fields§
§re: TReal part of the second order dual number
v1: StaticVec<T, N>Gradient part of the second order dual number
v2: StaticMat<T, N, N>Hessian part of the second order dual number
Implementations§
source§impl<T, F> Dual2Vec<T, F, 1>
impl<T, F> Dual2Vec<T, F, 1>
sourcepub fn new_scalar(re: T, v1: T, v2: T) -> Self
pub fn new_scalar(re: T, v1: T, v2: T) -> Self
Create a new scalar second order dual number from its fields.
source§impl<T: One, F> Dual2Vec<T, F, 1>
impl<T: One, F> Dual2Vec<T, F, 1>
sourcepub fn derive(self) -> Self
pub fn derive(self) -> Self
Derive a scalar second order dual number
let x = Dual2::from_re(5.0).derive().powi(2);
assert_eq!(x.re, 25.0); // x²
assert_eq!(x.v1[0], 10.0); // 2x
assert_eq!(x.v2[(0,0)], 2.0); // 2The argument can also be a dual number
let x = Dual2::from_re(Dual64::from_re(5.0).derive())
.derive()
.powi(2);
assert_eq!(x.re.re(), 25.0); // x²
assert_eq!(x.re.eps[0], 10.0); // 2x
assert_eq!(x.v1[0].re, 10.0); // 2x
assert_eq!(x.v1[0].eps[0], 2.0); // 2
assert_eq!(x.v2[(0,0)].re, 2.0); // 2Trait Implementations§
source§impl<'a, 'b, T: DualNum<F>, F: Float, const N: usize> Add<&'a Dual2Vec<T, F, N>> for &'b Dual2Vec<T, F, N>
impl<'a, 'b, T: DualNum<F>, F: Float, const N: usize> Add<&'a Dual2Vec<T, F, N>> for &'b Dual2Vec<T, F, N>
source§impl<T: Copy + AddAssign, F: Float, const N: usize> AddAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
impl<T: Copy + AddAssign, F: Float, const N: usize> AddAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moresource§impl<T: AddAssign<F>, F: Float, const N: usize> AddAssign<F> for Dual2Vec<T, F, N>
impl<T: AddAssign<F>, F: Float, const N: usize> AddAssign<F> for Dual2Vec<T, F, N>
source§fn add_assign(&mut self, other: F)
fn add_assign(&mut self, other: F)
Performs the
+= operation. Read moresource§impl<'a, 'b, T: DualNum<F>, F: Float, const N: usize> Div<&'a Dual2Vec<T, F, N>> for &'b Dual2Vec<T, F, N>
impl<'a, 'b, T: DualNum<F>, F: Float, const N: usize> Div<&'a Dual2Vec<T, F, N>> for &'b Dual2Vec<T, F, N>
source§impl<T: DualNum<F>, F: Float, const N: usize> DivAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: Float, const N: usize> DivAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
Performs the
/= operation. Read moresource§impl<T: DualNum<F>, F: DualNumFloat, const N: usize> DivAssign<F> for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: DualNumFloat, const N: usize> DivAssign<F> for Dual2Vec<T, F, N>
source§fn div_assign(&mut self, other: F)
fn div_assign(&mut self, other: F)
Performs the
/= operation. Read moresource§impl<T: DualNum<F>, F: DualNumFloat, const N: usize> DualNum<F> for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: DualNumFloat, const N: usize> DualNum<F> for Dual2Vec<T, F, N>
source§fn sin_cos(&self) -> (Self, Self)
fn sin_cos(&self) -> (Self, Self)
Calculate sine and cosine simultaneously
source§impl<T: DualNum<F>, F: Float + FloatConst, const N: usize> FloatConst for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: Float + FloatConst, const N: usize> FloatConst for Dual2Vec<T, F, N>
source§impl<T: DualNum<F>, F: Float + FromPrimitive, const N: usize> FromPrimitive for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: Float + FromPrimitive, const N: usize> FromPrimitive for Dual2Vec<T, F, N>
source§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
Converts an
isize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
Converts an
i8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
Converts an
i16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
Converts an
i32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_i64(n: i64) -> Option<Self>
fn from_i64(n: i64) -> Option<Self>
Converts an
i64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
Converts an
i128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moresource§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
Converts a
usize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
Converts an
u8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
Converts an
u16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_u32(n: u32) -> Option<Self>
fn from_u32(n: u32) -> Option<Self>
Converts an
u32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_u64(n: u64) -> Option<Self>
fn from_u64(n: u64) -> Option<Self>
Converts an
u64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.source§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
Converts an
u128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moresource§impl<T: DualNum<F> + IsDerivativeZero, F: Float, const N: usize> IsDerivativeZero for Dual2Vec<T, F, N>
impl<T: DualNum<F> + IsDerivativeZero, F: Float, const N: usize> IsDerivativeZero for Dual2Vec<T, F, N>
fn is_derivative_zero(&self) -> bool
source§impl<'a, 'b, T: DualNum<F>, F: Float, const N: usize> Mul<&'a Dual2Vec<T, F, N>> for &'b Dual2Vec<T, F, N>
impl<'a, 'b, T: DualNum<F>, F: Float, const N: usize> Mul<&'a Dual2Vec<T, F, N>> for &'b Dual2Vec<T, F, N>
source§impl<T: DualNum<F>, F: Float, const N: usize> MulAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: Float, const N: usize> MulAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs the
*= operation. Read moresource§impl<T: DualNum<F>, F: DualNumFloat, const N: usize> MulAssign<F> for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: DualNumFloat, const N: usize> MulAssign<F> for Dual2Vec<T, F, N>
source§fn mul_assign(&mut self, other: F)
fn mul_assign(&mut self, other: F)
Performs the
*= operation. Read moresource§impl<T: DualNum<F> + Signed, F: Float, const N: usize> Num for Dual2Vec<T, F, N>
impl<T: DualNum<F> + Signed, F: Float, const N: usize> Num for Dual2Vec<T, F, N>
type FromStrRadixErr = <F as Num>::FromStrRadixErr
source§fn from_str_radix(_str: &str, _radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(_str: &str, _radix: u32) -> Result<Self, Self::FromStrRadixErr>
Convert from a string and radix (typically
2..=36). Read moresource§impl<T: PartialEq, F: PartialEq, const N: usize> PartialEq<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
impl<T: PartialEq, F: PartialEq, const N: usize> PartialEq<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
source§impl<'a, T: DualNum<F>, F: Float, const N: usize> Product<&'a Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
impl<'a, T: DualNum<F>, F: Float, const N: usize> Product<&'a Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
source§impl<T: DualNum<F>, F: Float, const N: usize> Product<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: Float, const N: usize> Product<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
source§impl<T, F: Float, const N: usize> RemAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
impl<T, F: Float, const N: usize> RemAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
source§fn rem_assign(&mut self, _other: Self)
fn rem_assign(&mut self, _other: Self)
Performs the
%= operation. Read moresource§impl<T, F: Float, const N: usize> RemAssign<F> for Dual2Vec<T, F, N>
impl<T, F: Float, const N: usize> RemAssign<F> for Dual2Vec<T, F, N>
source§fn rem_assign(&mut self, _other: F)
fn rem_assign(&mut self, _other: F)
Performs the
%= operation. Read moresource§impl<T: DualNum<F>, F: DualNumFloat, const N: usize> Signed for Dual2Vec<T, F, N>
impl<T: DualNum<F>, F: DualNumFloat, const N: usize> Signed for Dual2Vec<T, F, N>
source§fn is_positive(&self) -> bool
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
fn is_negative(&self) -> bool
Returns true if the number is negative and false if the number is zero or positive.
source§impl<'a, 'b, T: DualNum<F>, F: Float, const N: usize> Sub<&'a Dual2Vec<T, F, N>> for &'b Dual2Vec<T, F, N>
impl<'a, 'b, T: DualNum<F>, F: Float, const N: usize> Sub<&'a Dual2Vec<T, F, N>> for &'b Dual2Vec<T, F, N>
source§impl<T: Copy + SubAssign, F: Float, const N: usize> SubAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
impl<T: Copy + SubAssign, F: Float, const N: usize> SubAssign<Dual2Vec<T, F, N>> for Dual2Vec<T, F, N>
source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
Performs the
-= operation. Read moresource§impl<T: SubAssign<F>, F: Float, const N: usize> SubAssign<F> for Dual2Vec<T, F, N>
impl<T: SubAssign<F>, F: Float, const N: usize> SubAssign<F> for Dual2Vec<T, F, N>
source§fn sub_assign(&mut self, other: F)
fn sub_assign(&mut self, other: F)
Performs the
-= operation. Read more