s-news
[Top] [All Lists]

call c++ from splus

To: s-news@lists.biostat.wustl.edu
Subject: call c++ from splus
From: Tony Smith <quickcur@yahoo.com>
Date: Tue, 13 Dec 2005 14:48:43 -0800 (PST)
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=mdrSMGwL/kdfSzZ1k2xZcpncWek65AtZNMrPOT3Gltfzq2wTf0di6IGjSEbwlFTQDJMDvNoebsJqWo1BNdGZJlFB5JkN5cJ32c3HDb4LIsMpG+nx2wpCXomZuaoFr87vYg/hrDZaEegmUvEEL7TBxFuJGTCQGKxJrGrk+19zhHc= ;
I was trying to call c++ function from splus. My goal
is to pass a two dimensional array to c++ code, do
some computation and return. But I am sure how to pass
two dimensional array to splus. The example shown
bellow is for one dimensional data. I do not want to
use CSPmatrix class since it will be slower to access
the data in c++. 


c++ 
void spC(double* pdX, double* pdY, long* plLen) 
{ 
        S_EVALUATOR 


  // TODO: Replace the example code below with your
own code. 


        //Validate the input arguments 
        if((pdX == NULL) || (pdY == NULL) || plLen ==
NULL) 
                PROBLEM "Invalid input" ERROR; 


        //Perform element by element operation 
        for(long n=0; n< *plLen; n++) 
                pdY[n] = pdX[n][n] * pdX[n][n]; //The
output = the input squared 


        return; 



} 


splus 
"spC" <- 
## TODO: Help documentation 
function(x) 
{ 
        ## TODO: Modify the codes below 
        ## Example of .C() with two arguments 
        ## See sp.cxx for the C/C++ (VC++)
implementation of spC() 

        len = length(x) 
        y = .C("spC", 
                                as.double(x), 
                                y=double(len), 
                                len 
                )$y 
        y 




__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

<Prev in Thread] Current Thread [Next in Thread>