Hi,<div><br></div><div>That's great, thanks for considering this!</div><div><br></div><div>Following this discussion, I went to browse through my code looking for wrap() and as() statements that could benefit from a speed-up of memory reuse. Of course I didn't find any. </div>
<div>I switched to using Modules when they were introduced, the code being much nicer to read, and these conversions only happen behind the scene.</div><div>My c++ functions thus only deal with native Armadillo / C++ objects, and I leave it up to the modules to magically do the required conversions in and out. It's a brilliant interface, very readable.</div>
<div><br></div><div>From what I understand, however, the resulting code can often lose a factor 2-3 in speed, compared to the now much more verbose alternative of explicitly converting and sharing the memory with this type of code:</div>
<div><span style="white-space:pre-wrap"><br></span></div><div><span style="white-space:pre-wrap">arma::mat A(M.begin(), M.rows(), M.cols(), false);</span></div><div><span style="white-space:pre-wrap"><br></span></div><div>
<div></div><div>From this perspective, the possibility of setting copy_aux_mem to false in as(), as used by modules, would be very welcome.</div><div><br></div><div>Best regards,</div><div><br></div><div>baptiste</div></div>
<div><br></div><br><div class="gmail_quote">On 11 July 2013 10:22,  <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 :<div class="HOEnZb"><div class="h5"><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></div></div><div class="HOEnZb"><div class="h5">
______________________________<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></div></div></blockquote></div><br>