Expand description
§f64ad_
| Documentation | API |
§Introduction
This crate brings easy to use, efficient, and highly flexible automatic differentiation to the Rust programming language. Utilizing Rust’s extensive operator overloading and expressive Enum features, f64ad_ can be thought of as a drop-in replacement for f64 that affords forward mode or backwards mode automatic differentiation on any downstream computation in Rust.
§Key features
- f64ad_ supports reverse mode or forward mode automatic differentiation
- f64ad_ supports not just first derivatives, but also any higher order derivatives on any functions.
- f64ad_ uses polymorphism such that any
f64ad_
object can either be considered a derivative tracking variable or a standard f64 with very little overhead depending on your current use case. Thus, it is reasonable to replace almost all uses of f64 with f64ad_, and in return, you’ll be able to “turn on” derivatives with respect to these values whenever you need them. - The f64ad_ Enum type implements several useful traits that allow it to operate almost exactly as a
standard f64. For example, it even implements the
RealField
andComplexField
traits, meaning it can be used in anynalgebra
orndarray
computations. - Certain functions can be pre-computed and locked to boost performance at run-time.
§Crate structure
This crate is a cargo workspace with two member crates: (1) f64ad_core
; and (2) f64ad_core_derive
.
All core implementations for f64ad_ can be found in f64ad_core
. The f64ad_core_derive
is
currently a placeholder and will be used for procedural macro implementations.
§Citing f64ad_
If you use any part of the f64ad_ library in your research, please cite the software as follows:
@misc{rakita_2022, url={https://djrakita.github.io/f64ad/},
author={Rakita, Daniel},
title={f64ad_: Efficient and Flexible Automatic Differentiation in Rust}
year={2022}}
Modules§
Macros§
- abs_
diff_ eq - Approximate equality of using the absolute difference.
- abs_
diff_ ne - Approximate inequality of using the absolute difference.
- assert_
abs_ diff_ eq - An assertion that delegates to
abs_diff_eq!
, and panics with a helpful error on failure. - assert_
abs_ diff_ ne - An assertion that delegates to
abs_diff_ne!
, and panics with a helpful error on failure. - assert_
relative_ eq - An assertion that delegates to
relative_eq!
, and panics with a helpful error on failure. - assert_
relative_ ne - An assertion that delegates to
relative_ne!
, and panics with a helpful error on failure. - assert_
ulps_ eq - An assertion that delegates to
ulps_eq!
, and panics with a helpful error on failure. - assert_
ulps_ ne - An assertion that delegates to
ulps_ne!
, and panics with a helpful error on failure. - relative_
eq - Approximate equality using both the absolute difference and relative based comparisons.
- relative_
ne - Approximate inequality using both the absolute difference and relative based comparisons.
- ulps_eq
- Approximate equality using both the absolute difference and ULPs (Units in Last Place).
- ulps_ne
- Approximate inequality using both the absolute difference and ULPs (Units in Last Place).
Structs§
- AbsDiff
- The requisite parameters for testing for approximate equality using a absolute difference based comparison.
- Parse
Float Error - Relative
- The requisite parameters for testing for approximate equality using a relative based comparison.
- Ulps
- The requisite parameters for testing for approximate equality using an ULPs based comparison.
Enums§
Traits§
- AbsDiff
Eq - Equality that is defined using the absolute difference of two numbers.
- AsPrimitive
- A generic interface for casting between machine scalars with the
as
operator, which admits narrowing and precision loss. Implementers of this traitAsPrimitive
should behave like a primitive numeric type (e.g. a newtype around another primitive), and the intended conversion must never fail. - Bounded
- Numbers which have upper and lower bounds
- Checked
Add - Performs addition that returns
None
instead of wrapping around on overflow. - Checked
Div - Performs division that returns
None
instead of panicking on division by zero and instead of wrapping around on underflow and overflow. - Checked
Euclid - Checked
Mul - Performs multiplication that returns
None
instead of wrapping around on underflow or overflow. - Checked
Neg - Performs negation that returns
None
if the result can’t be represented. - Checked
Rem - Performs an integral remainder that returns
None
instead of panicking on division by zero and instead of wrapping around on underflow and overflow. - Checked
Shl - Performs a left shift that returns
None
on shifts larger than or equal to the type width. - Checked
Shr - Performs a right shift that returns
None
on shifts larger than or equal to the type width. - Checked
Sub - Performs subtraction that returns
None
instead of wrapping around on underflow. - Closed
Add - Trait alias for
Add
andAddAssign
with result of typeSelf
. - Closed
Div - Trait alias for
Div
andDivAssign
with result of typeSelf
. - Closed
Mul - Trait alias for
Mul
andMulAssign
with result of typeSelf
. - Closed
Neg - Trait alias for
Neg
with result of typeSelf
. - Closed
Sub - Trait alias for
Sub
andSubAssign
with result of typeSelf
. - Complex
Field - Trait shared by all complex fields and its subfields (like real numbers).
- Const
One - Defines an associated constant representing the multiplicative identity
element for
Self
. - Const
Zero - Defines an associated constant representing the additive identity element
for
Self
. - Euclid
- Field
- Trait implemented by fields, i.e., complex numbers and floats.
- Float
- Generic trait for floating point numbers
- Float
Const - From
Bytes - From
Primitive - A generic trait for converting a number to a value.
- Inv
- Unary operator for retrieving the multiplicative inverse, or reciprocal, of a value.
- MulAdd
- Fused multiply-add. Computes
(self * a) + b
with only one rounding error, yielding a more accurate result than an unfused multiply-add. - MulAdd
Assign - The fused multiply-add assignment operation
*self = (*self * a) + b
- Num
- The base trait for numeric types, covering
0
and1
values, comparisons, basic numeric operations, and string conversion. - NumAssign
- The trait for
Num
types which also implement assignment operators. - NumAssign
Ops - Generic trait for types implementing numeric assignment operators (like
+=
). - NumAssign
Ref - The trait for
NumAssign
types which also implement assignment operations taking the second operand by reference. - NumCast
- An interface for casting between machine scalars.
- NumOps
- Generic trait for types implementing basic numeric operations
- NumRef
- The trait for
Num
types which also implement numeric operations taking the second operand by reference. - One
- Defines a multiplicative identity element for
Self
. - Pow
- Binary operator for raising a value to a power.
- PrimInt
- Generic trait for primitive integers.
- Real
Field - Trait shared by all reals.
- RefNum
- The trait for
Num
references which implement numeric operations, taking the second operand either by value or by reference. - Relative
Eq - Equality comparisons between two numbers using both the absolute difference and relative based comparisons.
- Saturating
- Saturating math operations. Deprecated, use
SaturatingAdd
,SaturatingSub
andSaturatingMul
instead. - Saturating
Add - Performs addition that saturates at the numeric bounds instead of overflowing.
- Saturating
Mul - Performs multiplication that saturates at the numeric bounds instead of overflowing.
- Saturating
Sub - Performs subtraction that saturates at the numeric bounds instead of overflowing.
- Signed
- Useful functions for signed numbers (i.e. numbers that can be negative).
- Subset
Of - Nested sets and conversions between them (using an injective mapping). Useful to work with
substructures. In generic code, it is preferable to use
SupersetOf
as trait bound whenever possible instead ofSubsetOf
(because SupersetOf is automatically implemented wheneverSubsetOf
is). - Superset
Of - Nested sets and conversions between them. Useful to work with substructures. It is preferable
to implement the
SubsetOf
trait instead ofSupersetOf
whenever possible (becauseSupersetOf
is automatically implemented wheneverSubsetOf
is). - ToBytes
- ToPrimitive
- A generic trait for converting a value to a number.
- UlpsEq
- Equality comparisons between two numbers using both the absolute difference and ULPs (Units in Last Place) based comparisons.
- Unsigned
- A trait for values which cannot be negative
- Wrapping
Add - Performs addition that wraps around on overflow.
- Wrapping
Mul - Performs multiplication that wraps around on overflow.
- Wrapping
Neg - Performs a negation that does not panic.
- Wrapping
Shl - Performs a left shift that does not panic.
- Wrapping
Shr - Performs a right shift that does not panic.
- Wrapping
Sub - Performs subtraction that wraps around on overflow.
- Zero
- Defines an additive identity element for
Self
.
Functions§
- abs
- Computes the absolute value.
- abs_sub
- The positive difference of two numbers.
- cast
- Cast from one machine scalar to another.
- checked_
pow - Raises a value to the power of exp, returning
None
if an overflow occurred. - clamp
- A value bounded by a minimum and a maximum
- clamp_
max - A value bounded by a maximum value
- clamp_
min - A value bounded by a minimum value
- one
- Returns the multiplicative identity,
1
. - pow
- Raises a value to the power of exp, using exponentiation by squaring.
- signum
- Returns the sign of the number.
- zero
- Returns the additive identity,
0
.