Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

call c++ from splus

0 views
Skip to first unread message

quic...@yahoo.com

unread,
Dec 13, 2005, 5:28:07 PM12/13/05
to
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
}

0 new messages