search for: narm

Displaying 9 results from an estimated 9 matches for "narm".

Did you mean: arm
2015 Jun 01
2
sum(..., na.rm=FALSE): Summing over NA_real_ values much more expensive than non-NAs for na.rm=FALSE? Hmm...
...sum(z, na.rm=FALSE)) user system elapsed 4.49 0.00 4.51 Following the source code, I'm pretty sure the code (https://github.com/wch/r-source/blob/trunk/src/main/summary.c#L112-L128) performing the calculation is: static Rboolean rsum(double *x, R_xlen_t n, double *value, Rboolean narm) { LDOUBLE s = 0.0; Rboolean updated = FALSE; for (R_xlen_t i = 0; i < n; i++) { if (!narm || !ISNAN(x[i])) { if(!updated) updated = TRUE; s += x[i]; } } if(s > DBL_MAX) *value = R_PosInf; else if (s < -DBL_MAX) *value = R_NegInf; else *value = (double)...
2015 Jun 01
0
sum(..., na.rm=FALSE): Summing over NA_real_ values much more expensive than non-NAs for na.rm=FALSE? Hmm...
...(on some system it's only double, cf. https://github.com/wch/r-source/blob/trunk/src/nmath/nmath.h#L28-L33), whereas my sum2() code uses double. So using long double, I can reproduce the penalty of having NA_real_ with na.rm=FALSE; > sum3 <- inline::cfunction(sig=c(x="double", narm="logical"), body=' #define LDOUBLE long double double *x_ = REAL(x); int narm_ = asLogical(narm); int n = length(x); LDOUBLE sum = 0.0; for (R_xlen_t i = 0; i < n; i++) { if (!narm_ || !ISNAN(x_[i])) sum += x_[i]; } return ScalarReal((double)sum); ') > x <- rep...
2010 Aug 23
1
Speeding up sum and prod
...(in 2.11.1 and in the development release of 2010-08-19) makes a costly call of ISNAN even when the option is na.rm=FALSE. The inner loop can also be sped up a bit in other respects. Here is the old procedure, in src/main/summary.c: static Rboolean rsum(double *x, int n, double *value, Rboolean narm) { LDOUBLE s = 0.0; int i; Rboolean updated = FALSE; for (i = 0; i < n; i++) { if (!ISNAN(x[i]) || !narm) { if(!updated) updated = TRUE; s += x[i]; } } *value = s; return(updated); } and here is my modified version: static R...
2007 Mar 03
0
2 bugs in max.col() (PR#9542)
...ue) || !value){ ties.method <- pmatch(ties.method, c("random", "first", "last")) if (is.na(ties.method)) stop("illegal ties method") ret <- .C("R_row_maxwithindex_double" , x=as.double(x) , nr=d[1] , nc=d[2] , narm = as.integer(na.rm) , index=integer(d[1]) , tiesmethod=as.integer(ties.method) , NAOK = TRUE, DUP = FALSE, PACKAGE = "base")[c("index")] i <- cbind(seq(length=d[1]), ret$index) if (is.na(value)) ret$value <- x[i] if (!is.null(index)) ret...
2001 Dec 14
2
colSums in C
Hi, all! My project today is to write a speedy colSums(), which is a function available in S-Plus to add the columns of a matrix. Here are 4 ways to do it, with the time it took (elapsed, best of 3 trials) in both R and S-Plus: m <- matrix(1, 400, 40000) x1 <- apply(m, 2, sum) ## R=16.55 S=52.39 x2 <- as.vector(rep(1,nrow(m)) %*% m) ## R= 2.39 S= 8.52 x3 <-
2003 Dec 30
1
Accuracy: Correct sums in rowSums(), colSums() (PR#6196)
...IEEE_754 mode, the patch is attached. It is intended to be applied against R-1.7.1/src/main/array.c --------- Cut here ---------- *** array.c.old Mon Dec 15 17:33:23 2003 --- array.c Mon Dec 15 17:33:45 2003 *************** *** 1016,1022 **** int OP, n, p, cnt = 0, i, j, type; Rboolean NaRm, keepNA; int *ix; ! double *rx, sum = 0.0; checkArity(op, args); x = CAR(args); args = CDR(args); --- 1016,1022 ---- int OP, n, p, cnt = 0, i, j, type; Rboolean NaRm, keepNA; int *ix; ! double *rx, sum = 0.0, correction = 0.0; checkArity(op, a...
2010 Sep 03
1
Fourteen patches to speed up R
I've continued to work on speeding up R, and now have a collection of fourteen patches, some of which speed up particular functions, and some of which reduce general interpretive overhead. The total speed improvement from these patches is substantial. It varies a lot from one R program to the next, of course, and probably from one machine to the next, but speedups of 25% can be expected in
2006 Mar 30
0
function min does not return correct result if .Machine$integer.max (PR#8732)
The code has s = INT_MAX; for (i = 0; i < n; i++) { if (x[i] != NA_INTEGER) { if (s > x[i]) { s = x[i]; if(!updated) updated = 1; } } else if (!narm) { if(!updated) updated = 1; *value = NA_INTEGER; return(updated); } } *value = s; so it ignores the initial value INT_MAX (updated is not set). Fairly easy to fix ... done for 2.3.0. There's a parallel problem with -.Machine$integer.max, also fixed. On Thu, 3...
2011 Aug 29
3
How to safely using OpenMP pragma inside a .C() function?
I am trying to parallelize part of a C function that is called from R (via .C) using OpenMP's "parallel for" pragma. I get mixed results: some runs finish with no problem, but some lead to R crashing after issuing a long error message involving memory violations. I found this post, which describes how a .Call() function can be made to avoid crashing R by raising the stack limit: