[Rcpp-devel] List of matrices mimicking 3d array?

Edward Wallace ewjwallace at gmail.com
Thu Jan 5 17:00:24 CET 2012


In the end I wrote an obvious miniature sugary hack to convert 3d array
indices into numeric vector indices

int threeDIndex(int j, int k, int l, int J, int K, int L) {
    return j*K*L + k*L + l;
}

so that where one wants to call A[j,k,l], instead one
calls A[ threeDIndex(j,k,l,J,K,L) ], where dim(A) = (J,K,L). Presumably a
programmer with more experience than me could write a cpp method to do this
for NumericVectors with dimension attribute?

Edward

On Wednesday, January 4, 2012, Dirk Eddelbuettel wrote:

>
> On 4 January 2012 at 19:11, Hadley Wickham wrote:
> | > Our arrays in Rcpp can be multidimensional just like they can in R.
> Here is a
> | > line from one of the unit tests:
> | >
> | >   return IntegerVector( Dimension( 2, 3, 4) ) ;
> | >
> | > which sets the dim attribute of a given vector to c(2,3,4) just like
> you
> | > would in R.  That should all work too but may have seen less exposure
> than
> | > other parts of our code.
> |
> | Am I reading the Vector documentation correctly
> | (http://dirk.eddelbuettel.com/code/rcpp/html/classVector.html) in
> | interpreting that while you can create vectors with dimensions, that
> | there is no syntactic sugar for  multidimensional indexing?  I'm not
>
> I think that is correct. We do have Range objects, and that is about it.
> This is not yet a level comparable to R.
>
> The unitTests/ directories, as always, has the largest collections of
> working
> idioms to copy from.  runit.Vector.r is probably what you want to look at.
>
> | quite sure how to interpret method signatures like operator() (const
> | size_t &i, const size_t &j) const. I can guess that means you can
> | index by two integers - but I don't know what those two integers mean.
>
> Well if I had to guess I'd say row and column ...
>
> Dirk
>
> |
> | Hadley
> |
> | --
> | Assistant Professor / Dobelman Family Junior Chair
> | Department of Statistics / Rice University
> | http://had.co.nz/
>
> --
> "Outside of a dog, a book is a man's best friend. Inside of a dog, it is
> too
> dark to read." -- Groucho Marx
>


-- 
Edward Wallace, PhD
Harvard FAS center for Systems Biology
+1-773-517-4009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120105/7e018972/attachment.htm>


More information about the Rcpp-devel mailing list