From 090a21bd536bf7fbff3e8c76e407301372526a22 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 29 Aug 2024 16:56:46 +0000 Subject: [PATCH] cbindlist add cbind by reference, timing R prototype of mergelist wording use lower overhead funs stick to int32 for now, correct R_alloc bmerge C refactor for codecov and one loop for speed address revealed codecov gaps refactor vecseq for codecov seqexp helper, some alloccol export on C bmerge codecov, types handled in R bmerge already better comment seqexp bmerge mult=error #655 multiple new C utils swap if branches explain new C utils comments mostly reduce conflicts to PR #4386 comment C code address multiple matches during update-on-join #3747 Revert "address multiple matches during update-on-join #3747" This reverts commit b64c0c3480fe9415bbda6729c361621e60da6e01. merge.dt has temporarily mult arg, for testing minor changes to cbindlist c dev mergelist, for single pair now add quiet option to cc() mergelist tests add check for names to perhaps.dt rm mult from merge.dt method rework, clean, polish multer, fix righ and full joins make full join symmetric mergepair inner function to loop on extra check for symmetric mergelist manual ensure no df-dt passed where list expected comments and manual handle 0 cols tables more tests more tests and debugging move more logic closer to bmerge, simplify mergepair more tests revert not used changes reduce not needed checks, cleanup copy arg behavior, manual, no tests yet cbindlist manual, export both cleanup processing bmerge to dtmatch test function match order for easier preview vecseq gets short-circuit batch test allow browser big cleanup remmove unneeded stuff, reduce diff more cleanup, minor manual fixes add proper test scripts Merge branch 'master' into cbind-merge-list comment out not used code for coverage more tests, some nocopy opts rename sql test script, should fix codecov simplify dtmatch inner branch more precise copy, now copy only T or F unused arg not yet in api, wording comments and refer issues codecov hasindex coverage codecov gap tests for join using key, cols argument fix missing import forderv more tests, improve missing on handling more tests for order of inner and full join for long keys new allow.cartesian option, #4383, #914 reduce diff, improve codecov reduce diff, comments need more DT, not lists, mergelist 3+ tbls proper escape heavy check unit tests more tests, address overalloc failure mergelist and cbindlist retain index manual, examples fix manual minor clarify in manual retain keys, right outer join for snowflake schema joins duplicates in cbindlist recycling in cbindlist escape 0 input in copyCols empty input handling closing cbindlist vectorized _on_ and _join.many_ arg rename dtmatch to dtmerge vectorized args: how, mult push down input validation add support for cross join, semi join, anti join full join, reduce overhead for mult=error mult default value dynamic fix manual add "see details" to Rd mention shared on in arg description amend feedback from Michael semi and anti joins will not reorder x columns Merge branch 'master' into cbind-merge-list spelling, thx to @jan-glx check all new funs used and add comments bugfix, sort=T needed for now Merge branch 'master' into cbind-merge-list Update NEWS.md Merge branch 'master' into cbind-merge-list Merge branch 'master' into cbind-merge-list NEWS placement numbering ascArg->order Merge remote-tracking branch 'origin/cbind-merge-list' into cbind-merge-list attempt to restore from master Update to stopf() error style Need isFrame for now More quality checks: any(!x)->!all(x); use vapply_1{b,c,i} really restore from master try to PROTECT() before duplicate() update error message in test appease the rchk gods extraneous space missing ';' use catf simplify perhapsDataTableR move sqlite.Rraw.manual into other.Rraw simplify for loop Merge remote-tracking branch 'origin/cbind-merge-list' into cbind-merge-list --- src/data.table.h | 1 + src/init.c | 1 + src/vecseq.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/data.table.h b/src/data.table.h index 26e074a3d..c4e76e3eb 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -159,6 +159,7 @@ SEXP int_vec_init(R_len_t n, int val); // vecseq.c SEXP vecseq(SEXP x, SEXP len, SEXP clamp); +SEXP seqexp(SEXP x); // uniqlist.c SEXP uniqlist(SEXP l, SEXP order); diff --git a/src/init.c b/src/init.c index 83917754a..d70780282 100644 --- a/src/init.c +++ b/src/init.c @@ -71,6 +71,7 @@ R_CallMethodDef callMethods[] = { {"Creorder", (DL_FUNC) &reorder, -1}, {"Crbindlist", (DL_FUNC) &rbindlist, -1}, {"Cvecseq", (DL_FUNC) &vecseq, -1}, +{"Cseqexp", (DL_FUNC) &seqexp, -1}, {"Csetlistelt", (DL_FUNC) &setlistelt, -1}, {"Caddress", (DL_FUNC) &address, -1}, {"CexpandAltRep", (DL_FUNC) &expandAltRep, -1}, diff --git a/src/vecseq.c b/src/vecseq.c index 707439ed4..f05d23bbe 100644 --- a/src/vecseq.c +++ b/src/vecseq.c @@ -1,7 +1,6 @@ #include "data.table.h" -SEXP vecseq(SEXP x, SEXP len, SEXP clamp) -{ +SEXP vecseq(SEXP x, SEXP len, SEXP clamp) { // Name taken from bit::vecseq, but, // * implemented in C rather than R // * takes len rather than y endpoints @@ -46,3 +45,37 @@ SEXP vecseq(SEXP x, SEXP len, SEXP clamp) return(ans); } +SEXP seqexp(SEXP x) { + // used in R/mergelist.R + // function(x) unlist(lapply(seq_along(x), function(i) rep(i, x[[i]]))) + // used to expand bmerge()$lens, when $starts does not have NAs (or duplicates?) + // replaces rep.int(indices__, len__) where indices__ was seq_along(x) + // input: 1,1,2, 1,3, 1,0,1,2 + // output: 1,2,3,3,4,5,5,5,6, 8,9,9 + // all1 returns NULL, this is now commented out to reduce overhead becase seqexp is called only when !(ans$allLen1 && (!inner || len.x==length(ans$starts))) if seqexp would be used in another place we could enable that + if (!isInteger(x)) + error("internal error: 'x' must be an integer"); // # nocov + const int *xp = INTEGER(x), nx = LENGTH(x); + int nans = 0; + for (int i=0; i