[Rcpp-devel] use of auxiliary functions

baptiste auguie baptiste.auguie at googlemail.com
Thu Aug 12 20:59:29 CEST 2010


Point well taken, l'll try to use const and const& wherever appropriate.

Thanks,

baptiste




On 11 August 2010 23:55, Davor Cubranic <cubranic at stat.ubc.ca> 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.
>
> 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 would in others. And it's good to be consistent, which will also
> help someone else reading your code. (But you don't have to put
> parentheses around the return statement's argument.)
>
> Also, making B a constant parameter if it's not supposed to be changed
> inside the function will sooner or later protect you from mistakes. Use
> consts even if you're not comfortable with using references, it's just
> another small bit of help from the compiler.
>
> Davor
>
>
> On August 11, 2010 12:30:05 pm baptiste auguie wrote:
>> 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 Rcpp ;
>> using namespace RcppArmadillo ;
>>
>> extern "C" {
>>
>>   arma::mat dum1(arma::mat B)
>>   {
>>     return (B*38);
>>   }
>>
>>   arma::mat dum2(const arma::mat& B)
>>   {
>>     return (B*38);
>>   }
>>
>>   RCPP_FUNCTION_2(NumericMatrix, dummy1, NumericMatrix A, int N) {
>>     arma::mat B = Rcpp::as< arma::mat >( A ) ;
>>     return wrap(dum1(repmat(B, N, N)));
>>   }
>>
>>   RCPP_FUNCTION_2(NumericMatrix, dummy2, NumericMatrix A, int N) {
>>     arma::mat B = Rcpp::as< arma::mat >( A ) ;
>>     return wrap(dum2(repmat(B, N, N)));
>>   }
>>
>> }
>



-- 
____________________

Dr. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides
____________________


More information about the Rcpp-devel mailing list