Repository navigation
Plan cumulative functions of a logical tree - #461
Merged
Merged
Conversation
# Conflicts: # r-package/dtatools/NEWS.md
# Conflicts: # r-package/dtatools/NEWS.md
# Conflicts: # r-package/dtatools/NEWS.md
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A planned arithmetic tree of a grouped
mutate()orfilter()takescumsum(),cummax()andcummin()of a Stata numeric operand, as ADR 0085 allows. Of a comparison, such as the running countcumsum(b5 == 1), the tree went to the loop. The comparison gives a bare logical vector, and each group's evaluation calledOps.dta_numeric()and base'scumsum(). Over the 42,739 women in the first 100,000 rows of the India 2021 DHS births file,mutate(b, c = cumsum(b5 == 1), .by = caseid)took about 0.30 seconds, where a tibble takes about 0.060.This PR lets the tree take
cumsum(),cummax()andcummin()of a logical tree, which gives a bare integer vector for each group. The call must find base's primitive, which dispatches on no bare logical vector. The native evaluator computes the running count, maximum or minimum of the logical values as integers, missing from the first missing value on, as the primitive does. A logical vector no longer thanINT_MAXcannot overflowcumsum()'s integer.The result may be the whole expression of a
mutate(), or compare with a bare number, as the positions fromrow_number()do under ADR 0099. The comparison gives a logical tree thatmutate()andfilter()take.Behavior
Results are unchanged. ADR 0123 records the decision. Arithmetic of the counts, a summary of them, and
abs()or the rounding functions of a logical vector, which give other types, still go to the loop.Timing
Best of three runs in fresh R sessions, in seconds, with the builds interleaved, over the first 100,000 rows of the India 2021 DHS births file. Before is main.
mutate(b, c = cumsum(b5 == 1), .by = caseid)filter(b, cumsum(b5 == 0) <= 1, .by = caseid)Tests
.byand bygroup_by(). The columns' missing and tagged missing values make the rest of a group's results missing. It also runs other logical trees, nested counts, comparisons of the counts with a number inmutate()andfilter(), andbetween()as the tree. Each case must give what the loop gives, and the plan must take every one.cumsum, arithmetic of the counts,abs()of a comparison,cumsum(n() > 1), asummarise()and rowwise data.