Skip to content

seq: add an arithmetic ramp generator, and correct rep's length_out docs - #45

Open
bobjansen wants to merge 1 commit into
mainfrom
seq
Open

bobjansen wants to merge 1 commit into
mainfrom
seq

Conversation

@bobjansen

Copy link
Copy Markdown
Owner

rep tiles a pattern but never advances, so no form of it produces 0,1,2,...,N-1. Until now a row index cost two statements and a junk column: transforms require a materialized column name, so cumsum(rep(1)) inline fails with "cumsum: argument must be a column name" and you had to bind one = rep(1) first.

Table(1000)[update { i = seq(), t = seq(0.0, 0.5) }]

seq(from, by) fills that gap as a Generator, with no parser work: a FnKind::Generator row, a GeneratorExec entry, REPL completion and help. Length is always the frame's row count. Row i is computed as from + by*i rather than accumulated, so the float form does not drift.

Two things are deliberate and easy to get wrong later:

from and by are positional. infer receives only positional argument types, so a named from=0.0 would type the column Int64 and then fill it with Doubles; the kernel refuses named arguments rather than mistype. The names are also reserved keywords (KeywordFrom/KeywordBy), so seq(from=0) is a parse error and the named form cannot be written at all — the tests assert that through parser::parse, since require_ir REQUIREs a lower.

seq gets no effects.cpp entry despite sitting beside rand_* in every other registry: it is deterministic, and kEffNondet would wrongly block folding and CSE. rep is absent there for the same reason.

Also corrects SPEC 12.8: length_out was documented as if it set the output length, but N is the only value it ever accepts — anything else errors with "generates X rows but the frame has Y", in select and update alike. It is retained only for R fidelity. The docs no longer advertise the -1 sentinel or imply the length is overridable.

repl.cpp's completion array is reflowed by clang-format, since inserting one element re-pairs every subsequent line.

`rep` tiles a pattern but never advances, so no form of it produces
0,1,2,...,N-1. Until now a row index cost two statements and a junk
column: transforms require a materialized column name, so `cumsum(rep(1))`
inline fails with "cumsum: argument must be a column name" and you had to
bind `one = rep(1)` first.

    Table(1000)[update { i = seq(), t = seq(0.0, 0.5) }]

`seq(from, by)` fills that gap as a Generator, with no parser work: a
FnKind::Generator row, a GeneratorExec entry, REPL completion and help.
Length is always the frame's row count. Row i is computed as from + by*i
rather than accumulated, so the float form does not drift.

Two things are deliberate and easy to get wrong later:

`from` and `by` are positional. `infer` receives only positional argument
types, so a named `from=0.0` would type the column Int64 and then fill it
with Doubles; the kernel refuses named arguments rather than mistype. The
names are also reserved keywords (KeywordFrom/KeywordBy), so `seq(from=0)`
is a parse error and the named form cannot be written at all — the tests
assert that through parser::parse, since require_ir REQUIREs a lower.

`seq` gets no effects.cpp entry despite sitting beside rand_* in every
other registry: it is deterministic, and kEffNondet would wrongly block
folding and CSE. `rep` is absent there for the same reason.

Also corrects SPEC 12.8: `length_out` was documented as if it set the
output length, but N is the only value it ever accepts — anything else
errors with "generates X rows but the frame has Y", in select and update
alike. It is retained only for R fidelity. The docs no longer advertise
the -1 sentinel or imply the length is overridable.

repl.cpp's completion array is reflowed by clang-format, since inserting
one element re-pairs every subsequent line.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant