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

invalid use of incomplete type in a CwiseBinaryOp

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

as mentioned in a previous post, I am creating an interface to include Eigen in an existing project. I created a template Matrix class:

Code: Select all
template<typename T,
         int _Rows = Eigen::Dynamic,
         int _Cols = Eigen::Dynamic>
class Matrix : public Eigen::Matrix<T, _Rows, _Cols>


which adds an operator % for component-wise multiplication:

Code: Select all
/** Component-wise product */
template<typename OtherDerived>
const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<T, T>,
                           const Eigen::Matrix<T, _Rows, _Cols>,
                           const Eigen::MatrixBase<OtherDerived> >
operator%(const Eigen::MatrixBase<OtherDerived>& other) const
{
  return Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<T, T>,
                              const Eigen::Matrix<T, _Rows, _Cols>,
                              const Eigen::MatrixBase<OtherDerived> >(this->derived(),
                                                                      other.derived(),
                                                                      Eigen::internal::scalar_product_op<T, T>());
}


At compilation, I get the following error:

Code: Select all
g++ -MD -MP -fPIC -I.. -I../boost -I../eigen src/Prog/mcTest.cpp -o ./bin/mcTest
In file included from ../eigen/Eigen/Core:252:0,
                 from ../eigen/Eigen/Dense:1,
                 from src/Prog/../LinAlg/mixt_LinAlg.h:27,
                 from src/Prog/mcTest.cpp:25:
../eigen/Eigen/src/Core/util/ForwardDeclarations.h: In instantiation of ‘struct Eigen::internal::traits<const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’:
../eigen/Eigen/src/Core/CwiseBinaryOp.h:106:7:   required from ‘class Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
src/Prog/mcTest.cpp:36:32:   required from here
../eigen/Eigen/src/Core/util/ForwardDeclarations.h:23:29: error: invalid use of incomplete type ‘struct Eigen::internal::traits<Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
 template<typename T> struct traits<const T> : traits<T> {};
                             ^
../eigen/Eigen/src/Core/util/ForwardDeclarations.h:17:29: error: declaration of ‘struct Eigen::internal::traits<Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
 template<typename T> struct traits;
                             ^
In file included from ../eigen/Eigen/Core:296:0,
                 from ../eigen/Eigen/Dense:1,
                 from src/Prog/../LinAlg/mixt_LinAlg.h:27,
                 from src/Prog/mcTest.cpp:25:
../eigen/Eigen/src/Core/CwiseBinaryOp.h: In instantiation of ‘class Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’:
src/Prog/mcTest.cpp:36:32:   required from here
../eigen/Eigen/src/Core/CwiseBinaryOp.h:106:7: error: no type named ‘StorageKind’ in ‘struct Eigen::internal::traits<const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
 class CwiseBinaryOp : internal::no_assignment_operator,
       ^
../eigen/Eigen/src/Core/CwiseBinaryOp.h:117:99: error: no type named ‘StorageKind’ in ‘struct Eigen::internal::traits<const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
                                          typename internal::traits<Rhs>::StorageKind>::ret>::Base Base;
                                                                                                   ^
../eigen/Eigen/src/Core/CwiseBinaryOp.h: In instantiation of ‘struct Eigen::internal::traits<Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > > >’:
../eigen/Eigen/src/Core/CwiseBinaryOp.h:118:5:   required from ‘class Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
src/Prog/mcTest.cpp:36:32:   required from here
../eigen/Eigen/src/Core/CwiseBinaryOp.h:60:84: error: no type named ‘StorageKind’ in ‘struct Eigen::internal::traits<const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
                                            typename traits<Rhs>::StorageKind>::ret StorageKind;
                                                                                    ^
../eigen/Eigen/src/Core/CwiseBinaryOp.h:62:77: error: no type named ‘Index’ in ‘struct Eigen::internal::traits<const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
                                          typename traits<Rhs>::Index>::type Index;
                                                                             ^
../eigen/Eigen/src/Core/CwiseBinaryOp.h:64:32: error: no type named ‘Nested’ in ‘const class Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> >’
   typedef typename Rhs::Nested RhsNested;
                                ^
../eigen/Eigen/src/Core/CwiseBinaryOp.h:66:54: error: no type named ‘Nested’ in ‘const class Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> >’
   typedef typename remove_reference<RhsNested>::type _RhsNested;
                                                      ^
../eigen/Eigen/src/Core/CwiseBinaryOp.h:67:8: error: no type named ‘Nested’ in ‘const class Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> >’
   enum {
        ^
../eigen/Eigen/src/Core/CwiseBinaryOp.h: In instantiation of ‘class Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’:
src/Prog/mcTest.cpp:36:32:   required from here
../eigen/Eigen/src/Core/CwiseBinaryOp.h:121:50: error: no type named ‘StorageKind’ in ‘struct Eigen::internal::traits<const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
     typedef typename internal::nested<Rhs>::type RhsNested;
                                                  ^
../eigen/Eigen/src/Core/CwiseBinaryOp.h:123:66: error: no type named ‘StorageKind’ in ‘struct Eigen::internal::traits<const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’
     typedef typename internal::remove_reference<RhsNested>::type _RhsNested;
                                                                  ^
src/Prog/mcTest.cpp: In function ‘int main()’:
src/Prog/mcTest.cpp:36:6: error: no match for ‘operator=’ (operand types are ‘mixt::Matrix<double>’ and ‘const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’)
   m2 = m1 % m2.block(2, 2, 3, 3);
      ^
src/Prog/mcTest.cpp:36:6: note: candidates are:
In file included from src/Prog/mcTest.cpp:25:0:
src/Prog/../LinAlg/mixt_LinAlg.h:68:13: note: template<class OtherDerived> mixt::Matrix<T, _Rows, _Cols>& mixt::Matrix<T, _Rows, _Cols>::operator=(const Eigen::MatrixBase<OtherDerived>&) [with OtherDerived = OtherDerived; T = double; int _Rows = -1; int _Cols = -1]
     Matrix& operator=(const Eigen::MatrixBase<OtherDerived>& other)
             ^
src/Prog/../LinAlg/mixt_LinAlg.h:68:13: note:   template argument deduction/substitution failed:
src/Prog/mcTest.cpp:36:6: note:   ‘const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’ is not derived from ‘const Eigen::MatrixBase<Derived>’
   m2 = m1 % m2.block(2, 2, 3, 3);
      ^
In file included from src/Prog/mcTest.cpp:25:0:
src/Prog/../LinAlg/mixt_LinAlg.h:75:13: note: mixt::Matrix<T, _Rows, _Cols>& mixt::Matrix<T, _Rows, _Cols>::operator=(const T&) [with T = double; int _Rows = -1; int _Cols = -1]
     Matrix& operator=(const T& scalar)
             ^
src/Prog/../LinAlg/mixt_LinAlg.h:75:13: note:   no known conversion for argument 1 from ‘const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’ to ‘const double&’
src/Prog/../LinAlg/mixt_LinAlg.h:49:7: note: mixt::Matrix<double>& mixt::Matrix<double>::operator=(const mixt::Matrix<double>&)
 class Matrix : public Eigen::Matrix<T, _Rows, _Cols>
       ^
src/Prog/../LinAlg/mixt_LinAlg.h:49:7: note:   no known conversion for argument 1 from ‘const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<double, double>, const Eigen::Matrix<double, -1, -1>, const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> > >’ to ‘const mixt::Matrix<double>&’
In file included from ../eigen/Eigen/Core:296:0,
                 from ../eigen/Eigen/Dense:1,
                 from src/Prog/../LinAlg/mixt_LinAlg.h:27,
                 from src/Prog/mcTest.cpp:25:
../eigen/Eigen/src/Core/CwiseBinaryOp.h: In instantiation of ‘Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::CwiseBinaryOp(const Lhs&, const Rhs&, const BinaryOp&) [with BinaryOp = Eigen::internal::scalar_product_op<double, double>; Lhs = const Eigen::Matrix<double, -1, -1>; Rhs = const Eigen::MatrixBase<Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false> >]’:
src/Prog/../LinAlg/mixt_LinAlg.h:150:117:   required from ‘const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<T, T>, const Eigen::Matrix<T, _Rows, _Cols>, const Eigen::MatrixBase<OtherDerived> > mixt::Matrix<T, _Rows, _Cols>::operator%(const Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived = Eigen::Block<Eigen::Matrix<double, -1, -1>, -1, -1, false>; T = double; int _Rows = -1; int _Cols = -1]’
src/Prog/mcTest.cpp:36:32:   required from here
../eigen/Eigen/src/Core/CwiseBinaryOp.h:126:49: error: using invalid field ‘Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::m_rhs’
       : m_lhs(aLhs), m_rhs(aRhs), m_functor(func)


Can someone help me resolve this problem ?

Thank you,

VK
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You should rather add it as a plugin to MatrixBase (or DenseBase), and copy/paste the code of cwiseProduct to make it an alias:
Code: Select all
template<typename OtherDerived>
EIGEN_STRONG_INLINE const EIGEN_CWISE_PRODUCT_RETURN_TYPE(Derived,OtherDerived)
operator%(const MatrixBase<OtherDerived> &other) const
{
  return EIGEN_CWISE_PRODUCT_RETURN_TYPE(Derived,OtherDerived)(derived(), other.derived());
}

For the curiosity, EIGEN_CWISE_PRODUCT_RETURN_TYPE is defined in Eigen/src/Core/util/Macros.h
vkubicki
Registered Member
Posts
14
Karma
0
OK, I will follow your advice and try to implement what I need through the plugin system !


Bookmarks



Who is online

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