<div dir="ltr"><div class="gmail_quote">Hi all,</div><div class="gmail_quote"><br><div dir="ltr"><div>I was wondering if there is a technical reason that element-wise matrix operations between Rcpp's Matrix type aren't implemented.  There is vector/vector, vector/scalar and matrix/scalar but no matrix/matrix.  The following naive code:</div><div><br></div><div>#include <Rcpp.h></div><div>using namespace Rcpp;</div><div><br></div><div>NumericMatrix operator+(NumericMatrix A, NumericMatrix B) {</div><div>  if ((A.nrow() != B.nrow()) | (A.ncol() != B.ncol()))</div><div>    stop("Dimensions of the two matrices do not conform!");</div><div>  NumericVector vA = as<NumericVector>(A);</div><div>  NumericVector vB = as<NumericVector>(B);</div><div>  NumericVector vC = vA + vB;</div><div>  NumericMatrix C = NumericMatrix(A.nrow(), A.ncol(), vC.begin());</div><div>  return C;</div><div>}</div><div><br></div><div>// [[Rcpp::export]]</div><div>NumericMatrix MatAdd(const NumericMatrix A, const NumericMatrix B) {</div><div>  return A+B;</div><div>}</div><div><br></div><div>works.  From my brief fiddling it seems there is no copying going on above so I don't think there is too much extra overhead in the abstraction.  My guess is that it just hasn't been a priority and "patches happily accepted" is the answer but I'm curious if there is some other less obvious reason as it seems to me all the heavy lifting was done to implement vector/vector.</div><div><br></div><div>Many thanks,</div><div>Jason</div><div><br></div></div>
</div><br></div>