Thanks again!<br><br><div class="gmail_quote">On Sun, Jan 30, 2011 at 4:16 PM, Dirk Eddelbuettel <span dir="ltr">&lt;<a href="mailto:edd@debian.org">edd@debian.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
Howdy,<br>
<br>
Thanks for posting here, and the kind words below.<br>
<div><div></div><div class="h5"><br>
On 30 January 2011 at 15:49, Sunny Srivastava wrote:<br>
| Dear Rcpp-List:<br>
|<br>
| I have been working on speeding my R code. A while ago, I realized that no<br>
| further vectorization would help and interacting R with C/C++/.. was absolutely<br>
| necessary. I don&#39;t program in C/C++ extensively, so the transition was a<br>
| difficult process. I tried to use the R API but the error messages were<br>
| intimidating. A few weeks ago I saw Professor Chambers presentation (pdf from<br>
| David Smith&#39;s website) about R in Stanford. I saw him mentioning Rcpp which<br>
| motivated me to try Rcpp (I confess, I am lazy to try new stuff). And I haven&#39;t<br>
| been dissapointed. Thank you very much Dirk and Romain (and other developers,<br>
| including Professor Chambers and Professor Bates).<br>
|<br>
| Rcpp reduced the length of my code considerably (like: I didn&#39;t need to bother<br>
| about PROTECT .. ) and the informative syntax (like: Rcpp::IntegerMatrix ..)<br>
| made my code more readable. These are great advantages, but the best part was<br>
| testing and compiling with the Inline package. I am a statistician; writing a C<br>
| program and then using dyn.load was the way I learned to do it in grad school.<br>
| Rcpp + inline makes this process way easier.<br>
|<br>
| Thank you for the great documentation on your webpage Dirk. It helped me a lot.<br>
|<br>
| I am still a beginner in using Rcpp and friends (2 weeks old) and have a few<br>
| miscellaneous questions. The answer to these questions may be very basic or<br>
| obvious, so please bear with me. (Dirk showed me a simple way to test things<br>
| using Rcpp + inline here -- <a href="http://stats.stackexchange.com/questions/6690/" target="_blank">http://stats.stackexchange.com/questions/6690/</a><br>
| what-is-the-difference-between-rf-dpois-in-rmath-h-and-the-dpois-that-i-use-direc<br>
| )<br>
|<br>
| 1. I have been using Rcpp + inline to test if the faster implementation gives<br>
| the right results (which is obtained from R code). I was wondering if there are<br>
| other strategies which people use to test their Rcpp code? (sorry, if this<br>
| doesn&#39;t make sense.)<br>
<br>
</div></div>No, that is precisely the best way about it: write code, and then test and<br>
profile it.<br>
<br>
A few times in the past users have posted things here that lead us to improve<br>
things down the road.  One only finds bottlenecks by testing for them.<br>
<div class="im"><br>
| 2. I have a MCMC simulation (say: foo) which uses several functions (say: fun1,<br>
| fun2). These functions (fun1, fun2) are themselves computation intensive and I<br>
| used Rcpp to speed them. Until now I do something like this:<br>
|<br>
| In R file:<br>
|<br>
| foo &lt;- function (...){<br>
|<br>
|     src1 &lt;- paste(readLines(&quot;fun1-rcpp.cpp&quot;), collapse=&quot;\n&quot;)<br>
|     RcppFun1 &lt;- cxxfunction( .., plugin=&quot;Rcpp&quot;,body=src1)<br>
<br>
</div>You probably want to write a package. That way the &#39;compilation cost&#39; is<br>
borne just once when you install the package, rather than each time its run.<br>
<br>
Doing a package may be a new step, but we try to help with documentation and<br>
existing packages. Give it a try!<br>
<div class="im"><br>
|    ## similar cpp code for fun2<br>
|<br>
|     for (i in 1:10000){<br>
|           ## use RcppFun1, RcppFun2 here<br>
|     }<br>
| }<br>
<br>
</div>It&#39;s a bit hard to say based on just this, but yes, you may be able to<br>
&#39;refactor&#39; this and regroup functions.  But no need to obsess over it.<br>
<div class="im"><br>
| I was wondering if this is OK (it already speeds up my code by zillion times)<br>
| or is there a more elegant way of doing this. I am thinking about using Rcpp to<br>
| increase the speed of foo (for more speed) but I am not too sure on how to do<br>
| this. Towards this end, I checked a few packages mentioned on Dirk&#39;s website<br>
| namely, pcaMethods. I am thinking RcppExport and .Call is the way to do this?<br>
<br>
</div>Yes. Give it try, look at some small packages and try to copy whatever<br>
package structure you may find useful.<br>
<br>
Cheers, Dirk<br>
<div class="im"><br>
<br>
| Thank you for your answers or pointers.<br>
|<br>
| S.   <br>
|<br>
</div>| ----------------------------------------------------------------------<br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<font color="#888888"><br>
--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</font></blockquote></div><br>