Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/between.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, SEXP checkArg) {
int nprotect = 0;
R_len_t nx = length(x), nl = length(lower), nu = length(upper);
const R_len_t nx = length(x), nl = length(lower), nu = length(upper);
if (!nx || !nl || !nu)
return (allocVector(LGLSXP, 0));
const int longest = MAX(MAX(nx, nl), nu);
Expand All @@ -20,13 +20,13 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
const int longestBound = MAX(nl, nu); // just for when check=TRUE
if (!IS_TRUE_OR_FALSE(incbounds))
error(_("%s must be TRUE or FALSE"), "incbounds");
const bool open = !LOGICAL(incbounds)[0];
if (!isLogical(NAboundsArg) || LOGICAL(NAboundsArg)[0]==FALSE)
const bool open = !LOGICAL_RO(incbounds)[0];
if (!isLogical(NAboundsArg) || LOGICAL_RO(NAboundsArg)[0]==FALSE)
error(_("NAbounds must be TRUE or NA"));
const bool NAbounds = LOGICAL(NAboundsArg)[0]==TRUE;
const bool NAbounds = LOGICAL_RO(NAboundsArg)[0]==TRUE;
if (!IS_TRUE_OR_FALSE(checkArg))
error(_("%s must be TRUE or FALSE"), "check");
const bool check = LOGICAL(checkArg)[0];
const bool check = LOGICAL_RO(checkArg)[0];
const bool verbose = GetVerbose();

// check before potential coercion which ignores methods, #7164
Expand Down Expand Up @@ -70,13 +70,13 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
const int uppMask = recycleUpp ? 0 : INT_MAX;
SEXP ans = PROTECT(allocVector(LGLSXP, longest)); nprotect++;
int *restrict ansp = LOGICAL(ans);
double tic=omp_get_wtime();
const double tic=omp_get_wtime();

switch (TYPEOF(x)) {
case INTSXP: {
const int *lp = INTEGER(lower);
const int *up = INTEGER(upper);
const int *xp = INTEGER(x);
const int *lp = INTEGER_RO(lower);
const int *up = INTEGER_RO(upper);
const int *xp = INTEGER_RO(x);
if (check) for (int i=0; i<longestBound; ++i) {
const int l=lp[i & lowMask], u=up[i & uppMask];
if (l!=NA_INTEGER && u!=NA_INTEGER && l>u)
Expand All @@ -103,9 +103,9 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S

case REALSXP:
if (INHERITS(x, char_integer64)) {
const int64_t *lp = (int64_t *)REAL(lower);
const int64_t *up = (int64_t *)REAL(upper);
const int64_t *xp = (int64_t *)REAL(x);
const int64_t *lp = (const int64_t*)REAL_RO(lower);
const int64_t* up = (const int64_t*)REAL_RO(upper);
const int64_t* xp = (const int64_t*)REAL_RO(x);
if (check) for (int i=0; i<longestBound; ++i) {
const int64_t l=lp[i & lowMask], u=up[i & uppMask];
if (l!=NA_INTEGER64 && u!=NA_INTEGER64 && l>u)
Expand All @@ -128,9 +128,9 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S
}
if (verbose) Rprintf(_("between parallel processing of integer64 took %8.3fs\n"), omp_get_wtime()-tic);
} else {
const double *lp = REAL(lower);
const double *up = REAL(upper);
const double *xp = REAL(x);
const double *lp = REAL_RO(lower);
const double *up = REAL_RO(upper);
const double *xp = REAL_RO(x);
if (check) for (int i=0; i<longestBound; ++i) {
const double l=lp[i & lowMask], u=up[i & uppMask];
if (!isnan(l) && !isnan(u) && l>u)
Expand Down
9 changes: 5 additions & 4 deletions src/bmerge.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Differences over standard binary search (e.g. bsearch in stdlib.h) :
static const SEXP *idtVec, *xdtVec;
static const int *icols, *xcols;
static SEXP nqgrp;
static int ncol, *o, *xo, *retFirst, *retLength, *retIndex, *allLen1, *allGrp1, *rollends, ilen, anslen;
static int ncol, *o, *xo, *retFirst, *retLength, *retIndex, *allLen1, *allGrp1, ilen, anslen;
static const int* rollends;
static int *op, nqmaxgrp;
static int ctr, nomatch; // populating matches for non-equi joins
enum {ALL, FIRST, LAST, ERR} mult = ALL;
Expand Down Expand Up @@ -56,8 +57,8 @@ SEXP bmerge(SEXP idt, SEXP xdt, SEXP icolsArg, SEXP xcolsArg, SEXP xoArg, SEXP r
if ((LENGTH(icolsArg)==0 || LENGTH(xcolsArg)==0) && LENGTH(idt)>0) // We let through LENGTH(i) == 0 for tests 2126.*
internal_error(__func__, "icols and xcols must be non-empty integer vectors");
if (LENGTH(icolsArg) > LENGTH(xcolsArg)) internal_error(__func__, "length(icols) [%d] > length(xcols) [%d]", LENGTH(icolsArg), LENGTH(xcolsArg)); // # nocov
icols = INTEGER(icolsArg);
xcols = INTEGER(xcolsArg);
icols = INTEGER_RO(icolsArg);
xcols = INTEGER_RO(xcolsArg);
xN = LENGTH(xdt) ? LENGTH(VECTOR_ELT(xdt,0)) : 0;
iN = ilen = anslen = LENGTH(idt) ? LENGTH(VECTOR_ELT(idt,0)) : 0;
ncol = LENGTH(icolsArg); // there may be more sorted columns in x than involved in the join
Expand Down Expand Up @@ -94,7 +95,7 @@ SEXP bmerge(SEXP idt, SEXP xdt, SEXP icolsArg, SEXP xcolsArg, SEXP xoArg, SEXP r
rollabs = fabs(roll);
if (!isLogical(rollendsArg) || LENGTH(rollendsArg) != 2)
error(_("rollends must be a length 2 logical vector"));
rollends = LOGICAL(rollendsArg);
rollends = LOGICAL_RO(rollendsArg);

if (isNull(nomatchArg)) {
nomatch=0;
Expand Down
6 changes: 3 additions & 3 deletions src/cj.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SEXP cj(SEXP base_list) {
switch(TYPEOF(source)) {
case LGLSXP:
case INTSXP: {
const int *restrict sourceP = INTEGER(source);
const int *restrict sourceP = INTEGER_RO(source);
int *restrict targetP = INTEGER(target);
#pragma omp parallel for num_threads(getDTthreads(thislen*eachrep, true))
// default static schedule so two threads won't write to same cache line in last column
Expand All @@ -40,7 +40,7 @@ SEXP cj(SEXP base_list) {
}
} break;
case REALSXP: {
const double *restrict sourceP = REAL(source);
const double *restrict sourceP = REAL_RO(source);
double *restrict targetP = REAL(target);
#pragma omp parallel for num_threads(getDTthreads(thislen*eachrep, true))
for (int i=0; i<thislen; ++i) {
Expand All @@ -54,7 +54,7 @@ SEXP cj(SEXP base_list) {
}
} break;
case CPLXSXP: {
const Rcomplex *restrict sourceP = COMPLEX(source);
const Rcomplex *restrict sourceP = COMPLEX_RO(source);
Rcomplex *restrict targetP = COMPLEX(target);
#pragma omp parallel for num_threads(getDTthreads(thislen*eachrep, true))
for (int i=0; i<thislen; ++i) {
Expand Down
10 changes: 5 additions & 5 deletions src/coalesce.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ SEXP coalesce(SEXP x, SEXP inplaceArg, SEXP nan_is_na_arg) {
if (TYPEOF(x)!=VECSXP) internal_error(__func__, "input is list(...) at R level"); // # nocov
if (!IS_TRUE_OR_FALSE(inplaceArg)) internal_error(__func__, "argument 'inplaceArg' must be TRUE or FALSE"); // # nocov
if (!IS_TRUE_OR_FALSE(nan_is_na_arg)) internal_error(__func__, "argument 'nan_is_na_arg' must be TRUE or FALSE"); // # nocov
const bool inplace = LOGICAL(inplaceArg)[0];
const bool nan_is_na = LOGICAL(nan_is_na_arg)[0];
const bool inplace = LOGICAL_RO(inplaceArg)[0];
const bool nan_is_na = LOGICAL_RO(nan_is_na_arg)[0];
const bool verbose = GetVerbose();
int nprotect = 0;
if (length(x)==0 || isNull(VECTOR_ELT(x,0))) return R_NilValue; // coalesce(NULL, "foo") return NULL even though character type mismatches type NULL
Expand Down Expand Up @@ -63,7 +63,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg, SEXP nan_is_na_arg) {
for (int j=0; j<nval; ++j) {
SEXP item = VECTOR_ELT(x, j+off);
if (length(item)==1) {
int tt = INTEGER(item)[0];
int tt = INTEGER_RO(item)[0];
if (tt==NA_INTEGER) continue; // singleton NA can be skipped
finalVal = tt;
break; // stop early on the first singleton that is not NA; minimizes deepest loop body below
Expand Down Expand Up @@ -108,7 +108,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg, SEXP nan_is_na_arg) {
for (int j=0; j<nval; ++j) {
SEXP item = VECTOR_ELT(x, j+off);
if (length(item)==1) {
double tt = REAL(item)[0];
double tt = REAL_RO(item)[0];
if (ISNAN(tt)) continue;
finalVal = tt;
break;
Expand All @@ -127,7 +127,7 @@ SEXP coalesce(SEXP x, SEXP inplaceArg, SEXP nan_is_na_arg) {
for (int j=0; j<nval; ++j) {
SEXP item = VECTOR_ELT(x, j+off);
if (length(item)==1) {
double tt = REAL(item)[0];
double tt = REAL_RO(item)[0];
if (ISNA(tt)) continue;
finalVal = tt;
break;
Expand Down
Loading
Loading