Article View: aus.stats.s
Article #224call c++ from splus
From: quickcur
Date: Tue, 13 Dec 2005 22:28
Date: Tue, 13 Dec 2005 22:28
41 lines
2166 bytes
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
}
Technical Details
Message-ID:
<1134512887.153430.94800@f14g2000cwb.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: fa931,31f67d5dbecb3d04,start X-Google-Attributes: gidfa931,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail From: "quickcur@yahoo.com" <quickcur@yahoo.com> Newsgroups: aus.stats.s Subject: call c++ from splus Date: 13 Dec 2005 14:28:07 -0800 Organization: http://groups.google.com Lines: 42 Message-ID: <1134512887.153430.94800@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: 192.146.1.16 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1134512892 1028 127.0.0.1 (13 Dec 2005 22:28:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 13 Dec 2005 22:28:12 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 ca1cache06 (NetCache NetApp/5.5R5D9) Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=192.146.1.16; posting-account=zinbigwAAACrhhHlTCipbyBFtD730-Xu