Re: [Rcpp-devel] use of auxiliary functions

2010-08-14 Thread baptiste auguie
Thanks for the conclusive example :) baptiste On 12 August 2010 21:53, Dirk Eddelbuettel wrote: > > On 12 August 2010 at 20:59, baptiste auguie wrote: > | Point well taken, l'll try to use const and const& wherever appropriate. > > I am coming to this late (sorry, too much other stuff going on

Re: [Rcpp-devel] use of auxiliary functions

2010-08-12 Thread Dirk Eddelbuettel
On 12 August 2010 at 20:59, baptiste auguie wrote: | Point well taken, l'll try to use const and const& wherever appropriate. I am coming to this late (sorry, too much other stuff going on...) but I had meant to illustrate the good advise provided by Davor and Romain. So here is a stylized Armad

Re: [Rcpp-devel] use of auxiliary functions

2010-08-12 Thread baptiste auguie
Point well taken, l'll try to use const and const& wherever appropriate. Thanks, baptiste On 11 August 2010 23:55, Davor Cubranic wrote: > As Romain said, there can be some hidden optimization going on, or the > difference is not significant compared to the cost of the rest of the > code. >

Re: [Rcpp-devel] use of auxiliary functions

2010-08-11 Thread Davor Cubranic
As Romain said, there can be some hidden optimization going on, or the difference is not significant compared to the cost of the rest of the code. But C++ best practice would recommend that you write this particular function as you did in dum2, not dum1. It may not matter in this case, but it

Re: [Rcpp-devel] use of auxiliary functions

2010-08-11 Thread baptiste auguie
"disguise" might be a more appropriate name? I like the idea. Thanks, baptiste On 11 August 2010 21:59, Romain Francois wrote: > Hi, > > For one thing, the construct : > > arma::mat B = Rcpp::as<  arma::mat>( A ) ; > > probably makes copies along the way. I'm not sure what right now, but we >

Re: [Rcpp-devel] use of auxiliary functions

2010-08-11 Thread Romain Francois
Hi, For one thing, the construct : arma::mat B = Rcpp::as< arma::mat>( A ) ; probably makes copies along the way. I'm not sure what right now, but we might a different construct, something like: arma::mat B ; Rcpp::borrow( B, A ) ; where borrow would have this signature perhaps template

Re: [Rcpp-devel] use of auxiliary functions

2010-08-11 Thread baptiste auguie
I think I understand the principle, however with my best effort I cannot find a test case. Here I thought I'd be passing an arbitrarily large arma matrix to some function, but again the timing is not convincing (in fact, I had to stop the execution once with the dummy2 version), using namespace Rc

Re: [Rcpp-devel] use of auxiliary functions

2010-08-11 Thread Davor Cubranic
On August 11, 2010 02:48:23 am rom...@r-enthusiasts.com wrote: > Le 10 août 2010 à 22:10, baptiste auguie a écrit : > > OK, thanks. I have not been able to produce a minimal code that > > would exhibit an improved performance using this > > passing-by-reference idea. > > Hi, > > It would usuall

Re: [Rcpp-devel] use of auxiliary functions

2010-08-11 Thread romain
Le 10 août 2010 à 22:10, baptiste auguie a écrit : > Hi, > > On 10 August 2010 07:51, Romain Francois wrote: >> Le 10/08/10 07:35, baptiste auguie a écrit : >>> >>> I see –– thanks for the clarification (it is indeed what Dirk really >>> had suggested, the accidental shortcut was mine). T

Re: [Rcpp-devel] use of auxiliary functions

2010-08-10 Thread baptiste auguie
Hi, On 10 August 2010 07:51, Romain Francois wrote: > Le 10/08/10 07:35, baptiste auguie a écrit : >> >> I see –– thanks for the clarification (it is indeed what Dirk really >> had suggested, the accidental shortcut was mine). This passing by >> reference seems very interesting (I pass several la

Re: [Rcpp-devel] use of auxiliary functions

2010-08-09 Thread Romain Francois
Le 10/08/10 07:35, baptiste auguie a écrit : I see –– thanks for the clarification (it is indeed what Dirk really had suggested, the accidental shortcut was mine). This passing by reference seems very interesting (I pass several large complex arma matrices in other functions), but I need to work

Re: [Rcpp-devel] use of auxiliary functions

2010-08-09 Thread baptiste auguie
I see –– thanks for the clarification (it is indeed what Dirk really had suggested, the accidental shortcut was mine). This passing by reference seems very interesting (I pass several large complex arma matrices in other functions), but I need to work out how it works inside the functions. Thanks

Re: [Rcpp-devel] use of auxiliary functions

2010-08-09 Thread Davor Cubranic
On 2010-08-07, at 7:03 PM, baptiste auguie wrote: > Thanks Davor, Douglas and Dirk –– all your comments have been very > helpful and I used them to improve my code (along with getting a > better understanding of C++). The only thing I haven't tried yet is > avoid duplicating the objects in memory

Re: [Rcpp-devel] use of auxiliary functions

2010-08-09 Thread Davor Cubranic
I tried compiling this function with various gcc optimization switches. The results of my experiment are mixed. For most commonly-used optimization switches (-On for n=0..3, even -fast), I could see multiple calls to 'cos' with repeated same arguments, directly corresponding to the expressions i

Re: [Rcpp-devel] use of auxiliary functions

2010-08-07 Thread baptiste auguie
Thanks Davor, Douglas and Dirk –– all your comments have been very helpful and I used them to improve my code (along with getting a better understanding of C++). The only thing I haven't tried yet is avoid duplicating the objects in memory using const (seems tricky from what I read on the net). Al

Re: [Rcpp-devel] use of auxiliary functions

2010-08-07 Thread Davor Cubranic
On August 6, 2010 02:44:00 pm Douglas Bates wrote: > On Fri, Aug 6, 2010 at 3:14 PM, baptiste auguie > > > arma::mat euler(double phi, double theta, double psi) > > { > >arma::mat Rot(3,3); > >Rot(0,0) = cos(psi)*cos(phi) - cos(theta)*sin(phi)*sin(psi); > >Rot(0,1) = cos(psi)*sin(phi

Re: [Rcpp-devel] use of auxiliary functions

2010-08-06 Thread Douglas Bates
On Fri, Aug 6, 2010 at 3:14 PM, baptiste auguie wrote: > Dear all, > In a package using RcppArmadillo I define several functions that use > the same piece of c++ code. For instance, several functions use a > rotation matrix constructed from 3 angles. I am considering the > following idea: 1) defi

[Rcpp-devel] use of auxiliary functions

2010-08-06 Thread baptiste auguie
Dear all, In a package using RcppArmadillo I define several functions that use the same piece of c++ code. For instance, several functions use a rotation matrix constructed from 3 angles. I am considering the following idea: 1) define a routine that performs the calculations; 2) create a wrapper i