Skip to content

Commit

Permalink
forder3 (#3162)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdowle committed Nov 28, 2018
1 parent 55168ed commit 05c0d45
Show file tree
Hide file tree
Showing 5 changed files with 681 additions and 422 deletions.
12 changes: 7 additions & 5 deletions R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -1464,11 +1464,13 @@ chmatch2 <- function(x, table, nomatch=NA_integer_) {
if (!bysameorder && identical(byindex,FALSE)) {
if (verbose) {last.started.at=proc.time();cat("Finding groups using forderv ... ");flush.console()}
o__ = forderv(byval, sort=!missing(keyby), retGrp=TRUE)
# The sort= argument is called sortStr at C level. It's just about saving the sort of unique strings at
# C level for efficiency (cgroup vs csort) when by= not keyby=. All other types are always sorted. Getting
# orginal order below is the part that retains original order. Passing sort=TRUE here always won't change any
# result at all (tested and confirmed to double check), it'll just make by= slower when there's a large
# number of unique strings. It must be TRUE when keyby= though, since the key is just marked afterwards.
# The sort= argument is called sortGroups at C level. It's primarily for saving the sort of unique strings at
# C level for efficiency when by= not keyby=. Other types also retain appearance order, but at byte level to
# minimize data movement and benefit from skipping subgroups which happen to be grouped but not sorted. This byte
# appearance order is not the same as the order of group values within by= columns, so the 2nd forder below is
# still needed to get the group appearance order. Always passing sort=TRUE above won't change any result at all
# (tested and confirmed), it'll just make by= slower. It must be TRUE when keyby= though since the key is just
# marked afterwards.
# forderv() returns empty integer() if already ordered to save allocating 1:xnrow
bysameorder = orderedirows && !length(o__)
if (verbose) {
Expand Down
24 changes: 11 additions & 13 deletions R/timetaken.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
timetaken <- function(started.at)
{
if (!inherits(started.at,"proc_time")) stop("Use started.at=proc.time() (faster) not Sys.time() (POSIXt and slow)")
secs = proc.time()[3L] - started.at[3L]
mins = as.integer(secs) %/% 60L
hrs = mins %/% 60L
days = hrs %/% 24L
mins = mins - hrs * 60L
hrs = hrs - days * 24L
if (secs > 60.0) {
res = if (days>=1L) paste0(days," day", if (days>1L) "s " else " ") else ""
paste0(res,sprintf("%02d:%02d:%02d", hrs, mins, as.integer(secs) %% 60L))
} else {
sprintf(if (secs >= 10.0) "%.1fsec" else "%.3fsec", secs)
}
if (!inherits(started.at,"proc_time")) stop("Use started.at=proc.time() not Sys.time() (POSIXt and slow)") # nocov
format = function(secs) {
if (secs > 60.0) {
secs = as.integer(secs)
sprintf("%02d:%02d:%02d", secs%/%3600L, (secs%/%60L)%%60L, secs%%60L)
} else {
sprintf(if (secs >= 10.0) "%.1fs" else "%.3fs", secs)
}
}
tt = proc.time()-started.at # diff all 3 times
paste0(format(tt[3L])," elapsed (", format(tt[1L]), " cpu)")
}

9 changes: 5 additions & 4 deletions cc.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sourceDir <- function(path=getwd(), trace = TRUE, ...) {
if(trace) cat("\n")
}

cc = function(test=TRUE, clean=FALSE, debug=FALSE, cc_dir=Sys.getenv("CC_DIR"), CC="gcc") {
cc = function(test=TRUE, clean=FALSE, debug=FALSE, omp=!debug, cc_dir=Sys.getenv("CC_DIR"), CC="gcc") {
stopifnot(is.character(CC), length(CC)==1L, !is.na(CC), nzchar(CC))
gc()

Expand All @@ -59,10 +59,11 @@ cc = function(test=TRUE, clean=FALSE, debug=FALSE, cc_dir=Sys.getenv("CC_DIR"),
setwd(file.path(cc_dir,"src"))
cat(getwd(),"\n")
if (clean) system("rm *.o *.so")
OMP = if (omp) "" else "no-"
if (debug) {
ret = system(sprintf("MAKEFLAGS='-j CC=%s PKG_CFLAGS=-fno-openmp CFLAGS=-std=c99\\ -O0\\ -ggdb\\ -pedantic' R CMD SHLIB -d -o data.table.so *.c", CC))
ret = system(sprintf("MAKEFLAGS='-j CC=%s PKG_CFLAGS=-f%sopenmp CFLAGS=-std=c99\\ -O0\\ -ggdb\\ -pedantic' R CMD SHLIB -d -o data.table.so *.c", CC, OMP))
} else {
ret = system(sprintf("MAKEFLAGS='-j CC=%s CFLAGS=-fopenmp\\ -std=c99\\ -O3\\ -pipe\\ -Wall\\ -pedantic' R CMD SHLIB -o data.table.so *.c", CC))
ret = system(sprintf("MAKEFLAGS='-j CC=%s CFLAGS=-f%sopenmp\\ -std=c99\\ -O3\\ -pipe\\ -Wall\\ -pedantic' R CMD SHLIB -o data.table.so *.c", CC, OMP))
# TODO add -Wextra too?
}
if (ret) return()
Expand All @@ -86,5 +87,5 @@ cc = function(test=TRUE, clean=FALSE, debug=FALSE, cc_dir=Sys.getenv("CC_DIR"),
invisible()
}

dd = function()cc(FALSE,debug=TRUE,clean=TRUE)
dd = function(omp=FALSE)cc(FALSE,debug=TRUE,omp=omp,clean=TRUE)

Loading

0 comments on commit 05c0d45

Please sign in to comment.