[Rcpp-devel] problem compiling with const in RcppEigen

Douglas Bates bates at stat.wisc.edu
Thu Jan 31 18:34:42 CET 2013


I should check the syntax before sending the message.

On Thu, Jan 31, 2013 at 11:30 AM, Douglas Bates <bates at stat.wisc.edu> wrote:

> The as function in RcppEigen can form an
>
> Eigen::Map<Eigen::MatrixXd>
>
> but doesn't know how to form an
>
> Eigen::Map<const Eigen::MatrixXd>
>
> Generally I find that I confuse myself less when the const is outside the
> Eigen::Map.  In other words, I use something like
>
> typedef Eigen::Map<Eigen::MatrixXd> mMat;
>
> const mMat M(mat_from_R);
>

That should be

const mMat M = as<mMat>(mat_from_R);

Well, at least I think so.

The bottom line is that I find it easier to use const in the declaration of
an instance of a class, not in the typedef.

>
> This tells me that M is a mapped MatrixXd object which is constructed from
> the SEXP mat_from_R and is read-only.
>
>
>
> On Thu, Jan 31, 2013 at 11:01 AM, M A <markoilcan at gmail.com> wrote:
>
>> I am compiling some source code using sourceCpp and getting a
>> compiling failure when the source has the line with the const keyword
>> but no failure when it does not, in the below source.
>>
>> // file: minimaltest.cpp
>> // [[Rcpp::depends(RcppEigen)]]
>>
>> #include <RcppEigen.h>
>> #include <Rcpp.h>
>>
>> typedef Eigen::Map<Eigen::VectorXd> MapVecd;
>> //typedef Eigen::Map<Eigen::MatrixXd> MapMatd; // This one works
>> typedef Eigen::Map<const Eigen::MatrixXd> MapMatd; // This one fails
>>
>> // [[Rcpp::export]]
>> Eigen::VectorXd testfunc(const MapVecd ytrait, MapMatd xmat) {
>>
>>     return ytrait;
>> }
>>
>> This is the error:
>>
>> > sourceCpp("minimaltest.cpp")
>> g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
>> -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG
>> -I/usr/local/include
>>
>> -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"
>>
>> -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/RcppEigen/include"
>>   -fPIC  -g -O2  -c minimaltest.cpp -o minimaltest.o
>> Error in sourceCpp("minimaltest.cpp") :
>>   Error 1 occurred building shared library.
>>
>> /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/internal/Exporter.h:
>> In constructor ‘Rcpp::traits::Exporter<T>::Exporter(SEXPREC*) [with T
>> = Eigen::Map<const Eigen::Matrix<double, -0x00000000000000001,
>> -0x00000000000000001, 0, -0x00000000000000001, -0x00000000000000001>,
>> 0, Eigen::Stride<0, 0> >]’:
>>
>> /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/as.h:67:
>>   instantiated from ‘T Rcpp::internal::as(SEXPREC*,
>> Rcpp::traits::r_type_generic_tag) [with T = Eigen::Map<const
>> Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001, 0,
>> -0x00000000000000001, -0x00000000000000001>, 0, Eigen::Stride<0, 0>
>> >]’
>>
>> /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/as.h:112:
>>   instantiated from ‘T Rcpp::as(SEXPREC*) [with T = Eigen::Map<const
>> Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001, 0,
>> -0x00000000000000001, -0x00000000000000001>, 0, Eigen::Stride<0, 0>
>> >]’
>> minimaltest.cpp:35:   instantiated from here
>>
>> /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/internal/Exporter.h:31:
>> error: no matching function for call to ‘Eigen::Map<const
>> Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001, 0,
>> -0x00000000000000001, -0x00000000000000001>, 0, Eigen::Stride<0, 0>
>> >::Map(SEXPREC*&)’
>>
>> /Library/Frameworks/R.framework/Versions/2.15/Resources/library/RcppEigen/include/Eigen/src/Core/Map.h:164:
>> note: candidates are: Eigen::Map<MatrixType, MapOptions,
>> StrideType>::Map(typename Eigen::MapBase<Eigen::Map<PlainObjectType,
>> MapOptions, StrideType>,
>> (Eigen::internal::accessors_level<Eigen::Map<PlainObjectType,
>> MapOptions, StrideType> >::has_write_access ?  WriteAccessors :
>> ReadOnlyAccessors)>::PointerType, typename
>> Eigen::internal::traits<Eigen::Map<PlainObjectType, MapOptions,
>> StrideType> >::Index, typename
>> Eigen::internal::traits<Eigen::Map<PlainObjectType, MapOptions,
>> StrideType> >::Index, const StrideType&) [with PlainObjectType = const
>> Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001, 0,
>> -0x00000000000000001, -0x00000000000000001>, int MapOptions = 0,
>> StrideType = Eigen::Stride<0, 0>]
>>
>> /Library/Frameworks/R.framework/Versions/2.15/Resources/library/RcppEigen/include/Eigen/src/Core/Map.h:151:
>> note:                 Eigen::Map<MatrixType, MapOptions,
>> StrideType>::Map(typename Eigen::MapBase<Eigen::Map<PlainObjectType,
>> MapOptions, StrideType>,
>> (Eigen::internal::accessors_level<Eigen::Map<PlainObjectType,
>> MapOptions, StrideType> >::has_write_access ?  WriteAccessors :
>> ReadOnlyAccessors)>::PointerType, typename
>> Eigen::internal::traits<Eigen::Map<PlainObjectType, MapOptions,
>> StrideType> >::Index, const StrideType&) [with PlainObjectType = const
>> Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001, 0,
>> -0x00000000000000001, -0x00000000000000001>, int MapOptions = 0,
>> StrideType = Eigen::Stride<0, 0>]
>>
>> /Library/Frameworks/R.framework/Versions/2.15/Resources/library/RcppEigen/include/Eigen/src/Core/Map.h:139:
>> note:                 Eigen::Map<MatrixType, MapOptions,
>> StrideType>::Map(typename Eigen::MapBase<Eigen::Map<PlainObjectType,
>> MapOptions, StrideType>,
>> (Eigen::internal::accessors_level<Eigen::Map<PlainObjectType,
>> MapOptions, StrideType> >::has_write_access ?  WriteAccessors :
>> ReadOnlyAccessors)>::PointerType, const StrideType&) [with
>> PlainObjectType = const Eigen::Matrix<double, -0x00000000000000001,
>> -0x00000000000000001, 0, -0x00000000000000001, -0x00000000000000001>,
>> int MapOptions = 0, StrideType = Eigen::Stride<0, 0>]
>>
>> /Library/Frameworks/R.framework/Versions/2.15/Resources/library/RcppEigen/include/Eigen/src/Core/Map.h:106:
>> note:                 Eigen::Map<const Eigen::Matrix<double,
>> -0x00000000000000001, -0x00000000000000001, 0, -0x00000000000000001,
>> -0x00000000000000001>, 0, Eigen::Stride<0, 0> >::Map(const
>> Eigen::Map<const Eigen::Matrix<double, -0x00000000000000001,
>> -0x00000000000000001, 0, -0x00000000000000001, -0x00000000000000001>,
>> 0, Eigen::Stride<0, 0> >&)
>> make: *** [minimaltest.o] Error 1
>>
>> Here is my session info:
>> > sessionInfo()
>> R version 2.15.2 (2012-10-26)
>> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>>
>> locale:
>> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>> [1] RcppEigen_0.3.1.2 Matrix_1.0-9      lattice_0.20-10   Rcpp_0.10.2
>>
>> loaded via a namespace (and not attached):
>> [1] grid_2.15.2  tools_2.15.2
>>
>> Note that the g++... portion works fine on the command line, so I
>> guess the failure is somewhere in the building of the library. Of
>> course I can get around this by not using the const keyword, but why
>> is there a problem and what is the right fix?
>>
>> Thanks,
>> Mark A
>> _______________________________________________
>> 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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130131/c1f6c4ce/attachment-0001.html>


More information about the Rcpp-devel mailing list