[Rd] C code validation

Adrian Duşa dusa.adrian at gmail.com
Sat Jul 28 00:52:32 CEST 2012


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:


> library(QCA)
Loading required package: lpSolve
> benchmark <- function(x, y) {
+     index <- 0
+     while((index <- index + 1) < length(x)) {
+         x <- setdiff(x, findSubsets(y + 1, x[index], max(x)))
+     }
+     return(x)
+ }
>
> set.seed(12345)
> exprnec <- sort(sample(13:19683, 500))
> noflevels <- rep(2, 9)
> mbase <- rev(c(1, cumprod(rev(noflevels + 1))))[-1]
> foo1 <- benchmark(exprnec, noflevels)
> foo2 <- .Call("removeRedundants", exprnec, noflevels, mbase)
>
> all.equal(foo1, foo2)
[1] "Numeric: lengths (184, 181) differ"
>
>
> set.seed(12345)
> exprnec <- sort(sample(13:19683, 500))
> foo2 <- .Call("removeRedundants", exprnec, noflevels, mbase)
> all.equal(foo1, foo2)
[1] TRUE
>
>
> set.seed(12345)
> exprnec <- sort(sample(13:19683, 500))
> foo2 <- .Call("removeRedundants", exprnec, noflevels, mbase)
> all.equal(foo1, foo2)
[1] TRUE
>
>
> set.seed(12345)
> exprnec <- sort(sample(13:19683, 500))
> foo2 <- .Call("removeRedundants", exprnec, noflevels, mbase)
> all.equal(foo1, foo2)
[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

-- 
Adrian Dusa
Romanian Social Data Archive
1, Schitu Magureanu Bd.
050025 Bucharest sector 5
Romania
Tel.:+40 21 3126618 \
       +40 21 3120210 / int.101
Fax: +40 21 3158391



More information about the R-devel mailing list