[Rcpp-devel] Error with sugar dnorm;

Romain Francois romain at r-enthusiasts.com
Thu Nov 25 14:39:35 CET 2010


Le 24/11/10 20:03, Andrew Redd a écrit :
> OK that fixed that problem. Thanks.
>
>   but now I have another.
>
> This is the defined model and function in question.
> SEXP gpubayes::data3::stepP(Rcpp::NumericVector sd){
> 	using namespace Rcpp;
> 	RNGScope scope;
> 	NumericVector rng = runif(4);
> 	NumericVector proposals = rnorm(1,0,1);
> 	prior priors[] = {pr_trans};
> 	return wrap<NumericVector>(takeStepP(&(rng[0]),&(proposals[0]),
> &(sd[0]), priors));
> }
> RCPP_MODULE(GPU_BAYES){
> 	using namespace Rcpp;
> 	class_<gpubayes::data3>("data3")
> 		.method("initPat",&gpubayes::data3::initPat)
> 		.method("initSwabs",&gpubayes::data3::initSwabs)
> 		.method("initAugmented",&gpubayes::data3::initAugmented)
> 		.method("setParameters",&gpubayes::data3::setParameters)
> 		.method("augmentedLogLikelihood",&gpubayes::data3::augmentedLogLikelihood)
> 		.method("dataLogLikelihood",&gpubayes::data3::dataLogLikelihood)
> 		.method("step1",&gpubayes::data3::step1)
> 		.method("step2",&gpubayes::data3::step2)
> 		.method("step3",&gpubayes::data3::step3)
> 		.method("step4",&gpubayes::data3::step4)
> 		.method("stepP",&gpubayes::data3::stepP)
> 		.method("stepG",&gpubayes::data3::stepG)
> 	;
> }
>
> But when running I get this error, it's not even making it to the compiled code.
>
> R>  d3$stepP(3) # R is the data3 object
> Error in .External(list(name = "CppMethod__invoke", address =
> <pointer: 0x13e2f40>,  :
>    negative length vectors are not allowed
>
> Thoughts?
> thanks,
> Andrew

Not sure what the problem is. Have you tried with the svn version of Rcpp ?

What is takeStepP ?

Romain

> On Wed, Nov 24, 2010 at 11:47 AM, Romain Francois
> <romain at r-enthusiasts.com>  wrote:
>> Le 24/11/10 19:38, Andrew Redd a écrit :
>>>
>>> I'm having a problem with sugar expressions that I can't figure out.
>>> I have these two functions that are sampling and prior functions for
>>> two different parameters of an MCMC model.  BTW this is part of my big
>>> CUDA project, so I pass these as pointers into other functions.
>>> ---
>>> numeric rb1(numeric a, numeric b){return Rcpp::rbeta(1,a,b)[0];}
>>> numeric pr_trans(numeric x){return Rcpp::dnorm(x,0.0, 1024.0)[0];}
>>> ---
>>> the first works fine but the second gives a compile error that
>>>>
>>>> error: no matching function for call to ‘dnorm4(numeric&, double,
>>>> double)’
>>>
>>> numeric is typedef double.   I don't see why this fails.  Any ideas?
>>>
>>> thanks,
>>> Andrew
>>
>> The first argument of dnorm is a numeric sugar expression (for example
>> NumericVector).
>>
>> Try this :
>>
>> numeric pr_trans(numeric x){return dnorm( NumericVector::create(x) ,0.0,
>> 1024.0)[0];}
>>
>> Romain
>>
>> --
>> Romain Francois
>> Professional R Enthusiast
>> +33(0) 6 28 91 30 30
>> http://romainfrancois.blog.free.fr
>> |- http://bit.ly/9VOd3l : ZAT! 2010
>> |- http://bit.ly/c6DzuX : Impressionnism with R
>> `- http://bit.ly/czHPM7 : Rcpp Google tech talk on youtube
>>
>>
>> _______________________________________________
>> 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
>>
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/9VOd3l : ZAT! 2010
|- http://bit.ly/c6DzuX : Impressionnism with R
`- http://bit.ly/czHPM7 : Rcpp Google tech talk on youtube




More information about the Rcpp-devel mailing list