Registered Member
|
Hi,
Apologies for my previous post I still have pending to send an example code but I've had to leave that task aside for the moment, hopefully I'll go back to that soon. So now I have another question. I have a templated function that receives a MatrixBase<Derived1>& as template argument. If this argument is a Map how can I declare inside this function I variable of the same type as the type argument of that Map. example: template<class Derived1, class Derived2> Derived1 filterRows(Eigen::MatrixBase<Derived1> &data, Eigen::ArrayBase<Derived2> &boolMap) { Derived1 result(data.rows(), data.cols()); int count = 0; for(int i = 0; i < data.rows(); i++) if(boolMap(i)) { result.row(count) = data.row(i); count++; } result.conservativeResize(count, NoChange); return result; } void main() { MatrixXd m1 = MatrixXd::Random(50, 20); Map<MatrixXd> mapm1(m1.data(), 50, 20); Array<bool, Dynamic, 1> boolMap = Array<bool, Dynamic, 1>::Random(50); MatrixXd filteredM1; filteredM1 = filterRows(m1, boolMap); //filteredM1 = filterRows(mapm1, boolMap); } This code as it is works well, but when I uncomment the last line in main and recompile I get an error in the line Derived1 result(data.rows(), data.cols()); I assume that what I need is to declare result as being the same type as the mapped type. I have tried to declare result as being a MatrixBase<Derived1>::PlainMatrixType or Derived1::PlainObjectType but does compile. How can I declare result to be of the type mapped by the map? Thanks, Martin |
Moderator
|
typename Derived1::PlainObject
the "typename" keyword is important here! |
Registered Member
|
It works!! it was the missing typename keyword.
Thanks! Martin |
Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]