[Rcpp-devel] "=" work in mathematical mode (if th0=th1 then th1=th0 and viceversa) not in"informatical mode (assigment) like i want ..WHY??

bbonit at tin.it bbonit at tin.it
Sun Jun 24 16:09:32 CEST 2012


 

sorry for my stupid questions but the question is one : im ignorant but i know some one could help me.
Why This  appen?   pay attention  please for the following code. In this there is  a  loop  for (int k=0; k<n; k++) {
th1[k]=th0[k];
    }    tha have the meaning of th0=th1  (like assigmant meaning)      if i put in the code th0=th1  instead of the loop  
this dont work....(the "=" work in "mathematical" mode Also the code that prof Douglas suggets   in the post  "call  R function" in rcccp  (that Prof Douglas attach  file labelled " foo") me  have the same problem   so maby could be a bug of rccp??  or is my ignorance  ?? ( i suspect the second option)
i think my code  could  be wrong but.....the prof  Douglas's code is corrrect .....(" Douglas"  is the "gold standard"  for me)

require(inline)
code <- '
RNGScope scope;
NumericVector start_= as<NumericVector>(start);

int n=Rf_length(start_);
int N = as<int>(nsim);
NumericVector tune = as<NumericVector>(scale);

NumericVector init (n);
NumericVector th0 (n);
NumericVector th1 (n);
NumericMatrix store(N,n);
NumericVector acount (n);
NumericVector f0;
NumericVector f1;
Function ltd(fun);
int i,j;
init = start_;
bool u;
for( i=0; i<n; i++ ){
th0[i]   = init[i];
                    }
f0=ltd(th0);  

for (i=0; i<N; i++) {
  for (j=0; j<n; j++) {

  for (int k=0; k<n; k++) {
th1[k]=th0[k];
     }

     th1[j] = Rf_rnorm(th0[j],tune[j]);
     f1=ltd(th1); 
      u= Rf_runif(0.0,1.0) <= exp(f1[0] - f0[0]);
         if(u) {th0[j] = th1[j];
                   f0=ltd(th0); 
                   f0=f1;
                   acount[j]++;
                   }
       store(i,j)=th0[j];
                   }
}
return  List::create (Named("sim") = store, Named("acount") = acount);
'

AM<- cxxfunction(signature(fun="function",start="numeric",nsim="numeric",scale="numeric"),
code,  plugin="Rcpp") 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120624/109ce8b6/attachment.html>


More information about the Rcpp-devel mailing list