Hi Giovanni, On 23 October 2012 at 17:56, Giovanni Petris wrote: | 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;
I would recommend RcppArmadillo or RcppEigen for this. Rcpp itself has matrices but not that many operations on them. RcppArmadillo and RcppEigen will both give you access to a wide variety of decompositions provided, respectively, by Armadillo and Eigen. There are a number of examples for either package in the list archives and on other places. Dirk -- Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel