<div dir="ltr">Not a question here, but a note.  Earlier there was an email about filling a NumericMatrix row by row.<div class="gmail_quote"><div dir="ltr"><div><div><div><div><br><a href="http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-March/005390.html" target="_blank">http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-March/005390.html</a><br>


<br></div><div>I noticed that for Rcpp 0.10.2 it was possible to fill a NumericMatrix with NumericVectors, but since Rcpp 0.10.3 it does so while printing out some lines.</div><div><br></div><div>As recommended, I have switched to using Armadillo matrices, which doesn't print out these lines.</div>

<div><br></div><div style>-Mike<br> </div><div>example with NumericMatrix, fill a matrix mat0 by row with the vector vec0:<br></div><div><br><div style="margin-left:40px">library(Rcpp)<br>library(inline)<br>code <- '<br>

   Rcpp::NumericMatrix mat(mat0);<br>   Rcpp::NumericVector vec(vec0);<br>
   for (int i = 0; i < mat.nrow(); i++) {<br>      mat(i,_) = vec;<br>   }<br>   return Rcpp::wrap(mat);<br>'<br>f <- cxxfunction(signature(mat0="numeric",vec0="numeric"),code,plugin="Rcpp")<br>


mat0 <- matrix(c(1:4),nrow=2)<br>vec0 <- c(5,6)<br>f(mat0,vec0)<br><br></div>produces:<br></div><div><div style="margin-left:40px"><br>MatrixRow::get_parent_index(int = 0), parent_nrow = 2 >> 0<br>MatrixRow::get_parent_index(int = 1), parent_nrow = 2 >> 2<br>


MatrixRow::get_parent_index(int = 0), parent_nrow = 2 >> 0<br>MatrixRow::get_parent_index(int = 1), parent_nrow = 2 >> 2<br>     [,1] [,2]<br>[1,]    5    6<br>[2,]    5    6<br><br><br></div>Example with Armadillo:<br>


<br><div style="margin-left:40px">arma.code <- '<br>   arma::mat mat = Rcpp::as<arma::mat>(mat0);<br>   arma::rowvec vec = Rcpp::as<arma::rowvec>(vec0);<br>   for (int i = 0; i < mat.n_rows; i++) {<br>


      mat.row(i) = vec;<br>   }<br>   return Rcpp::wrap(mat);<br>'<br>arma.f <- cxxfunction(signature(mat0="numeric",vec0="numeric"),arma.code,plugin="RcppArmadillo")<br>arma.f(mat0,vec0)<br>


<br></div>produces:<br><br><div style="margin-left:40px">     [,1] [,2]<br>[1,]    5    6<br>[2,]    5    6<br><br><br></div>> sessionInfo()<br>R Under development (unstable) (2013-03-20 r62335)<br>Platform: x86_64-unknown-linux-gnu (64-bit)<br>


<br>locale:<br>[1] C<br><br>attached base packages:<br>[1] stats     graphics  grDevices utils     datasets  methods   base     <br><br>other attached packages:<br>[1] RcppArmadillo_0.3.800.1 inline_0.3.11           Rcpp_0.10.3            <br>


[4] Defaults_1.1-1          BiocInstaller_1.9.8    <br><br>loaded via a namespace (and not attached):<br>[1] tools_3.1.0<br></div><div><div style="margin-left:40px"><br></div></div></div></div></div></div>
</div><br></div>