truncated (partial) SVD in RcppArmadillo

20 Views Asked by At

I would like to integrate my C++ code with RcppArmadillo library with an efficient function for partial Single Value Decomposition. I need to work with dense matrix and I am interested in the left singular vectors (U). I tried to use the svds function of the RcppArmadillo library converting the matrix in a spare matrix , as the code below:

// [[Rcpp::export]]
arma::mat SVDS(arma::mat X) {
  arma::mat U;
  arma::vec S;
  arma::mat V;
  arma::sp_mat Y(X);
  arma::svds(U,S,V,Y, 1,0.000001);
  return U;
}

Unfortunately, this code is not optimal, and calculating the full SVD is faster. Do you know how to improve this code?

0

There are 0 best solutions below