[Rcpp-devel] Slices of 3d arrays as matrices

Giovanni Petris gpetris at uark.edu
Tue Oct 23 19:56:50 CEST 2012


Hello,

I have a 3d array and I want to compute the eigendecomposition of each slice [,, k]. I am trying to make Rcpp see the relevant slice of the 3d array as a matrix. My experiments, along the lines illustrated below, have so far been unsuccessful. Does anybody have a suggestion? Thank you in advance!


   NumericVector cpp_Sigma(Sigma); // 3d array, with dim(Sigma) = c(M,M,K), as a vector
   NumericMatrix tmpMatrix;
   List var_eigen;
   Function eigen("eigen");
   int k=2; // 3rd slice, for example

   tmpMatrix = cpp_Sigma[k * M * M]; 
   tmpMatrix.attr("dim") = Dimension(M, M);
   var_eigen = eigen(tmpMatrix);
   return var_eigen;

Best,
Giovanni


More information about the Rcpp-devel mailing list