[R] Matrix variable in C code

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


Dear all,
I try to compute some piece of my R code in C.

My problem is about matrix.

My code in R is the following:



VPEfron<-function(XType,ZType,dX,G,c0,c1)
{
	XS<-sort(XType)
	rang<-sort.list(XType)

     	ZS<-matrix(0,k,max(dX))
	ZS<-ZType[rang,]
	S<-rep(0,length(XType))
	for(i in 1:length(XType))
		S[i]<-sum(ZS[i,])

      VPCEfron<-function(f,S,ZS,dX,tailleS=length(XType))
      {
		f.check<-function(x) {
            x<-f(x)
            }
     
.Call("VPCEfron",body(f.check),as.double(S),as.double(ZS),as.integer(dX),as.integer(tailleS),new.env())
	}

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

Vraisemblancepartielle<-VPCEfron(GG,S,ZS,dX) }


and my test code in C is:



SEXP VPCEfron(SEXP f, SEXP SR, SEXP ZR, SEXP DIR, SEXP nsR, SEXP rho)
{
	int taille=INTEGER(nsR)[0];
	int* DI=INTEGER(DIR);
	double* S=REAL(SR);
	double* Z=(ZR);

// just to check the value
	printf("verifie de S: %f - %f - %f\n",S[0],S[1],S[2]);
	printf("verifie dX: %d %d %d\n",DI[0],DI[1],DI[2]);
	printf("verifie k: %d\n",taille);
	printf("verifie de Z\n");
	printf("%f %f\n",Z[0][0]);
	printf("%f %f\n",Z[1][1]);
	printf("%f %f\n",Z[2][1]);
	somme=0.0;
	printf("STOP\n");

return(somme);
}

All works, except ZS, the variable ZS is a matrix in R, and when i try to give to C code, with ZR, ZR is only a vector.

How to obtain a matrix variable in C ?



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 01:23:53 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:16 EST