[Rcpp-devel] Filling NumericMatrix with NumericVectors with apply by row/column?
Romain Francois
romain at r-enthusiasts.com
Tue Sep 21 11:56:12 CEST 2010
Le 21/09/10 11:46, Christian Gunning a écrit :
>> You can always attach dimensions later:
>>
>> ret.attr( "dim" ) = Dimension( 2, 2, 2) ;
>
> Ah, yes. Thanks.
I'd rather encapsulate this a bit rather than let people touch the dim
attribute, or perhaps mimic what R is doing :
> x <- 1:24
> attr( x, "dim" ) <- c(2,12)
> x
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[1,] 1 3 5 7 9 11 13 15 17 19 21 23
[2,] 2 4 6 8 10 12 14 16 18 20 22 24
> attr( x, "dim" ) <- c(2,17)
Erreur dans attr(x, "dim") <- c(2, 17) :
dims [produit 34] ne correspond pas à la longueur de l'objet [24]
and gatekeep inside the attr() function
>> You can however Rcpp::wrap a cube. It is safer because the memory gets
>> copied, but less efficient, because the memory is copied.
>
> Got it. I erroneously assumed an implicit wrap somewhere.
There was no implicit wrap in the code you shown.
>> Sure. I need to think a little bit more about how to do Rcpp::Array, etc ...
>> because an Array could have an arbitrary number of dimensions.
>> Perhaps embedding information into the class would work.
>>
>> // make an array of 3 dimensions, etc ...
>> Rcpp::Array<3> ret( y ) ;
>
> Yes, I've been thinking similarly about an Indexer class. Accounting
> for a variable number of dimensions looks unpleasantly messy.
Yes. Feel free to share thoughts on that.
>>> * What about "ret = ret * as<int>(x);" causes ret to lose it's dimension?
>>
>> Omission, lack of time, I'm not using arrays all that much personally, etc
>
> Oh, I was thinking more along the lines of "by what mechanism is
> dimension lost" than "why is grass green" :)
>
> -Christian
Because we make a new vector and don't keep the attributes of the old
one, including the "dim" attribute.
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/cCmbgg : Rcpp 0.8.6
|- http://bit.ly/bzoWrs : Rcpp svn revision 2000
`- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th
More information about the Rcpp-devel
mailing list