<div dir="ltr">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. </div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">Bill Dunlap<br>TIBCO Software<br>wdunlap <a href="http://tibco.com" target="_blank">tibco.com</a></div></div>
<br><div class="gmail_quote">On Tue, Dec 13, 2016 at 5:04 AM, Christian Gunning <span dir="ltr"><<a href="mailto:xian@unm.edu" target="_blank">xian@unm.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">> | for (i = 0; i < numObjects; i++) {<br>
> | for (j = 0; j < numCodes; j++) {<br>
> | dist = 0;<br>
> | for (k = 0; k < numVars; k++) {<br>
> | if (!ISNAN(data[i * numVars + k])) {<br>
> | tmp = data[i * numVars + k] - codes[j * numVars + k];<br>
><br>
> Why not drop data and codes and use sData1(i,k) - sData2(j,k) ?<br>
<br>
Or better yet, just use the original code with NumericMatrix:<br>
sData1[i * numVars + k] does the right thing.<br>
I don't get any timing difference based on this change.<br>
<br>
Using Rcpp sugar<br>
(<a href="https://cran.r-project.org/package=Rcpp/vignettes/Rcpp-sugar.pdf" rel="noreferrer" target="_blank">https://cran.r-project.org/<wbr>package=Rcpp/vignettes/Rcpp-<wbr>sugar.pdf</a>),<br>
and moving the call outside the loop, appears to do the right thing.<br>
<br>
## modified example<br>
## see edits here:<br>
<a href="https://github.com/helmingstay/rcpp-timings/blob/master/diff/rcppdist.cpp#L24" rel="noreferrer" target="_blank">https://github.com/<wbr>helmingstay/rcpp-timings/blob/<wbr>master/diff/rcppdist.cpp#L24</a><br>
git clone <a href="https://github.com/helmingstay/rcpp-timings" rel="noreferrer" target="_blank">https://github.com/<wbr>helmingstay/rcpp-timings</a><br>
cd rcpp-timings/diff<br>
R --vanilla < glue.R<br>
<br>
best,<br>
Christian<br>
<br>
><br>
> That still doesn't explain the slowdowns though. Could you prepare a<br>
> _complete_ yet minimal example along with mock data?<br>
><br>
> Dirk<br>
<span class="HOEnZb"><font color="#888888">><br>
> --<br>
> <a href="http://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a><br>
><br>
<br>
--<br>
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!<br>
<a href="http://www.x14n.org" rel="noreferrer" target="_blank">http://www.x14n.org</a><br>
</font></span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a></div></div></blockquote></div><br></div>