[Rcpp-devel] Is this issue solved?

Yixuan Qiu yixuan.qiu at cos.name
Mon Feb 17 00:30:59 CET 2014


Hi Jianyang,
It seems that the problem still exists, and the problem is mainly due to
the following statement:

Rcpp::as<Eigen::MatrixXd>( A );

It means we cannot directly cast SEXP to Eigen::MatrixXd.

If you want to operate A using Eigen, there are several ways to do it:

1. Map A to Eigen::Map<Eigen::MatrixXd>

typedef Eigen::Map<Eigen::MatrixXd> MapMat;
MapMat _A = Rcpp::as<MapMat>( A );

In this case _A shares the same data with A, so changing _A will also
change A.

2. If you want to copy the data of A to a Eigen::MatrixXd variable, you can
use a copy constructor as suggested by Doug Bates.

Eigen::MatrixXd _A_copy(_A);

3. In Eigen the assignment of a matrix will also do the copy (at least for
the following example), so it is also true to use

Eigen::MatrixXd _A_copy = _A;


As a whole, the general rule at this moment is that you always convert A to
an Eigen::Map<Eigen::MatrixXd> object first, and then operate on _A either
by directly accessing it or by copying it to an Eigen::MatrixXd object.


Best,
Yixuan



2014-02-16 16:53 GMT-05:00 Jianyang Zhao <uzhao at ucdavis.edu>:

> Hello All,
>
> I got into same problem in this thread. Is it solved? I use last version
> R, Rcpp and RcppEigen under windows.
>
>
> http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2012-May/003792.html
>
> Thanks,
>
> Jianyang
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>



-- 
Yixuan Qiu <yixuan.qiu at cos.name>
Department of Statistics,
Purdue University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140216/47a199d5/attachment.html>


More information about the Rcpp-devel mailing list