Message-ID: <CADNH-Puah_nUjbK8rmrDtt=YU9E0mfXqkbrde+T9i-9jNPhZhw@mail.gmail.com>
Date: 2016-12-15T03:47:55Z
From: Christian Gunning
Subject: [Rcpp-devel] Rcpp ISNAN slower than C ISNAN?
In-Reply-To: <e9ee15a0-a4c7-695f-e9f1-1496e58b0082@kruisselbrink.eu>
On Wed, Dec 14, 2016 at 12:23 PM, Johannes Kruisselbrink
<johannes at kruisselbrink.eu> wrote:
>
> Good point. Actually, I didn't even realize there were so many is-nan
> functions to choose from. But indeed, we used the R-core ISNAN function on
> doubles accessed via Rcpp.
Me either :)
Of course, the above isn't particular to Rcpp, but I found that
tracking down the underlying machinery of ISNAN in the context of Rcpp
to be an interesting and useful exercise.
>> Based on the above, I added permutations to a *very* minimal test (no
>> return val, etc) that include Romain's suggestion:
>> https://github.com/helmingstay/rcpp-timings/tree/master/minimal
>> ## source('benchmarks.r')
>>
[...]
>
> Wow, thank you for the thorough comparison. I ran some tests myself based on
> your code. It seems that I cannot get the "CountNans_expr" version to
> compile, any ideas? Same problem with the Rcpp sugar isnan version.
Can you be more specific?
> The std::isnan version, however, does work and, on my machine, actually
> outperforms the call function. So performance-wise this is a very
> interesting candidate.
Just to clarify, R's NA is subset of ieee NaN. So std::isnan catches
both NAs and NaNs. If you need to manually catch *just* NAs, then it
looks like you need to return to an R-core solution (please do correct
me if I muxed this up).
Ref: https://github.com/wch/r-source/blob/trunk/src/main/arithmetic.c#L108
best,
Christian
--
A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal ? Panama!