I've been toying around with RcppEigen and I was curious what was the best
way to create a random matrix of standard normals of size n by n. I have
tried in Armadillo but ran into an error. Would prefer to do in RcppEigen.

src <- '

Rcpp::NumericMatrix Xr(Xs);

int q = Rcpp::as<int>(ys);

int n = Xr.nrow(), k = Xr.ncol();

arma::mat X(Xr.begin(), n, k, false);

arma::mat G, Y, B;

G = arma::randn(n,q);

Y = X*G;

arma::mat Q, R;

arma::qr(Q,R,Y);

 Q = Q(arma::span::all,arma::span(0,q-1));

  B = arma::trans(Q)*X;

 arma::vec d;

arma::mat u, v;

arma::svd(u, d, v, B );

 arma::mat U = Q*u;

return
Rcpp::List::create(Rcpp::Named("d")=d,Rcpp::Named("U")=U,Rcpp::Named("V")=v);'

rsvd <- cxxfunction(signature(Xs="numeric", ys="integer"), body=src, plugin=
"RcppArmadillo")


appsvd <- function(X, q) {

    .Call("rsvd", X, q, package = "RcppArmadillo")

}


[1] Error in .Call("rsvd", X, q, package = "RcppArmadillo") : C symbol name
"rsvd" not in load table

	[[alternative HTML version deleted]]

