Expand description

Operator implementations for Traces

These implementations are written here but Rust docs will display them on the Trace struct page.

Traces of any Numeric type (provided the type also implements the operations by reference as described in the numeric module) implement all the standard library traits for addition, subtraction, multiplication and division, so you can use the normal + - * / operators as you can with normal number types. As a convenience, these operations can also be used with a Trace on the left hand side and a the same type that the Trace is generic over on the right hand side, so you can do

use easy_ml::differentiation::Trace;
let x: Trace<f32> = Trace::variable(2.0);
let y: f32 = 2.0;
let z: Trace<f32> = x * y;
assert_eq!(z.number, 4.0);

or more succinctly

use easy_ml::differentiation::Trace;
assert_eq!((Trace::variable(2.0) * 2.0).number, 4.0);

Traces of a Real type (provided the type also implements the operations by reference as described in the numeric module) also implement all of those extra traits and operations. Note that to use a method defined in a trait you have to import the trait as well as have a type that implements it!