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

Christian Gunning xian at unm.edu
Tue Dec 13 14:04:39 CET 2016


> |    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 | edd at debian.org
>

-- 
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!
http://www.x14n.org


More information about the Rcpp-devel mailing list