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

Matrix class Constructor regression? [3.2.9] => [3.3.1]

Tags: None
(comma "," separated)
takeuchi
Registered Member
Posts
3
Karma
0
Hi Everyone,

I have compilation error with this code on 3.3.1:
Code: Select all
#include <Eigen/Core>
class MyVector{
public:
  MyVector(){x=1;y=2;z=3;}
   double x,y,z;
   operator Eigen::Matrix<double,3,1>() const {return Eigen::Matrix<double,3,1>(x,y,z);}
};
int main(){
   MyVector a;
   Eigen::Matrix<double,3 ,1> b(a);
}

Error messages are as follows:
Code: Select all
In file included from Eigen/Core:432:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h: In instantiation of ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = MyVector; _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 3; int _MaxCols = 1]’:
eigentest2.cpp:14:32:   required from here
Eigen/src/Core/Matrix.h:296:31: error: no matching function for call to ‘Eigen::Matrix<double, 3, 1>::_init1(const MyVector&)’
       Base::template _init1<T>(x);
                               ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/PlainObjectBase.h:761:30: note: candidate: template<class T> void Eigen::PlainObjectBase<Derived>::_init1(Eigen::Index, typename Eigen::internal::enable_if<(((typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != 1) || (! Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value)) && ((! Eigen::internal::is_same<typename Eigen::internal::traits<T>::XprKind, Eigen::ArrayXpr>::value) || (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime == Eigen::Dynamic))), T>::type*) [with T = T; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(Index size, typename internal::enable_if<    (Base::SizeAtCompileTime!=1 || !internal::is_convertible<T, Scalar>::value)
                              ^
Eigen/src/Core/PlainObjectBase.h:761:30: note:   template argument deduction/substitution failed:
In file included from Eigen/Core:432:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h:296:31: note:   cannot convert ‘x’ (type ‘const MyVector’) to type ‘Eigen::Index {aka long int}’
       Base::template _init1<T>(x);
                               ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/PlainObjectBase.h:775:30: note: candidate: template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Scalar&, typename Eigen::internal::enable_if<((typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime == 1) && Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value), T>::type*) [with T = T; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const Scalar& val0, typename internal::enable_if<Base::SizeAtCompileTime==1 && internal::is_convertible<T, Scalar>::value,T>::type* = 0)
                              ^
Eigen/src/Core/PlainObjectBase.h:775:30: note:   template argument deduction/substitution failed:
Eigen/src/Core/PlainObjectBase.h: In substitution of ‘template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Scalar&, typename Eigen::internal::enable_if<((typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime == 1) && Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value), T>::type*) [with T = MyVector]’:
Eigen/src/Core/Matrix.h:296:31:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = MyVector; _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 3; int _MaxCols = 1]’
eigentest2.cpp:14:32:   required from here
Eigen/src/Core/PlainObjectBase.h:775:30: error: invalid use of incomplete type ‘struct Eigen::internal::enable_if<false, MyVector>’
In file included from Eigen/Core:341:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/util/Meta.h:162:50: note: declaration of ‘struct Eigen::internal::enable_if<false, MyVector>’
 template<bool Condition, typename T=void> struct enable_if;
                                                  ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h: In instantiation of ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = MyVector; _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 3; int _MaxCols = 1]’:
eigentest2.cpp:14:32:   required from here
Eigen/src/Core/PlainObjectBase.h:784:30: note: candidate: template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Index&, typename Eigen::internal::enable_if<((((! Eigen::internal::is_same<long int, typename Eigen::internal::traits<T>::Scalar>::value) && Eigen::internal::is_same<long int, T>::value) && (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime == 1)) && Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value), T*>::type*) [with T = T; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const Index& val0,
                              ^
Eigen/src/Core/PlainObjectBase.h:784:30: note:   template argument deduction/substitution failed:
Eigen/src/Core/PlainObjectBase.h: In substitution of ‘template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Index&, typename Eigen::internal::enable_if<((((! Eigen::internal::is_same<long int, typename Eigen::internal::traits<T>::Scalar>::value) && Eigen::internal::is_same<long int, T>::value) && (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime == 1)) && Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value), T*>::type*) [with T = MyVector]’:
Eigen/src/Core/Matrix.h:296:31:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = MyVector; _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 3; int _MaxCols = 1]’
eigentest2.cpp:14:32:   required from here
Eigen/src/Core/PlainObjectBase.h:784:30: error: invalid use of incomplete type ‘struct Eigen::internal::enable_if<false, MyVector*>’
In file included from Eigen/Core:341:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/util/Meta.h:162:50: note: declaration of ‘struct Eigen::internal::enable_if<false, MyVector*>’
 template<bool Condition, typename T=void> struct enable_if;
                                                  ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h: In instantiation of ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = MyVector; _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 3; int _MaxCols = 1]’:
eigentest2.cpp:14:32:   required from here
Eigen/src/Core/PlainObjectBase.h:797:30: note: candidate: template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Scalar*) [with T = T; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const Scalar* data){
                              ^
Eigen/src/Core/PlainObjectBase.h:797:30: note:   template argument deduction/substitution failed:
In file included from Eigen/Core:432:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h:296:31: note:   cannot convert ‘x’ (type ‘const MyVector’) to type ‘const Scalar* {aka const double*}’
       Base::template _init1<T>(x);
                               ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/PlainObjectBase.h:804:30: note: candidate: template<class T, class OtherDerived> void Eigen::PlainObjectBase<Derived>::_init1(const Eigen::DenseBase<ElseDerived>&) [with T = T; OtherDerived = OtherDerived; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const DenseBase<OtherDerived>& other){
                              ^
Eigen/src/Core/PlainObjectBase.h:804:30: note:   template argument deduction/substitution failed:
In file included from Eigen/Core:432:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h:296:31: note:   ‘const MyVector’ is not derived from ‘const Eigen::DenseBase<Derived>’
       Base::template _init1<T>(x);
                               ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/PlainObjectBase.h:811:30: note: candidate: template<class T, class OtherDerived> void Eigen::PlainObjectBase<Derived>::_init1(const Eigen::EigenBase<OtherDerived>&) [with T = T; OtherDerived = OtherDerived; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const EigenBase<OtherDerived>& other){
                              ^
Eigen/src/Core/PlainObjectBase.h:811:30: note:   template argument deduction/substitution failed:
In file included from Eigen/Core:432:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h:296:31: note:   ‘const MyVector’ is not derived from ‘const Eigen::EigenBase<OtherDerived>’
       Base::template _init1<T>(x);
                               ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/PlainObjectBase.h:817:30: note: candidate: template<class T, class OtherDerived> void Eigen::PlainObjectBase<Derived>::_init1(const Eigen::ReturnByValue<OtherDerived>&) [with T = T; OtherDerived = OtherDerived; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const ReturnByValue<OtherDerived>& other)
                              ^
Eigen/src/Core/PlainObjectBase.h:817:30: note:   template argument deduction/substitution failed:
In file included from Eigen/Core:432:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h:296:31: note:   ‘const MyVector’ is not derived from ‘const Eigen::ReturnByValue<OtherDerived>’
       Base::template _init1<T>(x);
                               ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/PlainObjectBase.h:825:30: note: candidate: template<class T, class OtherDerived, int ColsAtCompileTime> void Eigen::PlainObjectBase<Derived>::_init1(const Eigen::RotationBase<OtherDerived, ColsAtCompileTime>&) [with T = T; OtherDerived = OtherDerived; int ColsAtCompileTime = ColsAtCompileTime; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const RotationBase<OtherDerived,ColsAtCompileTime>& r)
                              ^
Eigen/src/Core/PlainObjectBase.h:825:30: note:   template argument deduction/substitution failed:
In file included from Eigen/Core:432:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h:296:31: note:   ‘const MyVector’ is not derived from ‘const Eigen::RotationBase<OtherDerived, ColsAtCompileTime>’
       Base::template _init1<T>(x);
                               ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/PlainObjectBase.h:833:30: note: candidate: template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Scalar&, typename Eigen::internal::enable_if<((((typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != Eigen::Dynamic) && (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != 1)) && Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value) && Eigen::internal::is_same<typename Eigen::internal::traits<T>::XprKind, Eigen::ArrayXpr>::value), T>::type*) [with T = T; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const Scalar& val0,
                              ^
Eigen/src/Core/PlainObjectBase.h:833:30: note:   template argument deduction/substitution failed:
Eigen/src/Core/PlainObjectBase.h: In substitution of ‘template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Scalar&, typename Eigen::internal::enable_if<((((typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != Eigen::Dynamic) && (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != 1)) && Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value) && Eigen::internal::is_same<typename Eigen::internal::traits<T>::XprKind, Eigen::ArrayXpr>::value), T>::type*) [with T = MyVector]’:
Eigen/src/Core/Matrix.h:296:31:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = MyVector; _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 3; int _MaxCols = 1]’
eigentest2.cpp:14:32:   required from here
Eigen/src/Core/PlainObjectBase.h:833:30: error: invalid use of incomplete type ‘struct Eigen::internal::enable_if<false, MyVector>’
In file included from Eigen/Core:341:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/util/Meta.h:162:50: note: declaration of ‘struct Eigen::internal::enable_if<false, MyVector>’
 template<bool Condition, typename T=void> struct enable_if;
                                                  ^
In file included from Eigen/Core:431:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/Matrix.h: In instantiation of ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = MyVector; _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 3; int _MaxCols = 1]’:
eigentest2.cpp:14:32:   required from here
Eigen/src/Core/PlainObjectBase.h:844:30: note: candidate: template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Index&, typename Eigen::internal::enable_if<((((((! Eigen::internal::is_same<long int, typename Eigen::internal::traits<T>::Scalar>::value) && Eigen::internal::is_same<long int, T>::value) && (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != Eigen::Dynamic)) && (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != 1)) && Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value) && Eigen::internal::is_same<typename Eigen::internal::traits<T>::XprKind, Eigen::ArrayXpr>::value), T*>::type*) [with T = T; Derived = Eigen::Matrix<double, 3, 1>]
     EIGEN_STRONG_INLINE void _init1(const Index& val0,
                              ^
Eigen/src/Core/PlainObjectBase.h:844:30: note:   template argument deduction/substitution failed:
Eigen/src/Core/PlainObjectBase.h: In substitution of ‘template<class T> void Eigen::PlainObjectBase<Derived>::_init1(const Index&, typename Eigen::internal::enable_if<((((((! Eigen::internal::is_same<long int, typename Eigen::internal::traits<T>::Scalar>::value) && Eigen::internal::is_same<long int, T>::value) && (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != Eigen::Dynamic)) && (typename Eigen::internal::dense_xpr_base<Derived>::type:: SizeAtCompileTime != 1)) && Eigen::internal::is_convertible<T, typename Eigen::internal::traits<T>::Scalar>::value) && Eigen::internal::is_same<typename Eigen::internal::traits<T>::XprKind, Eigen::ArrayXpr>::value), T*>::type*) [with T = MyVector]’:
Eigen/src/Core/Matrix.h:296:31:   required from ‘Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::Matrix(const T&) [with T = MyVector; _Scalar = double; int _Rows = 3; int _Cols = 1; int _Options = 0; int _MaxRows = 3; int _MaxCols = 1]’
eigentest2.cpp:14:32:   required from here
Eigen/src/Core/PlainObjectBase.h:844:30: error: invalid use of incomplete type ‘struct Eigen::internal::enable_if<false, MyVector*>’
In file included from Eigen/Core:341:0,
                 from eigentest2.cpp:1:
Eigen/src/Core/util/Meta.h:162:50: note: declaration of ‘struct Eigen::internal::enable_if<false, MyVector*>’
 template<bool Condition, typename T=void> struct enable_if;

It was working on 3.2.9. I'm using gcc version 5.4.0 on Ubuntu(x86_64-linux-gnu).
Could you give me some advice on this?
Thank you very much in advance!
Hiroshi
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is because in 3.3 we had to introduce a generic ctor:
Code: Select all
template<typename T> explicit Matrix(const T& x) {...}

that prevents your conversion operator to be called. On the other hand, since this generic ctor is explicit, you can easily workaround with:
Code: Select all
Eigen::Matrix<double,3 ,1> b = a;
takeuchi
Registered Member
Posts
3
Karma
0
I could successfully compile my code. Thank you very much for the help!


Bookmarks



Who is online

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