
Scan: carry state along dim 1, emitting per-step outputs.
g_scan.RdThe loop op behind scan_over() bodies (Kalman smoothers, EWMA, IIR
filters, cumulative custom ops). At step t, body(carry, x) gets
the current carry and the step-t slice of xs (taken along dim 1
with that unit axis dropped) and returns list(carry = , out = );
the outs are stacked into (length, ...) buffers. reverse = TRUE
runs t = length..1, still reading and writing at position t (what
a backward smoothing pass needs, e.g. Rauch-Tung-Striebel). Traced
values route to anvl::nv_scan; plain R arrays take the pure-R
reference implementation with identical semantics.
Arguments
- init
Initial carry: array or (nested) named list of arrays.
- body
Step function
function(carry, x) -> list(carry, out);outmay be an array, a (nested) list, orNULL.- xs
Per-step inputs sliced along dim 1 (array, nested list, or NULL).
- length
Static trip count; required when
xsis NULL.- reverse
Run steps in reverse order?