<div dir="ltr"><div>I am sure there are better ways to achieve the goal. I would suggest that these two be similar if possible. I think the naive expectation is for them to be consistent.<br></div><div><br></div><div><span style="font-family:arial,sans-serif;font-size:13px">// [[Rcpp::export]]</span><br>
</div><div>stuff function(Rcpp::stuff) {</div><div>}</div><div><br></div><div><span style="font-family:arial,sans-serif;font-size:13px">// [[Rcpp::export]]</span><br></div><div><div>stuff function(arma::stuff) {</div><div>
}</div></div><div><br></div><div>Thank you again. Cheers.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 11, 2013 at 9:22 PM,  <span dir="ltr"><<a href="mailto:romain@r-enthusiasts.com" target="_blank">romain@r-enthusiasts.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Hello,<br>
<br>
This comes up every now and then, I think we can find a syntax to initiate an arma::mat that would allow what you want.<br>
<br>
It is not likely it will come via attributes. The idea is to keep them simple. The solutions I see below would eventually lead to clutter, and we are heading in the less clutter direction.<br>
<br>
I'll think about it and propose something.<br>
<br>
Romain<br>
<br>
Le 2013-07-11 14:32, Changi Han a écrit :<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I think I (superficially) understand the difference between:<br>
<br>
// [[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>
// [[Rcpp::export]]<br>
double sum2(arma::mat A) {<br>
    return sum(sum(A));<br>
}<br>
<br>
Partly out of laziness, partly because sum2 is more elegant, and<br>
partly to avoid namespace pollution, I was wondering if there is a way<br>
to "force" a "shallow" copy in sum2.<br>
<br>
If not, then may I submit a low priority feature request. An<br>
attribute? Some thing like:<br>
<br>
// [[Rcpp::export]]<br>
double sum2(arma::mat A) {<br>
    // [[ Rcpp::shallow ( A ) ]]<br>
     return sum(sum(A));<br>
}<br>
<br>
Or (akin to C++11 generalized attributes)<br>
<br>
// [[Rcpp::export]] { [[ Rcpp::shallow ( A ) ]] }<br>
double sum2(arma::mat A) {<br>
    return sum(sum(A));<br>
 }<br>
<br>
An alternative is to have an argument in sourceCpp that takes a<br>
list/vector of objects that are to be shallow or deep copied.<br>
<br>
For example in sum1, if M is changed within the function before<br>
casting to the arma::mat, then might be cleaner to add M to a<br>
list/vector of objects to be deep copied rather than cloning M within<br>
sum1: leads to one fewer variable name.<br>
<br>
Just a thought. I can certainly live with the additional step. As<br>
always, thanks for all the Rcpp goodness.<br>
<br>
Cheers,<br>
Changi Han<br>
</blockquote>
<br>
______________________________<u></u>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-<u></u>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-<u></u>project.org/cgi-bin/mailman/<u></u>listinfo/rcpp-devel</a></blockquote></div><br></div>