<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jan 31, 2014 at 1:14 PM, French, Joshua <span dir="ltr"><<a href="mailto:JOSHUA.FRENCH@ucdenver.edu" target="_blank">JOSHUA.FRENCH@ucdenver.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="font-size:14px;font-family:Cambria,sans-serif;word-wrap:break-word"><div><div><div>Hello everyone,</div><div>
<br></div><div>For those of you who have used the sparse matrix capabilities of Armadillo/RcppArmadillo, how seamless are the operations in moving between sparse and dense matrices?  I know there are some tricks for getting sparseMatrix objects into SpMat objects (Dirk has a nice Rcpp Gallery post on this), but is it just as easy when it comes to doing Linear Algebra? My google ninja skills didn't seem to produce any helpful information.</div>
<div><br></div><div>E.g., if A is a dense matrix and B is a sparse matrix in Armadillo, it is pretty much seamless to do calculations like A + B, A*B, solve(B, A), etc.?  </div></div></div></div></blockquote><div><br></div>
<div>I'm not that familiar with the sparse matrix capabilities of Armadillo but I do know those of Eigen fairly well.  Operations on sparse matrices require more care and thought than do those on dense matrices.  It is possible to use "one size fits all" algorithms but they can be slow or inaccurate compared to more specialized approaches to operations like solve(B,A).  For dense matrices you could use an LU factorization or a QR factorization on a symmetric B and never notice the difference relative to using a Cholesky factorization.  With sparse matrices you could notice the difference.</div>
<div><br></div><div>Operations like A + B would not be terribly meaningful because the result would be dense if A is dense so you may as well extract a dense version of B and use that.  A * B is definitely available in Eigen and I imagine also available with Armadillo.  A general solve(B, A) could be written using a sparse LU but that may not be an effective way of solving such a system.  Most sparse matrix operations have a symbolic phase and a numeric phase.  In the symbolic phase the problem is analyzed to determine the positions of the nonzeros in the result and possibly auxiliary information such as a fill-reducing permutation.  Often if you need to solve several systems of the same form but with different numerical values you can save and update the factorization rather than starting from scratch each time.</div>
<div><br></div><div>This is why I prefer Eigen which has classes representing factorizations in addition to the one-shot methods.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="font-size:14px;font-family:Cambria,sans-serif;word-wrap:break-word"><div><div><div><br></div><div>I'm trying to decide whether it would be worth it to convert my code from R using sparseMatrix objects (Matrix package) to a C++ equivalent using RcppArmadillo.  On the same topic, would it be easier/more difficult if I used RcppEigen instead?</div>
<div><br></div><div>Thanks,</div><div><br></div><div>Joshua</div><span class="HOEnZb"><font color="#888888"><div><div style="font-family:Calibri,sans-serif">-- </div><div><div><font face="Cambria">Joshua French, Ph.D.</font></div>
<div><span style="font-family:Cambria">Assistant Professor</span></div><div><span style="font-family:Cambria">Department of Mathematical and Statistical Sciences</span></div><div><font face="Cambria">University of Colorado Denver</font></div>
<div><font face="Cambria"><a href="mailto:Joshua.French@ucdenver.edu" target="_blank">Joshua.French@ucdenver.edu</a></font></div><div><font face="Cambria"><a href="http://math.ucdenver.edu/~jfrench/" target="_blank">http://math.ucdenver.edu/~jfrench/</a></font></div>
<div><span style="font-family:Cambria">Ph:  <a href="tel:303-315-1709" value="+13033151709" target="_blank">303-315-1709</a>  Fax:  <a href="tel:303-315-1701" value="+13033151701" target="_blank">303-315-1701</a></span></div>
</div></div></font></span></div></div></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></blockquote></div><br></div></div>