<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body text="#000000" bgcolor="#ffffff">
Hi guys, <br>
<br>
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. <br>
<br>
Any help would be greatly appreciated,<br>
Ced<br>
<br>
##########################################<br>
#### Discrete uniform variate. <br>
src <- '<br>
using namespace Rcpp ;<br>
RNGScope scope;<br>
int n = as<int>(xn); <br>
int a = as<int>(xa); <br>
int b = as<int>(xb); <br>
IntegerVector vec(n); <br>
for(int i=0; i<n; ++i) vec[i] = (int)floor(runif(i,a,b)); <br>
return vec;'<br>
cxxfun <-
cxxfunction(sig=signature(xn="numeric",xa="numeric",xb="numeric"),body=src,plugin="Rcpp",verbose=TRUE)<br>
cxxfun(10,0,10);<br>
<br>
##########################<br>
Error in compileCode(f, code, language = language, verbose =
verbose) : <br>
Compilation ERROR, function(s)/method(s) not created!
file52d217df.cpp: In function ‘SEXPREC* file52d217df(SEXPREC*,
SEXPREC*, SEXPREC*)’:<br>
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<br>
##################################################<br>
<br>
<br>
<div class="moz-signature">-- <br>
<div class="moz-signature"><font face="Times" size="3">
Cedric Ginestet <br>
Centre for Neuroimaging Sciences (L3.04) <br>
NIHR Biomedical Research Centre <br>
Department of Neuroimaging <br>
Institute of Psychiatry, Box P089 <br>
King's College London <br>
De Crespigny Park<br>
London <br>
SE5 8AF <br>
</font>
</div>
</div>
</body>
</html>