Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Gabor Grothendieck
On Thu, Jul 11, 2013 at 8:32 AM, Changi Han wrote: > Hello, > > I think I (superficially) understand the difference between: > > // [[Rcpp::export]] > double sum1(Rcpp::NumericMatrix M) { > arma::mat A(M.begin(), M.rows(), M.cols(), false); > return sum(sum(A)); > } > > > // [[Rcpp::export

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Changi Han
I entirely missed that thread ... sorry. I came across the above examples at: http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-April/005680.html On Thu, Jul 11, 2013 at 8:38 PM, Gabor Grothendieck wrote: > On Thu, Jul 11, 2013 at 8:32 AM, Changi Han > wrote: > > Hello, > > > > I t

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Gabor Grothendieck
On Thu, Jul 11, 2013 at 8:56 AM, Changi Han wrote: > I entirely missed that thread ... sorry. I came across the above examples > at: > > http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2013-April/005680.html > > > On Thu, Jul 11, 2013 at 8:38 PM, Gabor Grothendieck > wrote: >> >> On Thu,

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread romain
Hello, 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. 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

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread baptiste auguie
Hi, That's great, thanks for considering this! 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. I switched to using Modules when they were introduced, the code being

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Changi Han
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. // [[Rcpp::export]] stuff function(Rcpp::stuff) { } // [[Rcpp::export]] stuff function(arma::stuff) { } Thank you again. Cheers.

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread romain
These __are__ similar. The difference is in the classes themselves. Rcpp classes are proxy classes so C++ copy mechanism does not apply to them. arma classes are proper c++ classes, so C++ semantics apply. I'm at useR right now, so I can't really work on this. I'll submit at least ideas later.

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Dirk Eddelbuettel
On 11 July 2013 at 10:33, baptiste auguie wrote: | Hi, | | That's great, thanks for considering this! | | 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.  | I s

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Dirk Eddelbuettel
On 11 July 2013 at 21:34, Changi Han wrote: | 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. | | // [[Rcpp::export]] | stuff function(Rcpp::stuff) { | } | | // [[Rcpp::ex

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Dirk Eddelbuettel
Everybody has this existing example in their copy of Armadillo. I am running it here from SVN rather than the installed directory, but this should not make a difference. Machine is my not-overly-powerful thinkpad used for traveling: edd@don:~/svn/rcpp/pkg/RcppArmadillo/inst/examples$ r fastLm.r

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Gabor Grothendieck
1. Just to be clear what we have been discussing here is not just how to avoid copying but how to avoid copying while using as and wrap or approaches that automatically generate as and wrap. I was already aware of how to avoid copying using Armadillo how to use Armadillo types as arguments and ret

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-11 Thread Dirk Eddelbuettel
On 11 July 2013 at 19:21, Gabor Grothendieck wrote: | 1. Just to be clear what we have been discussing here is not just how to | avoid copying but how to avoid copying while using as and wrap | or approaches that automatically generate as and wrap. I was already | aware of how to avoid copying us

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-12 Thread Gabor Grothendieck
On Fri, Jul 12, 2013 at 1:42 AM, Dirk Eddelbuettel wrote: > > On 11 July 2013 at 19:21, Gabor Grothendieck wrote: > | 1. Just to be clear what we have been discussing here is not just how to > | avoid copying but how to avoid copying while using as and wrap > | or approaches that automatically gen

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-07-12 Thread Changi Han
I apologize if my emails were badly phrased, or disrespectful. No intention of saying anything was broken, suspicious or wrong. I second Gabor. His described use case matches mine. The outer loop is an optimization routine coming from other libraries. Rcpp is used to speed up the objective, gradie

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-09-13 Thread Romain Francois
Hello, (sorry this had to wait a few months, but now I have an idea about this) We all love to be able to do that: #include using namespace Rcpp ; // [[Rcpp::depends("RcppArmadillo")]] // [[Rcpp::export]] void do_stuff( arma::mat m ){ // do stuff with m } This is really nice. But R does

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-09-13 Thread JJ Allaire
> > Is it a big deal that we would cheat on chat reference passing means ? > If you want to implement these sort of semantics I think at a _minimum_ the type should be const & (otherwise it looks like you are going to actually modify the matrix in place which would appear to bypass the implicit me

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-09-13 Thread Romain Francois
Le 13/09/13 14:00, JJ Allaire a écrit : Is it a big deal that we would cheat on chat reference passing means ? If you want to implement these sort of semantics I think at a _minimum_ the type should be const & (otherwise it looks like you are going to actually modify the matrix in place whi

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-09-13 Thread Romain Francois
Le 13/09/13 14:15, Romain Francois a écrit : But I realize this might be a strech and we can definitely only have const references. Which is easier to implement anyway and we would not need the reference counting stuff I was talking about before. spoke too soon. We would need it otherwise we r

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-09-13 Thread Romain Francois
Le 13/09/13 14:00, JJ Allaire a écrit : Is it a big deal that we would cheat on chat reference passing means ? If you want to implement these sort of semantics I think at a _minimum_ the type should be const & (otherwise it looks like you are going to actually modify the matrix in place whi

Re: [Rcpp-devel] Forcing a shallow versus deep copy

2013-09-13 Thread Dirk Eddelbuettel
On 13 September 2013 at 17:56, Romain Francois wrote: | Here is where I am now. To wrap up this function: [...] | This is simple and elegant. And now we can pass down references and | const references of armadillo matrices from R without performance penalty. | | This makes using RcppArmadillo ev