Rules for every type
Every forward! and pullback! keeps these rules, whichever page of Writing new types it follows.
Number types
forward! must be generic in the element type of its arguments. A dual number, a Float32 or a tracked value can arrive in v, s or a field. So do not annotate Float64 or build 0.0; use zero(v), oftype and fields with type parameters.
Arguments of a pullback
In pullback!, v, s, p and history are the values forward! was given, so the values before the step. Read them, but do not write to them. Leave grads and the arguments after the role in pullback! untyped, so that the rule finds the method. A type without a pullback! still takes the rule when the local step can rebuild it.
Pointwise steps
A pointwise modifier sets blocks to (1, 1), and writes entry k of v and s from entry k only, for each k in eachindex(v).
Loop over
eachindex(v)and read parameters withparam, rather than broadcast; the:pointwisecheck ofPieceInterfacereports a broadcast.Its
Initwritess[k]from the parameters read at stratumkand time 1 and from rowkof the history only. Without anInitpullback!, its derivative is then taken stratum by stratum, and the:pointwisecheck tests it.Such a step runs under
Parallelwhen it reads and writes onlyeachindex(v)entries, and allocates nothing.
Threads
Under Threaded the steps of different strata can run at once. So a step writes only its own stratum's slots, and never to the type's fields. A mirror with an entry that is not a float array or a Ref of a number runs the reverse loop on one task; Executors says how the others are split.