Hi all, I've been happily using the RcppEigen package for a couple of projects, but now I'm running into problems converting a matrix from R into an Eigen::MatrixXd. Converting an R matrix to an Eigen::Map<Eigen::MatrixXd> works fine, but I would like to (deep)copy the values from R to a C++ Eigen::MatrixXd object. From the definition for the Exporter for Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> in RcppEigen/inst/include/RcppEigenWrap.h, it looks like Rcpp::as<Eigen::MatrixXd> could be used, but when compiling some example code (see below) I get an error (see below). Compiling the same code with an arma::mat or with Eigen::Map<Eigen::MatrixXd> does not result in any errors.
Does anyone have an idea what is causing this? Many thanks in advance and best wishes, Jelmer > sessionInfo() R version 2.15.0 (2012-03-30) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] inline_0.3.8 RcppArmadillo_0.3.0.3 RcppEigen_0.2.0 Rcpp_0.9.10 loaded via a namespace (and not attached): [1] grid_2.15.0 lattice_0.20-6 Matrix_1.0-6 tools_2.15.0 The error I get, is: In file included from c:/tools/R/library/RcppEigen/include/Eigen/Core:282:0, from c:/tools/R/library/RcppEigen/include/Eigen/Dense:1, from c:/tools/R/library/RcppEigen/include/RcppEigenForward.h:29, from c:/tools/R/library/RcppEigen/include/RcppEigen.h:25, from file160c52054c0.cpp:3: c:/tools/R/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h: In member function 'Eigen::DenseCoeffsBase<Derived, 1>::Scalar& Eigen::DenseCoeffsBase<Derived, 1>::operator[](Eigen::DenseCoeffsBase<Derived, 1>::Index) [with Derived = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, Eigen::DenseCoeffsBase<Derived, 1>::Scalar = double, Eigen::DenseCoeffsBase<Derived, 1>::Index = int]': c:/tools/R/library/Rcpp/include/Rcpp/internal/export.h:89:3: instantiated from 'void Rcpp::internal::export_indexing__impl(SEXP, T&, Rcpp::traits::false_type) [with T = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, value_type = double, SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool, false>]' c:/tools/R/library/Rcpp/include/Rcpp/internal/export.h:109:6: instantiated from 'void Rcpp::internal::export_indexing__dispatch(SEXP, T&, Rcpp::traits::r_type_primitive_tag) [with T = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, value_type = double, SEXP = SEXPREC*]' c:/tools/R/library/Rcpp/include/Rcpp/internal/export.h:127:6: instantiated from 'void Rcpp::internal::export_indexing(SEXP, T&) [with T = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, value_type = double, SEXP = SEXPREC*]' c:/tools/R/library/Rcpp/include/Rcpp/traits/Exporter.h:86:17: instantiated from 'T Rcpp::traits::MatrixExporter<T, value_type>::get() [with T = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, value_type = double]' c:/tools/R/library/Rcpp/include/Rcpp/as.h:53:33: instantiated from 'T Rcpp::internal::as(SEXP, Rcpp::traits::r_type_generic_tag) [with T = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, SEXP = SEXPREC*]' c:/tools/R/library/Rcpp/include/Rcpp/as.h:75:89: instantiated from 'T Rcpp::as(SEXP) [with T = Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, SEXP = SEXPREC*]' file160c52054c0.cpp:31:40: instantiated from here c:/tools/R/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:388:7: error: 'THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD' is not a member of 'Eigen::internal::static_assertion<false>' make: *** [file160c52054c0.o] Error 1 ERROR(s) during compilation: source code errors or compiler configuration errors! The code I used for the example is: library('RcppEigen') library('RcppArmadillo') library('inline') # Define C++ some function that uses a matrix as input. # MatrixType will be defined using a typedef in includes, # when compiling the function below. # MatrixType will take on values # * arma::mat # * Eigen::MatrixXd # * Eigen::Map<Eigen::MatrixXd> printMatrix_code <- ' MatrixType _A( Rcpp::as<MatrixType>( A ) ); Rcpp::Rcout << "_A: " << std::endl << _A << std::endl; return R_NilValue; ' # Define some matrix A set.seed( 3141 ) A <- matrix( rnorm( 10 ), nrow=5, ncol=2 ) A # Compile using MatrixType = arma::mat # (WORKS) try( { printArmaMatrix <- cxxfunction( signature(A="matrix"), printMatrix_code, plugin="RcppArmadillo", includes = 'typedef arma::mat MatrixType;', verbose=TRUE ) printArmaMatrix( A ) } ) # Compile using MatrixType = Eigen::MatrixXd # (FAILS) try( { printEigenMatrix <- cxxfunction( signature(A="matrix"), printMatrix_code, plugin="RcppEigen", includes = 'typedef Eigen::MatrixXd MatrixType;', verbose=TRUE ) printEigenMatrix( A ) } ) # Compile using MatrixType = Eigen::Map<Eigen::MatrixXd> # (WORKS) try( { printEigenMappedMatrix <- cxxfunction( signature(A="matrix"), printMatrix_code, plugin="RcppEigen", includes = 'typedef Eigen::Map<Eigen::MatrixXd> MatrixType;', verbose=TRUE ) printEigenMappedMatrix( A ) } ) _______________________________________________ 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