I am sorry that I was abusing this list. My point is 1) First, this code works for me for some simulation cases. I repeated the simulation 1000 times, which then called this Rcpp function 1000 times at least. And this code worked perfectly. 2) But in some other simulation case (here what I mean by simulation case, just change some parameters to produce the data, but the data formats are the same.), when I repeated the simulation 1000 times, at some point, for example, at the 298th simulation, it did not work. Then in order to see what is the problem, I just did the 298th simulation separately (since I set the seed, it used the same data), but it worked well in this case. Then I really have no idea what is going on there.
Best wishes! Honglang Wang Office C402 Wells Hall Department of Statistics and Probability Michigan State University 1579 I Spartan Village, East Lansing, MI 48823 wangh...@msu.edu On Thu, Dec 13, 2012 at 10:06 PM, Dirk Eddelbuettel <e...@debian.org> wrote: > > Honglang, > > You are now abusing the free facilities offered by this list. Your > examples > are not self-contained [ no sample data or simulated data ] and hence not > reproducible. Your code is complex, and not motivated. And we have told > you > REPEATEDLY to shorten your code to chunks until it works. > > On 13 December 2012 at 21:15, Honglang Wang wrote: > | I have no idea what's this error. > > My best guess is that we already explained this to you, but you are not > really reading our replies all that closely. Here is a hint: repeatedly > calling an R function is probably not the smartest thing to do in an > otherwise complex and hard to decipher program. [1] > > | I am just wondering whether I need to free some memory in this code. > > You are also making it pretty clear that you don't really know what you are > doing with C++, or else you would not ask this question (and the earlier > email people were to polite to reply to). > > I suggest that you take a deep breath, go for a walk and once you're back, > start learning about C++. > > So please stop emailing the list unless you have something more substantial > to post or ask -- and follow common courtesy and list etiquette. > > Right now you are wasting your time, as well as the time of a few hundred > list subscribers. Stop now. > > Dirk > > > [1] Just to be plain: Calling a function repeatedly is not per se a bad > thing. Complete example below. > > > ----------------------------------------------------------------------------- > #include <Rcpp.h> > > using namespace Rcpp; > > // [[Rcpp::export]] > double foo(Function f, NumericVector x) { > double r = 0.0; > for (int i=0; i<100; i++) > r += as<double>(f(x)); > return r; > } > > > /*** R > x <- 1:10 > foo(mean, x) > ***/ > > ----------------------------------------------------------------------------- > > Here is the result from the 100 calls: > > R> sourceCpp("/tmp/fun.cpp") > > R> x <- 1:10 > > R> foo(mean, x) > [1] 550 > R> > > > As expected... > > > > > -- > Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com >
_______________________________________________ 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