Scans and reduction functions
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 839
- Forks
- 220
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 14
Description
Related to #3339, there are also common higher-order functions that return a different type than their input.
Some common options are:
fold_left(F, T, ...) => f(f(f(f(T[0], T[1]), T[2]), ...), T[3])(sometimes, rather than starting at T[0], an extra 'init' argument is passed)fold_right, which is the same idea but with the opposite associationf(T[0], f(T[1], ...f(T[N], init)))reduce, which is defined such that it is equivalent to the above when thefis associative but does not explicitly state an order of evaluation. The cool thing aboutreduceis it can be parallelized, c.f.foldlandfoldrConsidered Slightly Harmful, and More Fun with Moniodsscan, which returns a cumulative evaluationscan(f, T, ...) => [T[1], f(T[1], T[2]), f(f(T[1], T[2]), T3), ...]. Note thatscancan also be parallelized when f is associative, c.f. Prefix Sums and their Applications. (Note: even thoughreduce(f, T, ...) == scan(f, T, ...)[N], the ideal parallelization algorithms actually differ)
There are other functions of questionable value to Stan in this family, like folding_map which returns both a carry and a mapped container (this is, confusingly, what JAX calls scan. Scans a-la Blelloch as described above are called associative_scan in JAX)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the related issue #3339, then review the proposed semantics for fold_left, fold_right, reduce, and scan and the linked references on parallel algorithms. Before implementation, clarify which functions Stan should support and their API and evaluation requirements; done means the scope is agreed and the selected functions are implemented consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100