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
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Reply via email to