Skip to content

Conversation

jangorecki
Copy link
Member

@jangorecki jangorecki commented Sep 9, 2025

Two new rolling functions, towards #2778.
Supersede #5682

Optimizations

  • for min are the same as used for max
  • for prod are the same as used for mean

benchmark vs very fast roll package

library(roll)
library(data.table)
set.seed(108)
x = rnorm(1e8)
n = 1e3

## PROD
system.time(a <- roll_prod(x, n))
#   user  system elapsed 
#  1.083   0.836   1.919
system.time(b <- frollprod(x, n))
#   user  system elapsed 
#  0.822   0.384   1.209 
all.equal(a,b)
#[1] TRUE

## MIN
system.time(a <- roll_min(x, n))
#   user  system elapsed 
#  1.896   0.840   2.739
system.time(b <- frollmin(x, n))
#   user  system elapsed 
#  0.278   0.394   0.672
all.equal(a,b)
#[1] TRUE

This is for rnorm, be aware that for specific input, data.table's implementation can be much slower, see issue reported for rolling max #5923


This work was supported by the Medical Research Council, UK [grant number 1573].

Copy link

github-actions bot commented Sep 9, 2025

  • HEAD=froll-min-prod stopped early for isoweek improved in #7144
    Comparison Plot

Generated via commit 227b39e

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 2 minutes and 59 seconds
Installing different package versions 21 seconds
Running and plotting the test cases 2 minutes and 38 seconds

Copy link

codecov bot commented Sep 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.09%. Comparing base (ed2f36f) to head (227b39e).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7299      +/-   ##
==========================================
+ Coverage   99.08%   99.09%   +0.01%     
==========================================
  Files          83       83              
  Lines       15781    16052     +271     
==========================================
+ Hits        15636    15907     +271     
  Misses        145      145              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

}
}

static inline void wmin(const double * restrict x, uint64_t o, int k, double * restrict w, uint64_t *iw, bool narm) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big fan of macros but couldn't we do something like and deduplicate wmin and wmax?

#define DEFINE_WINDOWFUN(fname, init_val, op)
DEFINE_WINDOWFUN(wmax, R_NegInf, >=)
DEFINE_WINDOWFUN(wmin, R_PosInf, <=)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be, one reason not to is reduced code coverage

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same holds for frollmaxFast and frollmaxExact

Copy link
Member Author

@jangorecki jangorecki Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same holds for frollmaxFast and frollmaxExact

frollmax Fast vs. Exact does not have that much in common, you possibly meant froll Min vs Max

as for the main functions, to turn them into macros would require __func__ handling as well. Additionally it would reduce clarify of code, and friendliness for code editors.

As for the helper functions wmin, wmax, IMO it indeed make sense, but maybe better as a follow up. So this PR will be focused more on adding new things rather than refactoring previous ones.

@jangorecki jangorecki merged commit 5975ffd into master Sep 14, 2025
12 checks passed
@jangorecki jangorecki deleted the froll-min-prod branch September 27, 2025 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants