[Rcpp-devel] Cast for output of Rcpp Sugar runif()
Cedric Ginestet
c.ginestet05 at googlemail.com
Wed Apr 13 13:19:53 CEST 2011
Hi guys,
I want to produce discrete uniform variates within C++ from the runif()
function available through Rcpp Sugar. However, I don't seem to be able
to find the appropriate cast in order to return an IntegerVector as
opposed to a numeric one. I have naively used int(), but this is clearly
not sufficient.
Any help would be greatly appreciated,
Ced
##########################################
#### Discrete uniform variate.
src <- '
using namespace Rcpp ;
RNGScope scope;
int n = as<int>(xn);
int a = as<int>(xa);
int b = as<int>(xb);
IntegerVector vec(n);
for(int i=0; i<n; ++i) vec[i] = (int)floor(runif(i,a,b));
return vec;'
cxxfun <-
cxxfunction(sig=signature(xn="numeric",xa="numeric",xb="numeric"),body=src,plugin="Rcpp",verbose=TRUE)
cxxfun(10,0,10);
##########################
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created!
file52d217df.cpp: In function 'SEXPREC* file52d217df(SEXPREC*, SEXPREC*,
SEXPREC*)':
file52d217df.cpp:37: error: invalid cast from type
'Rcpp::sugar::SugarMath_1<true, double, double, Rcpp::Vector<14>, double
(*)(double)>' to type 'int' make: *** [file52d217df.o] Error 1
##################################################
--
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110413/9ce5a9d2/attachment.htm>
More information about the Rcpp-devel
mailing list