[Rcpp-devel] R.e. is std::sort function broken??

Noah Silverman noahsilverman at ucla.edu
Thu Sep 22 19:29:02 CEST 2011


I wasn't asking a C++ question.

Due to a type at 2am, (My fault), I thought there might have been a problem with Rcpp.

If you notice, I sent a redaction almost immediately after, asking everyone to ignore my previous e-mail.


--
Noah Silverman
UCLA Department of Statistics
8117 Math Sciences Building #8208
Los Angeles, CA 90095

On Sep 22, 2011, at 4:59 AM, Darren Cook wrote:

>> I think this is the current prize-winner of inappropriate use of Rcpp...
>> How about using R to sort your vector?!
> 
> There is also the fact that the array is being created ready-sorted :-).
> I assumed this was an artificially simplified example from real code. Or
> a learning toy.
> 
>> This isn't really an Rcpp question, but since you asked, .push_back()
>> is a great way to slow yourself down.
> 
> Or add data.reserve(20) [1] after creating the vector. Then push_back()
> is very quick.
> 
> BTW, apologies for replying to something off-topic. Perhaps, Noah, Stack
> Overflow would be a better place for pure-C++ questions? (Any other
> suggestions anyone?)
> 
> Darren
> 
> [1]: http://www.cplusplus.com/reference/stl/vector/reserve/
> 
>>>               std::vector<double> data;
>>> 
>>>               for(int i=0; i != 20; i++){
>>>                       data.push_back(i);
>>>               }
>>>               std::sort(data.front(), data.back());
>>>               return Rcpp::wrap(data);
> 
> 
> 
> -- 
> Darren Cook, Software Researcher/Developer
> 
> http://dcook.org/work/ (About me and my work)
> http://dcook.org/blogs.html (My blogs and articles)
> _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20110922/21dee377/attachment-0001.htm>


More information about the Rcpp-devel mailing list