Re: [R] Optimizing C code

2010-01-23 Thread Christophe Genolini
Duncan Murdoch a écrit : On 22/01/2010 12:52 PM, Christophe Genolini wrote: Thanks both of you. Inf - Inf [1] NaN So isn't the line 9 useless ? If either x[i] or y[i] are NA, then dev will be NA and !ISNAN(dev) will detect it... Sothe loop cool be 8.for(i = 0 ; i taille ; i++) {

[R] Optimizing C code

2010-01-22 Thread Christophe Genolini
Hi the list, I need to write some efficient distances function, so I read the code for the Euclidean distance. I do not understand the purpose of the line 11 : if x[i] and y[i] are not NA (line 9), can dev be NA ? Christophe #define both_FINITE(a,b) (R_FINITE(a) R_FINITE(b)) #define

Re: [R] Optimizing C code

2010-01-22 Thread Romain Francois
Bonjour Christophe, NA and NaN are different things... Actually this is tricky because NA is implemented as a special kind of NaN : See this extract of R_ext/Arith.h : int R_IsNA(double); /* True for R's NA only */ int R_IsNaN(double);/* True for special NaN, *not*

Re: [R] Optimizing C code

2010-01-22 Thread Duncan Murdoch
Christophe Genolini wrote: Hi the list, I need to write some efficient distances function, so I read the code for the Euclidean distance. I do not understand the purpose of the line 11 : if x[i] and y[i] are not NA (line 9), can dev be NA ? As Romain said, the test is for NaN as well as

Re: [R] Optimizing C code

2010-01-22 Thread Christophe Genolini
Thanks both of you. Inf - Inf [1] NaN So isn't the line 9 useless ? If either x[i] or y[i] are NA, then dev will be NA and !ISNAN(dev) will detect it... Sothe loop cool be 8.for(i = 0 ; i taille ; i++) { 10.dev = (x[i] - y[i]); 11.if(!ISNAN(dev)) { 12. dist +=

Re: [R] Optimizing C code

2010-01-22 Thread Henrik Bengtsson
A side note: The NA vs NaN does not seem to play a role here, because: #define both_non_NA(a,b) (!ISNAN(a) !ISNAN(b)) So, it is the same type of test used in line 9 and in line 11. /Henrik On Fri, Jan 22, 2010 at 9:52 AM, Christophe Genolini cgeno...@u-paris10.fr wrote: Thanks both of you.

Re: [R] Optimizing C code

2010-01-22 Thread Duncan Murdoch
On 22/01/2010 12:52 PM, Christophe Genolini wrote: Thanks both of you. Inf - Inf [1] NaN So isn't the line 9 useless ? If either x[i] or y[i] are NA, then dev will be NA and !ISNAN(dev) will detect it... Sothe loop cool be 8.for(i = 0 ; i taille ; i++) { 10.dev = (x[i] -