🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by quickcur Tue, 13 Dec 2005 22:28
call c++ from splus
#224
Author: quickcur
Date: Tue, 13 Dec 2005 22:28
41 lines
2166 bytes
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
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads