Skip to content

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

6 messages · Romain Francois, Douglas Bates, Dominick Samperi

#
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?
#
Le 15/06/10 20:08, Douglas Bates a ?crit :
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
#
I have tried something like

Rcpp::NumericVector nm(Rcpp::Dimension(2,3,4));

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

Am I misunderstanding the purpose of Dimension() here?

On Tue, Jun 15, 2010 at 2:19 PM, Romain Francois
<romain at r-enthusiasts.com>wrote:

            
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20100615/fc1c0ddd/attachment.htm>
#
Le 15/06/10 20:45, Dominick Samperi a ?crit :
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.
What do you mean ?
Perhaps. Perhaps not. You did not tell us what you understand.

  
    
#
On Tue, Jun 15, 2010 at 2:11 PM, Romain Francois
<romain at r-enthusiasts.com> wrote:
Actually, that was what I was thinking of.   All I want to do is to
generate the array and then I will fill in the values using a pointer.
#
[should have used reply all]

On Tue, Jun 15, 2010 at 3:11 PM, Romain Francois
<romain at r-enthusiasts.com>wrote:
I made the mistake of using NumericMatrix(Dimension(2,3,4)) instead of
NumericVector(Dimension(2,3,4)). That is why I had compilation problems.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20100615/579111d3/attachment-0001.htm>