<div dir="ltr">Hello,<div><br></div><div>I think I (superficially) understand the difference between:</div><div><br></div>// [[Rcpp::export]]<br>double sum1(Rcpp::NumericMatrix M) {<br>    arma::mat A(M.begin(), M.rows(), M.cols(), false);<br>
    return sum(sum(A));<br>}<br><br><br>// [[Rcpp::export]]<br>double sum2(arma::mat A) {<br>    return sum(sum(A));<br>}<br><div><br></div><div>Partly out of laziness, partly because sum2 is more elegant, and partly to avoid namespace pollution, I was wondering if there is a way to "force" a "shallow" copy in sum2.</div>
<div><br></div><div>If not, then may I submit a low priority feature request. An attribute? Some thing like:</div><div><br></div><div>// [[Rcpp::export]]<br>double sum2(arma::mat A) {</div><div>    // [[ Rcpp::shallow ( A ) ]]<br>
    return sum(sum(A));<br>}<br></div><div><br></div><div>Or (akin to C++11 generalized attributes)</div><div><br></div><div><div>// [[Rcpp::export]] { [[ Rcpp::shallow ( A ) ]] }<br>double sum2(arma::mat A) {</div><div>    return sum(sum(A));<br>
}</div></div><div><br></div><div>An alternative is to have an argument in sourceCpp that takes a list/vector of objects that are to be shallow or deep copied.</div><div><br></div><div>For example in sum1, if M is changed within the function before casting to the arma::mat, then might be cleaner to add M to a list/vector of objects to be deep copied rather than cloning M within sum1: leads to one fewer variable name.</div>
<div><br></div><div>Just a thought. I can certainly live with the additional step. As always, thanks for all the Rcpp goodness.</div><div><br></div><div>Cheers,</div><div>Changi Han</div></div>