I have the book on my desk as it happens, and it is a great one, but the appendix is better than I remembered, so I parceled it out:<div><br></div><div><a href="http://www.flaver.com/BoydVandenberghe_appendixC_numericalLinearAlgebra.pdf">http://www.flaver.com/BoydVandenberghe_appendixC_numericalLinearAlgebra.pdf</a> (hope this helps a few other people)</div>
<div><br></div><div>I bought the text because I like being able to write in the margins, but I'd forgotten how good even the appendices are. </div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Dec 4, 2012 at 7:01 PM, Kasper Daniel Hansen <span dir="ltr"><<a href="mailto:kasperdanielhansen@gmail.com" target="_blank">kasperdanielhansen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Tue, Dec 4, 2012 at 9:55 PM, Christian Gunning <<a href="mailto:xian@unm.edu">xian@unm.edu</a>> wrote:<br>
> What exactly do these timings show? A single call you your function?<br>
> How many calls?<br>
><br>
> Building on Romain's point: -- a portion of your function's runtime is<br>
> in memory allocation<br>
> (and you have a lot of allocations here).<br>
> If you're calling your function thousands or millions of times, then<br>
> it might pay to closely<br>
> examine your memory allocation strategies and figure out what's<br>
> temporary, for example.<br>
> It looks like you're already using copy_aux_mem = false in a number<br>
> of places, but you're<br>
> allocating a lot of objects -- of approx what size?<br>
><br>
> For example, wouldn't this work just as well with one less allocation?<br>
> arma::vec kk = t;<br>
> arma::uvec q1 = arma::find(arma::abs(tp)<h);<br>
> kk.elem(q1) = ((1-arma::pow(tp.elem(q1)/h,2))/h)*0.75;<br>
> // done with q1. let's reuse it.<br>
> q1 = arma::find(arma::abs(tp)>=h);<br>
> // was q2<br>
> kk.elem(q1).zeros();<br>
><br>
> You could potentially allocate memory for temporary working space in<br>
> R, grab it with copy_aux_mem = false, write your temp results there,<br>
> and reuse these objects in subsequent function calls. It doesn't make<br>
> sense to go to this trouble, though, if your core algorithm consumes<br>
> the bulk of runtime.<br>
><br>
> Have you looked on the armadillo notes r.e. inv? Matrix inversion has<br>
> O(>n^2). You may be aided by pencil-and-paper math here.<br>
> <a href="http://arma.sourceforge.net/docs.html#inv" target="_blank">http://arma.sourceforge.net/docs.html#inv</a><br>
<br>
</div></div>Very tangential, but I have always found appendix C of Boyd's convex<br>
optimization to be very useful on numerical linear algebra. Freely<br>
available from the author at<br>
<a href="http://www.stanford.edu/~boyd/cvxbook/" target="_blank">http://www.stanford.edu/~boyd/cvxbook/</a><br>
(very nice book, but not something you read in an evening. Appendix C<br>
is something that does not depend on anything else in the book<br>
though.)<br>
<span class="HOEnZb"><font color="#888888"><br>
Kasper<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> best,<br>
> Christian<br>
><br>
>> Dear All,<br>
>> I have tried out the first example by using RcppArmadillo, but I am not<br>
>> sure whether the code is efficient or not. And I did the comparison of the<br>
>> computation time.<br>
>><br>
>> 1) R code using for loop in R: 87.22s<br>
>> 2) R code using apply: 77.86s<br>
>> 3) RcppArmadillo by using for loop in C++: 53.102s<br>
>> 4) RcppArmadillo together with apply in R: 47.310s<br>
>><br>
>> It is kind of not so big increase. I am wondering whether I used an<br>
>> inefficient way for the C++ coding:<br>
><br>
><br>
><br>
> --<br>
> A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!<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>
_______________________________________________<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>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><i>A model is a lie that helps you see the truth.</i><div><i><br></i><div><a href="http://cancerres.aacrjournals.org/content/31/9/1173.full.pdf" target="_blank">Howard Skipper</a></div>
</div><br>
</div>