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!
], and panics with a helpful error on failure.abs_diff_ne!
], and panics with a helpful error on failure.relative_eq!
], and panics with a helpful error on failure.relative_ne!
], and panics with a helpful error on failure.ulps_eq!
], and panics with a helpful error on failure.ulps_ne!
], and panics with a helpful error on failure.Structs
Enums
Traits
as
operator, which admits narrowing and precision loss.
Implementers of this trait AsPrimitive
should behave like a primitive
numeric type (e.g. a newtype around another primitive), and the
intended conversion must never fail.None
instead of wrapping around on
overflow.None
instead of panicking on division by zero and instead of
wrapping around on underflow and overflow.None
instead of wrapping around on underflow or
overflow.None
if the result can’t be represented.None
instead of panicking on division by zero and
instead of wrapping around on underflow and overflow.None
on shifts larger than
the type width.None
on shifts larger than
the type width.None
instead of wrapping around on underflow.Add
and AddAssign
with result of type Self
.Div
and DivAssign
with result of type Self
.Mul
and MulAssign
with result of type Self
.Neg
with result of type Self
.Sub
and SubAssign
with result of type Self
.(self * a) + b
with only one rounding
error, yielding a more accurate result than an unfused multiply-add.0
and 1
values,
comparisons, basic numeric operations, and string conversion.Num
types which also implement assignment operators.+=
).NumAssign
types which also implement assignment operations
taking the second operand by reference.Num
types which also implement numeric operations taking
the second operand by reference.Self
.Num
references which implement numeric operations, taking the
second operand either by value or by reference.SaturatingAdd
, SaturatingSub
and
SaturatingMul
instead.SupersetOf
as trait bound whenever
possible instead of SubsetOf
(because SupersetOf is automatically implemented whenever
SubsetOf
is).SubsetOf
trait instead of SupersetOf
whenever possible (because
SupersetOf
is automatically implemented whenever SubsetOf
is).Self
.Functions
None
if an overflow occurred.1
.0
.