[Rcpp-devel] Rcpp ISNAN slower than C ISNAN?

Dirk Eddelbuettel edd at debian.org
Mon Dec 12 15:55:05 CET 2016


Why do you do this:

On 12 December 2016 at 14:35, Ron Wehrens wrote:
| double RcppDist(NumericMatrix sData1,
|    NumericMatrix sData2,
|    int numObjects,
|    int numVars,
|    int numCodes) {
|    int i, j, k;
|    double dist, tmp, mindist,
|      *data = REAL(sData1),
|      *codes = REAL(sData2);
|    mindist = 10000.0;
| 
|    for (i = 0; i < numObjects; i++) {
|      for (j = 0; j < numCodes; j++) {
|        dist = 0;
|        for (k = 0; k < numVars; k++) {
|          if (!ISNAN(data[i * numVars + k])) {
|            tmp = data[i * numVars + k] - codes[j * numVars + k];

Why not drop data and codes and use  sData1(i,k) - sData2(j,k)  ?

That still doesn't explain the slowdowns though.  Could you prepare a
_complete_ yet minimal example along with mock data?

Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list