Function rust_examples::dispatch::gradient_descent_dynamic[][src]

pub fn gradient_descent_dynamic(
    f: &dyn Differentiable,
    max_iters: usize,
    eta: f64
) -> f64
Expand description

Gradient Descent that finds a minimum of a dynamically defined function f on given interval.

Dynamic dispatch means that the actual type of f (or more precisely of the grad method) is determined at runtime. Call f.grad(x) is indirect via a vtable - a lookup table that holds memory addresses of grad methods for each type implementing Differentiable.

Contrary to the statically dispatched version, this implementation f only provides the public interface defined by Differentiable trait. Moreover any inlining on dyn traits is ignored.