[Rcpp-devel] Inf to NA.
Dirk Eddelbuettel
edd at debian.org
Tue Dec 21 18:41:30 CET 2010
On 21 December 2010 at 17:24, Cedric Ginestet wrote:
| Dear Rcpp experts,
|
| When passing a vector/argument with infinite values to a C++ function, the R
| wrapper returns NA's. [See the code below] Is there a way around this to ensure
| that infinite values are preserved from R to C++ and then from C++ to R again?
Inf and NA and NaN are defined for _floating_ point only. Please use
NumericMatrix and/or NumericVector.
R> infEcho <- cxxfunction(signature(x="list"), '
+ Rcpp::List param(x);
+ double z = Rcpp::as<double>(param["value"]);
+ return(Rcpp::wrap(z)); ', plugin="Rcpp")
R> infEcho(Inf)
Error in infEcho(Inf) : index out of bounds
R> infEcho(list(value=Inf))
[1] Inf
R> infEcho(list(value=NA))
[1] NA
R> infEcho(list(value=NaN))
[1] NaN
R>
Apologies also for an error in the last message -- I mean Rcpp::List as used
here.
Dirk
|
| ######################################
| D <- matrix(c(0,1,Inf,Inf),2,2)
| src3 <- '
| IntegerMatrix xD(D);
| IntegerVector Drow(xD.ncol());
| for(int i=0; i<xD.ncol(); i++) std::cout << xD[1,i] << std::endl;
| return xD;
| '
| rowExtraction <- cxxfunction(signature(D="matrix"),body=src3,plugin=
| "Rcpp",verbose=TRUE)
| rowExtraction(D)
| ######################################
|
| Thank you very much,
| Cedric
|
| --
| Cedric Ginestet
| Centre for Neuroimaging Sciences (L3.04)
| NIHR Biomedical Research Centre
| Department of Neuroimaging
| Institute of Psychiatry, Box P089
| King's College London
| De Crespigny Park
| London
| SE5 8AF
| Tel: (+44) 20-3228-3052
| Fax: (+44) 20-3228-2116
| Email: cedric.ginestet at kcl.ac.uk
|
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list