Repository navigation
Compile Reduce and Fold with a list, tuple or Boolean accumulator - #648
enumeratio wants to merge 2 commits into
Conversation
|
Measured on a combinatorics corpus (main 1044ec1 against this branch at 55c526c, every compiled answer re-checked against the interpreter):
"a list where a scalar is required" (1378) and "Reduce from a value that is not a real number" (101) go to 0. Nothing that compiled on main declines or changes its answer. Of the newly compiled results, all but two agree with the interpreter, and in those two the interpreter is wrong: #655, with the fix in #656. The next largest decline was a |
81df99b to
ce384c7
Compare
|
For a sense of what the interpreted path costs in that corpus (0.194.x, where these decline with "a list where a scalar is required"):
The tableaux count compiled on 0.187.1, through the older compiler. |
ReduceandFoldby a function literal now compile when the accumulator is a Boolean, a flat list of reals, integers or Booleans, or a tuple of scalars. That covers a Fibonacci pair, a constant-length array, an And/Or flag, a zero array of run-time length (Map(z -> 0, Range(1, n))), and a fold seeded withList()that appends to it. Each result equalsevaluate(); an empty collection gives the initial value.reduceBy()was a counted loop whose carried value had to be a real scalar. It is now the same loop with a carried value of the accumulator's kind, as the loop of aLoopcarries a list local written whole: a Boolean is a boolean carried value; a list of a stated length, and a tuple always, is one carried value of that length, which every step must keep; a list of a run-time length is carried as its length and then the list, with the type of the list naming the length (mapLengths), as inloop(). An integer accumulator keeps the integer lane by the same trial lowering as for scalars, and widens to reals when a step gives reals. ForList()the lane comes from the same trial (integer, then Boolean), and the initial value is an empty build. A fixed-length list whose step changes its length (aJointhat grows it) is retried as a run-time one. A fold accumulator that the body reads at a run-time index is typedindexed_collection<number>, whichJoinrefused; its binding is now marked as the carried accumulator andjoinLists()accepts such a symbol only when its binding has that mark. An input of that type still declines, as before (tested). The bigint pair is checked againstevaluate()past 2^53 (F(100)).Still declining: a tuple whose step changes its length; a list of points or a matrix as accumulator; a list of a run-time length on GLSL and in the bigint mode (as for a list local written whole); the interval mode, which declines
Reduceby a function altogether; and an emptyList()whose element type the body does not fix. The carry logic mirrorsloop()in lower.ts rather than sharing a helper, sincefitWholeandwholeLocalare tied to Bindings; happy to factor it out if you prefer. A newbigintfield in the lowering context carries the mode toreduceBy().Tests are in
test/compute-engine/compile-fold-accumulators.test.ts, each comparing the compiled run toevaluate(): the Fibonacci pair, a tuple, a constant array, a Boolean pair, the zero array,List()appends, And/Or, empty collections, and the declines. The existing fold, list-local, loop and IR profile tests still pass.Fixes #647