Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions interactive/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ The pair structure `(key, val)` calls out first how the data are organized, and

A currently unfortunate amount of symbolic load is in shuffling around fields of collection elements.
The `map` operator applies to each record, and the `->` fragment is an expression converting the input to the output.
`flatmap` gives a `List((key, val))` of complete rows, choosing both keys and values.
A zero-or-one-element list drops or keeps a row; `match` builds only the selected arm.
For positions, explicitly zip a list `l` with its range: `((0, l len) range, l) zip`.
The language is a small interpreted columnar language with ADTs, and is at the moment a bit esoteric (the `inject` verb puts data within an enum variant).

</details>
Expand Down
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/authored/plans/bi01.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let total = sums | filter(((_, _, _, _, c), _) -> (c, 0) eq)
| join_function(((rid, _, _, _, _), n) -> ((rid, ()), (0), n) enlist) | count;
let ranked = groups | map(((rid, year, kind, cat), (n, s)) -> (rid, (year, kind, cat, n, s)))
| join(total, (rid, (year, kind, cat, n, s), all) -> (rid, ((year neg, kind, cat), (n, s, all))))
| collect | flatmap((_, entries) -> entries);
| collect | flatmap((k, entries) -> (k, ((0, entries len) range, entries) zip) cap_list);
let answer = ranked | map((rid, (rank, ((neg_year, kind, cat), (n, s, all)))) -> ((rid, rank),
(neg_year neg, kind, cat, n, (s to_float, n to_float) div, s, ((n, 100) mul to_float, all to_float) div)));

Expand Down
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/authored/plans/bi12.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let counted = chosen | map(((rid, who, _), ()) -> ((rid, who), ())) | count;
let perhead = counted + ((everyone - (everyone | join(counted, (key, z, _) -> (key, z)))));
let people = perhead | map(((rid, _), n) -> ((rid, n), ())) | count;
let ranked = people | map(((rid, n), p) -> (rid, (p neg, n neg)))
| collect | flatmap((_, entries) -> entries);
| collect | flatmap((k, entries) -> (k, ((0, entries len) range, entries) zip) cap_list);
let answer = ranked | map((rid, (rank, (np, nn))) -> ((rid, rank), (nn neg, np neg)));

output "answer" = answer | arrange;
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/authored/plans/bi19.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let best = ends | map((rid, (_, _, cost)) -> (rid, cost)) | min;
let ranked = ends | join(best, (rid, (source, node, cost), least) -> (rid, (source, node, cost, least)))
| filter((_, (_, _, cost, least)) -> (cost, least) eq)
| map((rid, (source, node, cost, _)) -> (rid, ((source, node), cost)))
| collect | flatmap((_, entries) -> entries);
| collect | flatmap((k, entries) -> (k, ((0, entries len) range, entries) zip) cap_list);
let answer = ranked | map((rid, (rank, ((source, node), cost))) -> ((rid, rank), (source, node, cost)));

output "answer" = answer | arrange;
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/authored/plans/ic11.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let jobs = circle | map(((node, rid, country, year), ()) -> (node, (rid, coun
| map((key, (company, _, _)) -> (key, company));

-- Within one person and start year, number companies by name; order puts the last name first.
let named = jobs | collect | flatmap((_, entries) -> entries);
let named = jobs | collect | flatmap((k, entries) -> (k, ((0, entries len) range, entries) zip) cap_list);
-- Top k: `reduce` sees a key's values in sort order and keeps the first k (copies capped
-- at k), emitting (rank, value). Changes below the top k produce no output.
let ranked = named | map(((rid, since, node), (pos, company)) -> (node, (rid, since, pos, company)))
Expand Down
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/authored/plans/is03.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let friend = import "graph::friend" : (int, (int, int)); -- (person, (frie
let ranked = request | map(((rid, who), ()) -> (who, rid))
| join(friend, (_, rid, (f, since)) -> (f, (rid, since)))
| join(person, (f, (rid, since), (first, last, _, _, _, _, _, _, _, _, _)) -> (rid, ((since neg, f), (first, last))))
| collect | flatmap((_, entries) -> entries);
| collect | flatmap((k, entries) -> (k, ((0, entries len) range, entries) zip) cap_list);
let answer = ranked | map((rid, (rank, ((neg, f), (first, last)))) -> ((rid, rank), (f, first, last, neg neg)));

output "answer" = answer | arrange;
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/authored/plans/is07.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let known = reply | map(((who, op), row) -> (who, (op, row)))
| map(((pair, row), ()) -> (pair, row));
let marked = (known | map(((who, _), row) -> (who, (row, 1)))) + ((reply - known) | map(((who, _), row) -> (who, (row, 0))));
let ranked = marked | join(person, (who, ((rid, id, text, created), k), (first, last, _, _, _, _, _, _, _, _, _)) -> (rid, ((created neg, who), (id, text, first, last, k))))
| collect | flatmap((_, entries) -> entries);
| collect | flatmap((k, entries) -> (k, ((0, entries len) range, entries) zip) cap_list);
let answer = ranked | map((rid, (rank, ((neg, who), (id, text, first, last, k)))) -> ((rid, rank), (id, text, neg neg, who, first, last, k)));

output "answer" = answer | arrange;
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/bi5.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ let replied = selected | map(((rid, m, creator), ()) -> (m, (rid, creator)))
let totals = (own + liked + replied) | collect
| map((k, vs) -> (k, ((0, 0, 0), vs) fold (((a0, a1, a2), (x0, x1, x2)) -> ((a0, x0) add, (a1, x1) add, (a2, x2) add))));
let scores = totals | map(((rid, creator), t) -> let (m, r, l) = t in (rid, (((m, (2, r) mul) add, (10, l) mul) add neg, creator, t)));
output "answer" = scores | collect | flatmap((_, vs) -> vs) | filter((_, (pos, _)) -> (pos, 100) lt)
output "answer" = scores | collect | flatmap((k, vs) -> (k, ((0, vs len) range, vs) zip) cap_list) | filter((_, (pos, _)) -> (pos, 100) lt)
| map((rid, (pos, (score, creator, (m, r, l)))) -> ((rid, pos), (creator, r, l, m, score neg)));
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/ic6.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ let counts = selected | map(((rid, m, tag), ()) -> ((m), (rid, tag)))
| join(tagged, (_, (rid, tag), (name)) -> ((rid, name, tag), ()))
| filter(((_, name, tag), ()) -> (name, tag) ne) | map(((rid, name, _), ()) -> ((rid, name), ())) | count;
output "answer" = counts | map(((rid, name), n) -> (rid, (n neg, name)))
| collect | flatmap((_, vs) -> vs) | filter((_, (pos, _)) -> (pos, 10) lt)
| collect | flatmap((k, vs) -> (k, ((0, vs len) range, vs) zip) cap_list) | filter((_, (pos, _)) -> (pos, 10) lt)
| map((rid, (pos, (negn, name))) -> ((rid, pos), (name, negn neg)));
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let jobs = circle | map(((node, rid, country, year), ()) -> (node, (rid, coun
| join(place, (_, (key, (company, country)), (there, _, _)) -> (key, (company, country, there)))
| filter((_, (_, country, there)) -> (country, there) eq)
| map((key, (company, _, _)) -> (key, company));
let named = jobs | collect | flatmap((_, entries) -> entries);
let named = jobs | collect | flatmap((k, entries) -> (k, ((0, entries len) range, entries) zip) cap_list);
let ranked = named | map(((rid, since, node), (pos, company)) -> (node, (rid, since, pos, company)))
| join(person, (node, (rid, since, pos, company), (first, last, _, _, _, _, _, _, _, _, _)) -> (rid, ((since, node, pos neg), (first, last, company))))
| reduce((_, vals) -> let positive = (vals map ((_, d) -> (d, 0) gt), (0, vals len) range) zip filter in let indices = ((0, (positive len, 10) min) range, positive) gather in let prefix = (indices, vals) gather in let ends = prefix map ((_, d) -> (d, 10) min) scan_add in let chosen = (prefix, ends) zip map (((item, d), end) -> let count = (d, 10) min in let before = (end, count) sub in let keep = (((10, before) sub, 0) max, count) min in ((keep, 0) gt, (item, keep))) filter in let ends = chosen map ((_, d) -> d) scan_add in (chosen, ends) zip map (((item, d), end) -> (item, ((end, d) sub, end) range) cap_list map ((item, rank) -> ((rank, item), 1))) flatten .1);
Expand Down
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/is3.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ let person = import "graph::person" : ((int), (List(int), List(int), int));
let friends = request | map(((rid, pid), ()) -> ((pid), rid))
| join(edge, (_, rid, (q, created)) -> ((q), (rid, created)))
| join(person, ((q), (rid, created), (first, last, _)) -> (rid, (created neg, q, first, last)));
output "answer" = friends | collect | flatmap((_, vs) -> vs)
output "answer" = friends | collect | flatmap((k, vs) -> (k, ((0, vs len) range, vs) zip) cap_list)
| map((rid, (pos, (negc, q, first, last))) -> ((rid, pos), (q, first, last, negc neg)));
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/snb/rel.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def keyed(source, fields, keys, keep=True):
ordered = f'{src} | map((row, ()) -> ({projection([col(n) for n in keys],refs)}, {sort}))'
out = product([*(f'item.{len(order)}.{i}' for i in range(len(source.fields))),'rank'])
if limit is None:
code = ordered+' | collect | flatmap((_, values) -> values)'
code = ordered+' | collect | flatmap((k, values) -> (k, ((0, values len) range, values) zip) cap_list)'
code += f' | map((_, (rank, item)) -> ({out}, ()))'
else:
# DD retains all candidates; the lambda copies only the best
Expand Down
2 changes: 1 addition & 1 deletion interactive/bench/ldbc/test_topk.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def program():
exports.append(f'output "{name}" = {compiler.emit(ranked)} | arrange;')
lines = [*compiler.lines, *exports, f'let values = {initial} '
'| map((row, ()) -> (row.0, (row.1, row.2, row)));',
'let baseline = values | collect | flatmap((_, vals) -> vals) '
'let baseline = values | collect | flatmap((k, vals) -> (k, ((0, vals len) range, vals) zip) cap_list) '
'| filter((_, (rank, _)) -> (rank, 20) lt);',
'output "baseline" = baseline | map((key, value) -> ((key, value.0), value.1)) | arrange;']
for name, (buckets, hash_key) in VARIANTS.items():
Expand Down
3 changes: 1 addition & 2 deletions interactive/examples/aoc2023/day03/part1.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ labels: {

-- digit cells adjacent to a symbol
let symnbrs = symbols
| flatmap(_ -> [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)])
| map(((r, col), (_, (dr, dc))) -> (((r, dr) add, (col, dc) add), ())) | distinct;
| flatmap(((r, col), _) -> ((r, col), [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)]) cap_list map (((r, col), (dr, dc)) -> (((r, dr) add, (col, dc) add), ()))) | distinct;

let active_runs = labels::label
| map(((r, col, s), _) -> ((r, col), s)) | join(symnbrs, ((r, _), s, _) -> ((r, s), ())) | distinct;
Expand Down
3 changes: 1 addition & 2 deletions interactive/examples/aoc2023/day03/part2.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ labels: {
let labelcells = labels::label | map(((r, col, s), _) -> ((r, col), s));

let gearnbrs = gears
| flatmap(_ -> [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)])
| map(((r, col), (_, (dr, dc))) -> (((r, dr) add, (col, dc) add), (r, col)));
| flatmap(((r, col), _) -> ((r, col), [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1)]) cap_list map (((r, col), (dr, dc)) -> (((r, dr) add, (col, dc) add), (r, col))));
-- (nbr_cell, gear)

let pairs = gearnbrs
Expand Down
3 changes: 1 addition & 2 deletions interactive/examples/aoc2023/day15/part1.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ let chars = input 0 : ((int, int, int), ()) | map(((r, pos, code), ()) -> ((r, p
let lens = chars | map(((r, _), _) -> (r, ())) | count; -- (r, len)

let ktab = chars | map(_ -> ((), ())) | distinct
| flatmap(_ -> (0, 34) range)
| map((_, (_, k)) -> ((), k));
| flatmap(_ -> (0, 34) range map (k -> ((), k)));
-- ((), k)

hash: {
Expand Down
3 changes: 1 addition & 2 deletions interactive/examples/aoc2023/day15/part2.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ let ops = input 0 : ((int, int, int, int, int), ())
| map(((r, l1, l2, op, d), ()) -> (r, (l1, l2, ((op, 61) eq, (d, 48) sub, 0) select)));

let ktab = ops | map(_ -> ((), ())) | distinct
| flatmap(_ -> (0, 34) range)
| map((_, (_, k)) -> ((), k));
| flatmap(_ -> (0, 34) range map (k -> ((), k)));

let opsk = ops | map((r, (l1, l2, f)) -> ((l1, l2), (r, f))); -- ((l1,l2), (r, op))
let dels = opsk | filter((_, (_, f)) -> (f, 0) eq) | map((l, (r, _)) -> (l, (1000000, r) sub)) | min
Expand Down
3 changes: 1 addition & 2 deletions interactive/examples/aoc2023/day16/part1.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ let shift = cells | map(_ -> ((), ())) | distinct | flatmap(_ -> [
(1, 124, 1, 0, 3), (1, 124, -1, 0, 2), (1, 47, 1, 0, 3), (1, 92, -1, 0, 2),
(2, 46, -1, 0, 2), (2, 45, 0, 1, 0), (2, 45, 0, -1, 1), (2, 124, -1, 0, 2),
(2, 47, 0, 1, 0), (2, 92, 0, -1, 1), (3, 46, 1, 0, 3), (3, 45, 0, 1, 0),
(3, 45, 0, -1, 1), (3, 124, 1, 0, 3), (3, 47, 0, -1, 1), (3, 92, 0, 1, 0) ])
| map((_, (_, (d, s, dr, dc, nd))) -> ((d, s), (dr, dc, nd)));
(3, 45, 0, -1, 1), (3, 124, 1, 0, 3), (3, 47, 0, -1, 1), (3, 92, 0, 1, 0) ] map ((d, s, dr, dc, nd) -> ((d, s), (dr, dc, nd))));
-- ((dir, sym), (dr, dc, newdir))

beam: {
Expand Down
3 changes: 1 addition & 2 deletions interactive/examples/aoc2023/day16/part2.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ let shift = cells | map(_ -> ((), ())) | distinct | flatmap(_ -> [
(1, 124, 1, 0, 3), (1, 124, -1, 0, 2), (1, 47, 1, 0, 3), (1, 92, -1, 0, 2),
(2, 46, -1, 0, 2), (2, 45, 0, 1, 0), (2, 45, 0, -1, 1), (2, 124, -1, 0, 2),
(2, 47, 0, 1, 0), (2, 92, 0, -1, 1), (3, 46, 1, 0, 3), (3, 45, 0, 1, 0),
(3, 45, 0, -1, 1), (3, 124, 1, 0, 3), (3, 47, 0, -1, 1), (3, 92, 0, 1, 0) ])
| map((_, (_, (d, s, dr, dc, nd))) -> ((d, s), (dr, dc, nd)));
(3, 45, 0, -1, 1), (3, 124, 1, 0, 3), (3, 47, 0, -1, 1), (3, 92, 0, 1, 0) ] map ((d, s, dr, dc, nd) -> ((d, s), (dr, dc, nd))));

let rows = cells | map(((r, _), _) -> (r, ())) | distinct;
let cols = cells | map(((_, c), _) -> (c, ())) | distinct;
Expand Down
3 changes: 1 addition & 2 deletions interactive/examples/aoc2023/day18/part1.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ let n = s | join(perim, (_, a, b) -> ((), (a, b) add));
-- ((), |S| + P), even; halve by binary decomposition (no division)

let powtab = instr | map(_ -> ((), ())) | distinct
| flatmap(_ -> [549755813888, 274877906944, 137438953472, 68719476736, 34359738368, 17179869184, 8589934592, 4294967296, 2147483648, 1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1])
| map((_, (i, p)) -> (i, p));
| flatmap(_ -> let l = [549755813888, 274877906944, 137438953472, 68719476736, 34359738368, 17179869184, 8589934592, 4294967296, 2147483648, 1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1] in ((0, l len) range, l) zip);
-- (i, 2^(39-i))

halve: {
Expand Down
3 changes: 1 addition & 2 deletions interactive/examples/aoc2023/day18/part2.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ let n = s | join(perim, (_, a, b) -> ((), (a, b) add));
-- ((), |S| + P), even; halve by binary decomposition (no division)

let powtab = instr | map(_ -> ((), ())) | distinct
| flatmap(_ -> [549755813888, 274877906944, 137438953472, 68719476736, 34359738368, 17179869184, 8589934592, 4294967296, 2147483648, 1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1])
| map((_, (i, p)) -> (i, p));
| flatmap(_ -> let l = [549755813888, 274877906944, 137438953472, 68719476736, 34359738368, 17179869184, 8589934592, 4294967296, 2147483648, 1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216, 8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536, 32768, 16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1] in ((0, l len) range, l) zip);
-- (i, 2^(39-i))

halve: {
Expand Down
2 changes: 1 addition & 1 deletion interactive/examples/programs/ast.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let lists = rows
) append));

-- one row per element, carrying its position
let exploded = lists | flatmap((_, l) -> l);
let exploded = lists | flatmap((k, l) -> (k, ((0, l len) range, l) zip) cap_list);

-- bucket by (position, magnitude); payload folds a four-element list, wrapped in a variant
-- and matched straight back out (the tag is the point, not the payload).
Expand Down
2 changes: 1 addition & 1 deletion interactive/examples/programs/tour.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let tagged = edges
let folded = edges
| map((a, b) -> (a, (a enlist, b enlist, 7 enlist) append))
| map((k, l) -> (k, ((0, l) fold ((acc, x) -> (acc, x) add), l len)));
let nested = edges | flatmap((a, b) -> (b enlist, a enlist) append) | collect;
let nested = edges | flatmap(row -> let (a, b) = row in let l = (b enlist, a enlist) append in (row.0, ((0, l len) range, l) zip) cap_list) | collect;

-- Reducers.
let counted = edges | count;
Expand Down
2 changes: 1 addition & 1 deletion interactive/examples/programs/unnest.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let rows = input 0 : ((int, int), ()) | map(((a, b), ()) -> (a, (a enlist, b enlist, (a, b) add enlist) append));
-- rows: (a, [a, b, a+b])

let exploded = rows | flatmap((_, l) -> l);
let exploded = rows | flatmap((k, l) -> (k, ((0, l len) range, l) zip) cap_list);
-- one row per element: (a, (pos, elem))

let regrouped = exploded | collect;
Expand Down
2 changes: 1 addition & 1 deletion interactive/examples/server/programs/arrange_idem.ddp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let elems = node | map((id, _) -> (id, id)); -- id ; id (s
-- canonicalized through the current class map, then regrouped into a signature
let pc = node
| map((id, (op, cs)) -> ((id, op), cs))
| flatmap((_, cs) -> cs)
| flatmap((k, cs) -> (k, ((0, cs len) range, cs) zip) cap_list)
| map(((id, op), (pos, child)) -> (child, (id, op, pos))); -- (child, (id, op, pos))

-- nodes that produce an arrangement (op 1 = Arrange, op 2 = Reduce)
Expand Down
45 changes: 26 additions & 19 deletions interactive/src/backend/corgi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,29 +183,36 @@ fn apply_ops(mut c: CC, ops: &[LinearOp], level: Level, plans: &[Plan]) -> CC {
}
LinearOp::FlatMap(_) => {
let g = plan.graph(&kshape, &vshape);
// Structural explode: the evaluated list column's FLAT element storage already
// IS the new value column, so the elements never move. Each row's span in the
// bounds gives both the within-row position (DDIR's `$1[0]`) and a repeat map
// carrying key/time/diff across. No per-row eval, no transcode.
// The flat element storage is already the output rows. Repeat only time/diff.
let (bounds, elems) =
corgi::eval_graph(g, CValue::Prod(vec![c.keys.clone(), c.vals])).into_list("flatmap list").unwrap();
let ends: Vec<usize> = bounds.to_vec();
let total = ends.last().copied().unwrap_or(0);
let (mut reps, mut pos) = (Vec::with_capacity(total), Vec::with_capacity(total));
let mut start = 0usize;
for (row, end) in ends.into_iter().enumerate() {
for p in 0..(end - start) {
reps.push(row);
pos.push(p as i64);
corgi::eval_graph(g, CValue::Prod(vec![c.keys, c.vals])).into_list("flatmap list").unwrap();
let mut row = elems.into_prod("flatmap row").unwrap();
let vals = row.pop().unwrap();
let keys = row.pop().unwrap();
// Enlist's uniform 1:1 case can retain the original metadata columns.
if bounds.strided() == Some(1) {
c = CorgiContainer { keys, vals, times: c.times, diffs: c.diffs };
continue;
}
let ends = bounds.to_vec();
let mut start = 0;
let zero_or_one = ends.iter().all(|&end| {
let len = end - start;
start = end;
len <= 1
});
let mut reps = Vec::with_capacity(ends.last().copied().unwrap_or(0));
start = 0;
for (r, end) in ends.into_iter().enumerate() {
if zero_or_one {
if end != start { reps.push(r); }
} else {
reps.extend(std::iter::repeat_n(r, end - start));
}
start = end;
}
CorgiContainer {
keys: gather(&c.keys, &reps),
vals: CValue::Prod(vec![CValue::i64(pos), elems]),
times: c.times.gather(&reps),
diffs: reps.iter().map(|&r| c.diffs[r]).collect(),
}
CorgiContainer { keys, vals, times: c.times.gather(&reps),
diffs: reps.iter().map(|&r| c.diffs[r]).collect() }
}
};
}
Expand Down
Loading
Loading