Skip to content

C code validation

3 messages · Brian Ripley, Adrian Dusa

#
Dear R-devel,

I'm trying to validate the results from a C function, against a (trial
and tested) older R function. For reasons unknown to me, the C
function seems to give different result sometimes at each trial, even
with the very same data.

These are the relevant outputs from R:
Loading required package: lpSolve
+     index <- 0
+     while((index <- index + 1) < length(x)) {
+         x <- setdiff(x, findSubsets(y + 1, x[index], max(x)))
+     }
+     return(x)
+ }
[1] "Numeric: lengths (184, 181) differ"
[1] TRUE
[1] TRUE
[1] "Numeric: lengths (184, 173) differ"


The relevant C code can be found here:
http://codeviewer.org/view/code:287e

As I am too baffled by these (to me strange) results, any hint is much
appreciated.

Thanks very much in advance,
Adrian
#
On 27/07/2012 23:52, Adrian Du?a wrote:
See the advice in 'Writing R Extensions'.  In particular, the most 
common cause is the use of initialized values, so run under valgrind.

Also check that your C code does not change any of its arguments: if it 
does you may end up with self-modifying R code.  (That's probably rare, 
but I spent a couple of hours on such an example last night.)

  
    
#
Dear Prof. Ripley,

On Sat, Jul 28, 2012 at 7:54 AM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:
Thanks very much for this, valgrind proved to be a real asset. Thanks
to Martin Morgan as well for pointing the same thing, the issue is now
solved (the code tried to read outside the bounds of the allocated
memory).

Best wishes,
Adrian