Crates.io | dfo |
lib.rs | dfo |
version | 0.1.0-beta.5 |
source | src |
created_at | 2022-11-16 16:16:02.546868 |
updated_at | 2022-11-23 11:55:03.822487 |
description | Differentiable Floating-point Operations in Rust. |
homepage | |
repository | https://github.com/jeertmans/dfo |
max_upload_size | |
id | 716573 |
size | 56,726 |
⚠ This crate is very much in progress and should not be used as if!
If you want to contribute, or ask a question, please contact me through GitHub issues.
The DFO crate aims at making your already existing code differentiable, leveraging automatic differentiation.
As for automatic differentiation, this crate is made of two separate parts:
forward
] module;backward
] module.As their name implies, the former implements forward-mode automatic differentiation, while the latter implements backward-mode.
NOTE: if you are new to automatic differentation, I recommend you to read this excellent article from Max Slater's blog.
Next, each of those modules is split in (at least) two submodules: primitive and generic.
The primitive module implements a given differentiation mode on primitive types, e.g., [f32
] with [forward::DFloat32
].
use dfo::forward::primitive::*;
let f = |x| { x * x + 1.0 - x };
let df = |x| { 2.0 * x - 1.0 };
let x = DFloat32::var(4.0);
assert_eq!(f(x).deriv(), df(x).value());
The generic module implements a given differentiation mode on generic types. For the latter, we recommend using the num_traits::Float
trait, for example. Primitive types are usually better optimized (no useless copy, faster compilation time), and recommended unless you want to work with external crates, as ndarray
.
The following crate feature flags are available. They are configured in your Cargo.toml
.
libm
: enables num-traits/libm
featurenum-traits
: supports for (most) traits defined in num-traits
(enabled by default)std
: Rust standard library-using functionality (enabled by default)serde
: serialization support for serde
1.xDFO has two main objectives. It has to be:
[TL;DR] Is this create stable? It it production-ready?
No, and maybe not until a long time.
Currently, the following modules are implemented:
primitive
generic
Here is a small TO-DO list of things that I would like to work on:
primitive
, forward
and backward