Skip to main content

Kernel

Trait Kernel 

Source
pub trait Kernel<N>: Kernel
where N: Cell + Wired + ?Sized,
{ type Host; type Pre; const FIDELITY: Fidelity; const RATE: Rate; // Required methods fn advance<'t>( host: &'t mut Self::Host, deps: <<N as Wired>::Deps as DepSet>::Outs<'t>, ) -> <N as Cell>::Out<'t>; fn pre<'d>( host: &Self::Host, want: Want, deps: <<N as Wired>::Deps as DepSet>::Outs<'d>, ) -> Self::Pre; fn formula(pre: &Self::Pre) -> Option<&Ast>; fn jac<'d>( pre: &Self::Pre, j: Jac<'_, <<N as Wired>::Deps as DepSet>::Outs<'d>>, ) -> bool where <N as Wired>::Deps: DepFlat, <<N as Wired>::Deps as DepSet>::Outs<'d>: Copy, <N as Cell>::Out<'x>: for<'x> Flat; // Provided methods fn trace(_: &Self::Pre, _: &[f64]) -> Option<Trace> { ... } fn exact<'d>( _: &Self::Pre, _: Exact<'_, <<N as Wired>::Deps as DepSet>::Outs<'d>>, ) -> bool where <N as Wired>::Deps: DepFlat, <<N as Wired>::Deps as DepSet>::Outs<'d>: Copy, <N as Cell>::Out<'x>: for<'x> Flat { ... } }
Expand description

How a node computes, and therefore what can be read off it. Sealed: the kernel set is the framework’s, so a node’s only choice is which one it names and there is no way to supply a body the engine cannot also read.

Each kernel demands its own body trait, so naming one without the body does not compile. The split into pre and jac is what lets the two readings cost their own price: Pure captures one grad pass and nothing else, where Opaque captures the pre-advance clone its finite differences re-advance.

One trait for both node shapes. What used to be a second, run-shaped copy of it was the level side read against a different owner of the out — so Host names the owner and the rest is one declaration.

Required Associated Constants§

Source

const FIDELITY: Fidelity

How much of what the body read jac covers.

Source

const RATE: Rate

Where the node’s rate comes from (rates.node.declared).

Required Associated Types§

Source

type Host

What the sweep advances. A level node is its own host; a run node’s is the [Emitter] beside it, which owns the buffer the run is filled into and the last_period its rate is enforced against. That the storage sits here rather than in a second argument is the whole of why one trait can serve both: an out borrowed from the node and an out borrowed from the engine differ in who is lent for the tick, and naming the lender is enough to say it.

Source

type Pre

Whatever the derivative reading needs off the node before advance consumes it for the tick. Below Want::Jac every kernel captures nothing, which is what makes an unobserved sweep the bare chain.

Required Methods§

Source

fn advance<'t>( host: &'t mut Self::Host, deps: <<N as Wired>::Deps as DepSet>::Outs<'t>, ) -> <N as Cell>::Out<'t>

Source

fn pre<'d>( host: &Self::Host, want: Want, deps: <<N as Wired>::Deps as DepSet>::Outs<'d>, ) -> Self::Pre

Source

fn formula(pre: &Self::Pre) -> Option<&Ast>

The equation, where there is one — None under Want::Jac means this kernel has no algebra, not that the node did not fire.

Source

fn jac<'d>( pre: &Self::Pre, j: Jac<'_, <<N as Wired>::Deps as DepSet>::Outs<'d>>, ) -> bool
where <N as Wired>::Deps: DepFlat, <<N as Wired>::Deps as DepSet>::Outs<'d>: Copy, <N as Cell>::Out<'x>: for<'x> Flat,

Fills the Jacobian and reports whether it is exact. Called once, for a node that fired at Want::Jac. What it fills is the one-step reading — each dep’s last element perturbed, prior state held fixed — however the kernel arrived there; the derivative over a dep’s whole reach is a different quantity and is not this one (r[kernels.jac.two-quantities]).

The observation bounds sit here rather than on the trait, so a bare step — which never asks for a derivative — carries none of them.

Provided Methods§

Source

fn trace(_: &Self::Pre, _: &[f64]) -> Option<Trace>

The value-annotated reading of the body over this tick’s dep flattening, where that flattening is the env the body was read over. The default declines, which is the honest answer for a per-element kernel: its env is filled by read — wider than the deps’ own slots, and in the order the body asked for them — so a trace taken over the flattening would be evaluating the body against an env that is not the one it read (Ast::Var indexes, so it would not even be wrong quietly).

A reading rather than a flag, because every other reading the engine offers comes off this one declaration and a bool here would leave the last one being reconstructed outside.

Source

fn exact<'d>( _: &Self::Pre, _: Exact<'_, <<N as Wired>::Deps as DepSet>::Outs<'d>>, ) -> bool
where <N as Wired>::Deps: DepFlat, <<N as Wired>::Deps as DepSet>::Outs<'d>: Copy, <N as Cell>::Out<'x>: for<'x> Flat,

Fills the exact block and reports whether it did. The default fills nothing and says so — a kernel that cannot answer over a dep’s whole reach has to be able to decline rather than fabricate a block.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<E> Kernel<E> for Close
where E: Closes<Out<'x> = &'x [<E as Series>::Item]> + Emit + for<'x> Cell, <E as Series>::Item: Unflat, <E as Wired>::Deps: DepFlat,

Source§

impl<E> Kernel<E> for Fold
where E: Folds<Out<'x> = &'x [<E as Series>::Item]> + Emit + for<'x> Cell, <E as Series>::Item: Unflat, <E as Wired>::Deps: DepFlat,

Source§

const FIDELITY: Fidelity

Source§

const RATE: Rate = Rate::Lead

Source§

type Host = Emitter<E>

Source§

type Pre = Option<PerElem>

Source§

impl<E> Kernel<E> for Raw
where E: Runs<Out<'x> = &'x [<E as Series>::Item]> + Emit + for<'x> Cell,

Source§

const FIDELITY: Fidelity

Source§

const RATE: Rate = Rate::Declared

Source§

type Host = Emitter<E>

Source§

type Pre = Option<E>

Source§

impl<E> Kernel<E> for Scan
where E: Scans<Out<'x> = &'x [<E as Series>::Item]> + Emit + for<'x> Cell, <E as Series>::Item: Unflat, <E as Wired>::Deps: DepFlat,

Source§

const FIDELITY: Fidelity = Fidelity::Exact

Source§

const RATE: Rate = Rate::Lead

Source§

type Host = Emitter<E>

Source§

type Pre = Option<PerElem>

Source§

impl<N> Kernel<N> for Opaque
where N: Blind + Node,

Source§

const FIDELITY: Fidelity

Source§

const RATE: Rate = Rate::Declared

Source§

type Host = N

Source§

type Pre = Option<N>

Source§

impl<N> Kernel<N> for Predicate
where N: Decides<Out<'t> = bool> + Node + for<'t> Cell, <N as Wired>::Deps: DepFlat,

Source§

const FIDELITY: Fidelity = Fidelity::Exact

Source§

const RATE: Rate = Rate::Declared

Source§

type Host = N

Source§

type Pre = Option<Ast>

Source§

impl<N> Kernel<N> for Pure
where N: Symbolic + Node, <N as Cell>::Out<'t>: for<'t> Unflat, <N as Wired>::Deps: DepFlat,

Source§

const FIDELITY: Fidelity = Fidelity::Exact

Source§

const RATE: Rate = Rate::Declared

Source§

type Host = N

Source§

type Pre = Option<Algebra>