Skip to content

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

3 messages · Christian Gunning, William Dunlap, Johannes Kruisselbrink

#
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

  
    
#
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 <xian at unm.edu> wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20161213/2f893f65/attachment.html>
#
Moving the call outside the main loop would be effective for some 
scenarios (i.e, the scenarios where the data objects do not contain 
NaNs). However, once they do we still want to compute a distance based 
on the values and "correct" for the NaNs in some way, so skipping the 
entire object is not really an option. Including a switch between the 
cases of objects with and objects without NaNs is probably something 
worthwhile (that and using more rcpp-sugar).

Nevertheless, the question still remains why the rcpp isNaN call is so 
much slower.
On 12/13/2016 2:04 PM, xian at unm.edu (Christian Gunning) wrote: