Changelog
Source:NEWS.md
RcppRoll 0.3.1 (UNRELEASED)
CRAN release: 2024-07-07
The window loops that dominate small-window calls have been rewritten branchlessly where measurement showed a win, with bit-identical results:
roll_sum()androll_mean()withna.rm = TRUErun 1.4-2.5x faster,roll_max()withna.rm = TRUE1.4-1.8x faster, and the weightedroll_median()about 1.8x faster.Matrices whose columns are too short to split into chunks are now parallelized across their columns instead, so wide matrices benefit from OpenMP too. As before, results are identical whatever the number of threads.
roll_median()now keeps large windows in a pair of heaps meeting at the median, so that sliding costs O(log n) per point rather than O(n). Windows below about two hundred observations keep the sorted-window representation, which remains faster there.roll_prod()now slides its window incrementally rather than recomputing each window in full, so its cost no longer grows with the window size. The window is carried as two stacks of partial products – departing values are never divided out, so zeros, infinities and rounding behave as a fresh multiplication would.The rolling window computations are now parallelized with OpenMP, where support for it is available. By default, the number of threads is chosen by the OpenMP runtime (e.g. via
OMP_NUM_THREADS); it can be set explicitly withoptions(RcppRoll.threads = <n>), andoptions(RcppRoll.threads = 1)disables parallelization. Work is split into chunks whose boundaries do not depend on the thread count, so results are identical whatever the number of threads – including on builds without OpenMP support at all.The new
roll_threads()function reports the number of threads in use, or NA when the package was compiled without OpenMP support. The package reports this on attach as well; suppress the startup message withoptions(RcppRoll.quiet = TRUE). Instructions for enabling OpenMP when installing from sources on macOS are in the README.-
The
partialargument is now implemented. Withpartial = TRUE, windows at the edges ofxare computed over however many elements are in range rather than filled, so the result has one element per element ofx. This matcheszoo::rollapply(partial = TRUE). (#18)partial = TRUEcannot be combined withweights, and onlyTRUEorFALSEare accepted – zoo’s numeric “minimum observations” form is not supported.filldoes not apply, and is warned about if supplied. roll_var()androll_sd()now compute a weighted variance whenweightsis supplied, rather than the variance of the weighted values. Weights are treated as frequency weights, so an equal weight vector gives the same answer as the unweighted routines. (#47)roll_var()androll_sd()now keep each weight paired with its own value whenna.rm = TRUE, instead of shifting the weights when NAs are dropped. (#47)roll_var()androll_sd()now return NA for a window holding fewer than two non-missing values, matchingvar(). Previously an all-NA window gave 0 and a single-value window gave NaN. (#47)Fixed an issue where
roll_mean()produced incorrect results when bothweightsandna.rm = TRUEwere used. The weights are now re-normalized after removing NAs. (#23)Fixed an issue where the weighted version of
roll_median()ignoredna.rm, and associated each weight with the sorted position of a value rather than with the value itself.The
roll_*()functions now warn whennandweightsare both supplied and disagree, sinceweightssilently determines the window size. (#39)
RcppRoll 0.3.1
CRAN release: 2024-07-07
- Fixed an issue where
roll_median()produced incorrect results in the presence of NAs. (#42)
RcppRoll 0.3.0
CRAN release: 2018-06-05
Properly document the
alignargument – the function accepts “center” rather than “middle”. (#28)Fixed an issue where empty fills were not handled correctly.
The interface has now been standardized such that each implemented window function has version center-aligned by default (e.g.
roll_mean()), a left-aligned version (roll_meanl()), and right-aligned version (roll_meanr()).Implement rolling window functions for
mean(),median(),min(),max(),prod(),sum(),sd()andvar().