Marsha
Marsha

Reputation: 43

RowVectorXd not supported in rcppEigen?

Mapping works fine with:

Map<Eigen::VectorXd> x(as<Map<Eigen::VectorXd> >(y));

but not with:

Map<Eigen::RowVectorXd> x(as<Map<Eigen::RowVectorXd> >(y));

Is RowVectorXd not supported in RcppEigen?

Upvotes: 0

Views: 118

Answers (1)

coatless
coatless

Reputation: 20746

Edit:

The code to enable this form of wrapping has been merged into the dev version of RcppEigen. Feel free to grab a copy via:

devtools::install_github("RcppCore/RcppEigen")

Original:

Per RcppEigen's unit tests and exporters, it looks as if only VectorXd/VectorXi presently has an export class set up.

This needs to be added to the exporter class. Here is a PR containing the fix.

template<typename T>
class Exporter<Eigen::Map<Eigen::Matrix<T, 1, Eigen::Dynamic> > > {
    typedef typename Eigen::Map<Eigen::Matrix<T, 1, Eigen::Dynamic> > OUT ;
    const static int RTYPE = ::Rcpp::traits::r_sexptype_traits<T>::rtype ;
    Rcpp::Vector<RTYPE> vec ;

    public:
        Exporter(SEXP x) : vec(x) {
            if (TYPEOF(x) != RTYPE)
                throw std::invalid_argument("Wrong R type for mapped vector");
        }
        OUT get() {return OUT(vec.begin(), vec.size());}
    } ;

Since RowVectorXd is given as a row-vector of X decimals: Matrix<double, 1, X>. See Matrix docs

Upvotes: 1

Related Questions