[Rcpp-devel] Integer matrices in Rcpp and Armadillo

Romain Francois romain at r-enthusiasts.com
Fri Jun 7 13:13:37 CEST 2013


Le 07/06/13 13:09, Simon Zehnder a écrit :
> HI Dirk, hi Romain,
>
> allright, this is now clear to me, if I want to reuse memory, the allocated memory from R (so implicitly in C) must of course have the same type - otherwise the memory has a different size.

so far, this is obvious.

> On the other side I then assume, that the Rcpp:as<class M>() function makes a cast and therefore creates a copy with new allocated memory of the type included in M? Therefore a reuse of memory with this function is not possible.

Depends what is M, but most of the time yes, as<> copies data.

> Best
>
> Simon
>
>
> On Jun 6, 2013, at 8:31 PM, Dirk Eddelbuettel <edd at debian.org> wrote:
>
>>
>> On 6 June 2013 at 13:17, Dirk Eddelbuettel wrote:
>> |
>> | On 6 June 2013 at 19:05, Simon Zehnder wrote:
>> | | sorry I had overseen this message from you. Okay, so the explicit cast to SEXP together with the assignment operator makes the deal. But it still includes the reuse of memory right, i.e. the '=' does not call the copy constructor?
>> |
>> | But how could an _unsigned int_ from Armadillo possibly have the same value
>> | as a _signed int_ in R?
>> |
>> | Either you are efficient (no copy), or you are correct (with a copy). I do
>> | not see how you could have both.
>>
>> Sorry -- please ignore this message.
>>
>> I had mistakenly assumed that you were still thinking about arma::umat to
>> integer.  For direct int-to-int this is indeed efficient just like the
>> double-to-double is for arma::mat to NumericMatrix (and dito for vectors).  I
>> though that was a given -- maybe need to make this (even) more explicit in
>> the documentation.
>>
>> So in sum: you get correct and efficient behaviour if and only if you stick
>> with the types natively supported in Armadillo and R.
>>
>> Dirk
>>
>> --
>> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
>
>


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:            http://blog.r-enthusiasts.com
|- http://bit.ly/Zs97qg  : highlight 0.4.1
`- http://bit.ly/10X94UM : Mobile version of the graph gallery



More information about the Rcpp-devel mailing list