[Rcpp-devel] Is there an Rcpp class for arrays with > 2 dimensions?

Romain Francois romain at r-enthusiasts.com
Tue Jun 15 21:11:21 CEST 2010


Le 15/06/10 20:45, Dominick Samperi a écrit :
> I have tried something like
>
> Rcpp::NumericVector nm(Rcpp::Dimension(2,3,4));

I get this:

 > require( Rcpp )
Le chargement a nécessité le package : Rcpp
 > require( inline )
Le chargement a nécessité le package : inline
 > fx <- cxxfunction( signature(), ' return NumericVector( 
Dimension(2,3,4) ) ;', plugin = "Rcpp" )
 >
 > fx()
, , 1

      [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    0

, , 2

      [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    0

, , 3

      [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    0

, , 4

      [,1] [,2] [,3]
[1,]    0    0    0
[2,]    0    0    0

which looks about right. although not much useful without some more 
support such as extract or set the values.

> But there seems to be a problem due to non-public fields.

What do you mean ?

> Am I misunderstanding the purpose of Dimension() here?

Perhaps. Perhaps not. You did not tell us what you understand.

> On Tue, Jun 15, 2010 at 2:19 PM, Romain Francois
> <romain at r-enthusiasts.com <mailto:romain at r-enthusiasts.com>> wrote:
>
>     Le 15/06/10 20:08, Douglas Bates a écrit :
>
>
>         I may be confusing Armadillo classes and Rcpp classes but I seem to
>         recall that there is an Rcpp class for arrays with more than 2
>         dimensions.  However, I can't find anything that looks like that in
>         the declarations or in the unit tests.  I can easily create such an
>         object by installing a dim attribute on a Vector type but I didn't
>         want to reinvent the wheel.
>
>         Is there such a class or am I misremembering?
>
>
>     We do not have invented that wheel. It should not be too hard to
>     generalize what we do with Rcpp::Matrix
>
>     You can ignore the member functions that have diag in their names.
>
>     although, we would probably also have to extend the
>     Vector::operator() for more dimensions, and probably also
>     Vector::offset.
>
>     I feel somewhat lazy here, but if you or someone else decides to
>     pick it up, I will have a look.
>
>     Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/98Uf7u : Rcpp 0.8.1
|- http://bit.ly/c6YnCi : graph gallery collage
`- http://bit.ly/bZ7ltC : inline 0.3.5



More information about the Rcpp-devel mailing list