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.<br>
<div class="gmail_quote"><div class="HOEnZb"><div class="h5"><br></div><div class="h5">(Note: I'm not 100% sure why I get the error with Armadillo either)</div><div class="h5">
<br>src <- '<br><br>Rcpp::NumericMatrix Xr(Xs);<br><br>int q = Rcpp::as<int>(ys);<br><br>int n = Xr.nrow(), k = Xr.ncol();<br><br>arma::mat X(Xr.begin(), n, k, false);<br><br>arma::mat G, Y, B;<br><br>G = arma::randn(n,q);<br>

<br>Y = X*G;<br><br>arma::mat Q, R;<br><br>arma::qr(Q,R,Y);<br><br>Q = Q(arma::span::all,arma::span(0,q-1));<br><br>B = arma::trans(Q)*X;<br><br>arma::vec d;<br><br>arma::mat u, v;<br><br>arma::svd(u, d, v, B ); <br><br>
arma::mat U = Q*u;<br>
<br>return Rcpp::List::create(Rcpp::Named("d")=d,Rcpp::Named("U")=U,Rcpp::Named("V")=v);'<br><br>rsvd <- cxxfunction(signature(Xs="numeric", ys="integer"), body=src, plugin="RcppArmadillo")<br>

<br><br>appsvd <- function(X, q) {<br><br>    .Call("rsvd", X, q, package = "RcppArmadillo")<br><br>}<br><br><br>[1] Error in .Call("rsvd", X, q, package = "RcppArmadillo") : C symbol name "rsvd" not in load table<br>
<br>
</div></div></div><br>