I'm trying to replace the function for the sum of 3x1 Vector in Eigen with my own function. For example,
Matrix<float, 3, 1> q, q2, q3;
q.setRandom();
q2.setRandom();
q3.setRandom();
q3 = q + q2;
I hope that q3 is computed by my own function.
Since Eigen actually computes the sum by the operator= instead of operator+, and operator+ just returns a CwiseBinaryOp objects, I need to do overload the operator=.
Now I'm using EIGEN_MATRIX_PLUGIN marco to add my code to the Matrix.h of Eigen:
inline Matrix<float, 3, 1> &operator=(
const CwiseBinaryOp<internal::scalar_sum_op<float>, const Matrix<float, 3, 1>, const Matrix<float, 3, 1>>
&op) {
float *t = m_storage.data();
op.lhs(); //error here
return *this;
}
My own function needs to access the pointer to the data of q, q2 and q3. But I got the following error when trying to access the data of q and q2 by the CwiseBinaryOp object.
In file included from /home/tong/Program/Eigen/Eigen/src/Core/Matrix.h:340:0,
from /home/tong/Program/Eigen/Eigen/Core:294,
from /home/tong/Program/Eigen/Eigen/Dense:1,
from /home/tong/ClionProjects/EigenTest/main.cpp:7:
/home/tong/ClionProjects/EigenTest/MatrixAddon.h: In member function ‘Eigen::Matrix<float, 3, 1>& Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>::operator=(const Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<float>, const Eigen::Matrix<float, 3, 1>, const Eigen::Matrix<float, 3, 1> >&)’:
/home/tong/ClionProjects/EigenTest/MatrixAddon.h:12:7: error: invalid use of incomplete type ‘const class Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<float>, const Eigen::Matrix<float, 3, 1>, const Eigen::Matrix<float, 3, 1> >’
op.lhs();
^
In file included from /home/tong/Program/Eigen/Eigen/Core:252:0,
from /home/tong/Program/Eigen/Eigen/Dense:1,
from /home/tong/ClionProjects/EigenTest/main.cpp:7:
/home/tong/Program/Eigen/Eigen/src/Core/util/ForwardDeclarations.h:89:65: error: declaration of ‘const class Eigen::CwiseBinaryOp<Eigen::internal::scalar_sum_op<float>, const Eigen::Matrix<float, 3, 1>, const Eigen::Matrix<float, 3, 1> >’
template<typename BinaryOp, typename Lhs, typename Rhs> class CwiseBinaryOp;
I wonder why does this error appear and how to get rid of it.