Re: [R] Matrix variable in C code

From: <depire_at_inrets.fr>
Date: Fri 03 Feb 2006 - 19:11:42 EST

Selon Gabor Csardi <csardi@rmki.kfki.hu>:

> On Thu, Feb 02, 2006 at 06:27:47PM +0100, depire@inrets.fr wrote:
> [...]
>
> The problem is that as.double drops the dim attribute:
> > b <- matrix( 1:4, 2, 2)
> > b
> [,1] [,2]
> [1,] 1 3
> [2,] 2 4
> > as.double(b)
> [1] 1 2 3 4
> >
>
> You can try:
>
> > b <- matrix( 1:4, 2, 2)
> > d <- dim(b)
> > b <- as.double(b)
> > b
> [1] 1 2 3 4
> > dim(b) <- d
> > b
> [,1] [,2]
> [1,] 1 3
> [2,] 2 4
>
> Another thing is that i cannot really see why the ZT parameter of the .Call
> should be a matrix anyway. It's just the vector (40 21 30 20). Or am i
> missing something?

Sorry, i made a mistake writing the small code, the correct one is the following with the correct dim for ZT. But it doesn't work...



X<-c(4,2,3,2)
Z<-c(40,21,30,20)
dX<-c(2,1,1)

dyn.load("test.so")

Phi<-function(z,a,b)
{

        Phi<-z
}

VPEfron<-function(XType,ZType,dXType,G,c0,c1) {

        ####################
        ZT<-matrix(0,3,2)
        ZT[1,1]<-Z[2]
        ZT[1,2]<-Z[4]
        ZT[2,1]<-Z[3]
        ZT[3,1]<-Z[1]
        ####################

        # A OPTIMISER
      VPCEfron<-function(f,XT,ZT,dXT,tailleS=length(XT))
      {
                f.check<-function(x) {
            x<-f(x)
            }

.Call("VPCEfron",body(f.check),as.double(XT),as.double(ZT),as.integer(dXT),as.integer(tailleS),new.env())
        }

GG<-function(z) G(z,c0,c1)

Vraisemblancepartielle<-VPCEfron(GG,XType,ZType,dXType) }

resultat<-VPEfron(X,Z,dX,Phi,0,0)


The new piece of code is between ###.

Thanks,

Alex



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Feb 03 19:20:35 2006

This archive was generated by hypermail 2.1.8 : Sat 04 Feb 2006 - 03:01:42 EST