Performance of the divide-and-conquer SVD algorithm
The ubiquitous LAPACK library provides several implementations for the singular-value decomposition (SVD). We will illustrate possible speed gains from using the divide-and-conquer method by comparing it to the base case.
[Read more...]<span>#include <RcppArmadillo.h></span> <span>// [[Rcpp::depends(RcppArmadillo)]]</span> <span>// [[Rcpp::export]]</span> <span>arma</span><span>::</span><span>vec</span> <span>baseSVD</span><span>(</span><span>const</span> <span>arma</span><span>::</span><span>mat</span> <span>&</span> <span>X</span><span>)</span> <span>{</span> <span>arma</span><span>::</span><span>mat</span> <span>U</span><span>,</span> <span>V</span><span>;</span> <span>arma</span><span>::</span><span>vec</span> <span>S</span><span>;</span> <span>arma</span><span>::</span><span>svd</span><span>(</span><span>U</span><span>,</span> <span>S</span><span>,</span> <span>V</span><span>,</span> <span>X</span><span>,</span> <span>"standard"</span><span>);</span> <span>return</span> <span>S</span><span>;</span> <span>}</span> <span>// [[Rcpp::export]]</span> <span>arma</span><span>::</span><span>vec</span> <span>dcSVD</span><span>(</span><span>const</span> <span>arma</span><span>::</span><span>mat</span> <span>&</span> <span>X</span><span>)</span> <span>{</span> <span>arma</span><span>::</span><span>mat</span> <span>U</span><span>,</span> <span>V</span><span>;</span> <span>arma</span><span>::</span><span>vec</span> <span>S</span><span>;</span> <span>arma</span><span>::</span><span>svd</span><span>(</span><span>U</span><span>,</span> <span>S</span><span>,</span> <span>V</span><span>,</span> <span>X</span><span>,</span> <span>"dc"</span><span>);</span> <span>return</span> <span>S</span><span>;</span> <span>}</span>Having the two implementations, which differ only in the method argument (added recently in Armadillo 3.930), we are ready to ...