Could the c++ slowdown be due to the fact that Rinternals.h defines ISNAN differently for C and C++? For C it uses the compiler's isnan macro, for C++ it calls the function R_isnancpp.
Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Dec 13, 2016 at 5:04 AM, Christian Gunning <x...@unm.edu> wrote: > > | 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) ? > > Or better yet, just use the original code with NumericMatrix: > sData1[i * numVars + k] does the right thing. > I don't get any timing difference based on this change. > > Using Rcpp sugar > (https://cran.r-project.org/package=Rcpp/vignettes/Rcpp-sugar.pdf), > and moving the call outside the loop, appears to do the right thing. > > ## modified example > ## see edits here: > https://github.com/helmingstay/rcpp-timings/blob/ > master/diff/rcppdist.cpp#L24 > git clone https://github.com/helmingstay/rcpp-timings > cd rcpp-timings/diff > R --vanilla < glue.R > > best, > Christian > > > > > 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 | e...@debian.org > > > > -- > A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama! > http://www.x14n.org > _______________________________________________ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel