fix/258-getcommonChunk code in C++#342
Conversation
|
thanks, but this seems overly complex (300+ lines of C++) |
|
Okay, I'll do it
…On Mon, 29 Jun 2026, 20:45 Toby Dylan Hocking, ***@***.***> wrote:
*tdhock* left a comment (animint/animint2#342)
<#342 (comment)>
thanks, but this seems overly complex (300+ lines of C++)
is it possible to simplify? (I was expecting <100 lines of C++ code to
review, maybe I was being too optimistic though?)
—
Reply to this email directly, view it on GitHub
<#342?email_source=notifications&email_token=BCA4SQILXJKASH2I2JBP5FL5CKBX7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBTGQYTANBZHA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#issuecomment-4834104985>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCA4SQLDGN6B4VWARQFUMZD5CKBX7AVCNFSNUABEKJSXA33TNF2G64TZHMZDANZQHE3TQNZ3JFZXG5LFHM2DONRUGA2DOMJSGGQXMAQ>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/BCA4SQOW353TAQA6MTQYNR35CKBX7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBTGQYTANBZHA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/BCA4SQMPCXWIOP74WOGKTPT5CKBX7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIOBTGQYTANBZHA22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #342 +/- ##
==========================================
+ Coverage 69.14% 73.10% +3.96%
==========================================
Files 163 165 +2
Lines 6002 8951 +2949
==========================================
+ Hits 4150 6544 +2394
- Misses 1852 2407 +555
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| chunk.vars <- "showSelected" | ||
| col.name.vec <- c("x", "y", "colour") | ||
| setkeyv(built, c("group", chunk.vars)) | ||
| r_dt <- with( |
There was a problem hiding this comment.
Hi @Nishita-shah1 , could you confirm that with() block is not changing the animint2.use.cpp value globally? If it changed on global scope, later cpp_dt is still using R implementation.
|
|
||
| SEXP scalar_at(SEXP v, int i) { | ||
| switch (TYPEOF(v)) { | ||
| case REALSXP: return Rf_ScalarReal(REAL(v)[i]); |
There was a problem hiding this comment.
Is Rf_ScalarReal() returning an R object? If it returns R object, is it necessary to add these objects to R's protection stack to keep those away from R's garbage collector?
Since the loop in common_value_for_group_subset_cpp keeps allocating more scalars using scalar_at(), which can trigger R's GC, it would collect the unprotected scalars. Later scalars_to_vector can read freed memory.
Summary
Fixes #258 by adding a small C++ fast path for common-column detection inside
getCommonChunk().New file:
src/get_common_chunk.cpp(~154 lines)Exported function:
common_value_for_group_subset_cpp(value_lists)For one
(column, group), given values split by chunk subset (e.g. eachshowSelectedlevel), it checks whether those values are identical across chunks. This mirrors R'scommon_value_for_group_subset()(matrix / NA / scalar logic from PR #242).Architecture: R still groups columns and groups via
detect_common_value_dt(). C++ only accelerates the inner compare. No change to TSV format, public API,geom-.r, oranimint.js.What this PR adds
src/get_common_chunk.cppsrc/RcppExports.cpp,R/RcppExports.RR/z_animintHelpers.Rcommon_value_for_group_subset()calls C++ when compiled; R fallback viaoptions(animint2.use.cpp)tests/testthat/test-compiler-getCommonChunk.Rvignettes/get-common-chunk-cpp.RmdDESCRIPTION,NAMESPACE,NEWS.md,.ci/atime/tests.RC++ design (review-friendly)
detect_common_value_dt()common_value_for_group_subset_cpp()getCommonChunk(),split_recursive(),saveChunks()Internal C++ helpers:
is_na_at,eq_at,scalar_at,wrap_common(correct R list shape forcommoncolumn).Documentation
Vignette:
vignettes/get-common-chunk-cpp.RmdAfter install:
vignette("get-common-chunk-cpp", package = "animint2")Motivation
After PRs #242 and #255,
getCommonChunk()is correct but the inner compare (matrix + NA handling) runs in R for every(column, group, chunk subset). This PR moves that hot inner loop to C++ while keeping grouping in R for a small, reviewable diff.Design highlights
Rf_Scalar*- Windows / R 4.5+ compatible C APIwrap_common()- returnslist(common = list(vector), is.common = ...)matching R shapedcast,split_recursive,saveChunksQuick test
Requires Rtools on Windows for first
load_all().