This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Template argument deduction error between RowXpr and Block

Tags: None
(comma "," separated)
vkubicki
Registered Member
Posts
14
Karma
0
Hi,

I create a templated function which signature is:

Code: Select all
template<typename InType,
         typename OutType>
void logToMulti(InType& log,
                OutType& multi)


I call it as:

Code: Select all
logToMulti(lnComp, tik_.row(i));


where lnComp is a RowVector (a typedef to a one row Matrix) and tik_ is a Matrix<double>. I get the following error:

Code: Select all
make utest
g++ -m64 -O0 -g -DMC_DEBUG_NEW -Wall -mtune=core2 -pthread -MD -MP -DEIGEN_MATRIXBASE_PLUGIN=\"mixt_EigenMatrixBaseAddons.h\" -fPIC -Isrc/LinAlg -I../boost -I../eigen -I../gtest -I../gtest/include   -c -o src/Composer/mixt_IMixtureComposerBase.o src/Composer/mixt_IMixtureComposerBase.cpp
src/Composer/mixt_IMixtureComposerBase.cpp:1:0: warning: -fPIC ignored for target (all code is position independent) [enabled by default]
src/Composer/mixt_IMixtureComposerBase.cpp: In member function 'void mixt::IMixtureComposerBase::eStep(int)':
src/Composer/mixt_IMixtureComposerBase.cpp:132:25: error: no matching function for call to 'logToMulti(mixt::RowVector<double>&, Eigen::DenseBase<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001> >::RowXpr)'
src/Composer/mixt_IMixtureComposerBase.cpp:132:25: note: candidate is:
src/Composer/../Statistic/mixt_FunctionStatistic.h:44:6: note: void mixt::logToMulti(InType&, OutType&) [with InType = mixt::RowVector<double>, OutType = Eigen::Block<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, 1, -0x00000000000000001, false>]
src/Composer/../Statistic/mixt_FunctionStatistic.h:44:6: note:   no known conversion for argument 2 from 'Eigen::DenseBase<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001> >::RowXpr {aka Eigen::Block<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, 1, -0x00000000000000001, false>}' to 'Eigen::Block<Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>, 1, -0x00000000000000001, false>&'
make: *** [src/Composer/mixt_IMixtureComposerBase.o] Error 1


While the following code compiles without problem (Real is a typedef for double):

Code: Select all
RowVector<Real> dummyVec;
logToMulti(lnComp,
           dummyVec);
tik_.row(i) = dummyVec;


The compiler is gcc. What I do not understand is why the compiler does not find any function with a RowXpr parameter, and only finds a candidate with Eigen::Block for the second parameter. Since logToMulti is templated, shouldn't the candidate with RowXpr as the second parameter be automatically generated ?

Regards
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
In c++ temporaries cannot be bound to a non const reference. Here, tik_.row(i) returns a temporary Block<> object referencing the i-th row of tik. If you really need read-write object, then either use the Eigen::Ref<> class, or use a const ref with a const_cast, or you can also name the object, in c++11:

auto ri = tik_.row(i);
logToMulti(lnComp,ri);
vkubicki
Registered Member
Posts
14
Karma
0
Thank you for your explanation ! I can now link this problem to what is presented on the doc: http://eigen.tuxfamily.org/dox-devel/To ... Types.html .


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]