Skip to content

Using unsupported modules in R packages with RcppEigen #141

@serkor1

Description

@serkor1

Hi @eddelbuettel,

I am trying to use the unsupported modules in Eigen. This is my something.cpp-file:

//[[Rcpp::depends(RcppEigen)]]
#include <RcppEigen.h>
#include <unsupported/Eigen/CXX11/Tensor>

// [[Rcpp::export]]
Rcpp::XPtr<Eigen::Tensor<float, 2>> createFloatTensor(const Eigen::Map<Eigen::MatrixXd>& mat)
{
   
    Eigen::Index rows = mat.rows();
    Eigen::Index cols = mat.cols();

   
    auto* t = new Eigen::Tensor<float, 2>(rows, cols);

    
    for(Eigen::Index i = 0; i < rows; i++)
    {
        for(Eigen::Index j = 0; j < cols; j++)
        {
            (*t)(i, j) = static_cast<float>(mat(i, j));
        }
    }


    return Rcpp::XPtr<Eigen::Tensor<float, 2>>(t, true);
}

If I do Rcpp::sourceCpp("src/somethting.cpp") I have no issues with compiling and running the functions in R. However, if I build my R package with with R CMD build . + R CMD install I get the following error:

 RcppExports.cpp:15:19: error: ‘Tensor’ is not a member of ‘Eigen’
      15 | Rcpp::XPtr<Eigen::Tensor<float, 2>> createFloatTensor(const Eigen::Map<Eigen::MatrixXd>& mat);
         |                   ^~~~~~

If I compile the R package without // [[Rcpp::export]] there is no issues. I have mingled with the Makevars a bit, too:

PKG_CXX_STD = CXX23
PKG_CPPFLAGS = -I../inst/include

But nothing really works. Am I doing something wrong, or is this a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions