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

How to derive a new matrix class

Tags: None
(comma "," separated)
hengcheng
Registered Member
Posts
2
Karma
0

How to derive a new matrix class

Mon Mar 16, 2009 7:56 am
Hi all,

I am writing code for a robotic project, in which I need use small fixed size matrix. For efficiency reasons, I want to derive a few special matrices class, such as ZeroMatrix (without data), SkewSymmetricMatrix (with a Vector3d data), etc., and specialize several operations (such as addition, multiplication) for these classes.

Are there existing examples available?

I tried to write such code (attached below), however MS VC8 won't compile with error messages like:
======================================================
1>c:usersalexdesktopeigen-2.0.0vc8rbdrbdmain.cpp(8) : error C2143: syntax error : missing ';' before 'c:usersalexdesktopeigen-2.0.0vc8rbdrbdmain.cpp(22) : error C2504: 'MatrixBase' : base class undefined
======================================================

Can someone help me?
Thanks a lot.

======================================================
#include

template
struct ei_traits >
{
//typedef typename Scalar Scalar;
enum {
RowsAtCompileTime = Rows;
ColsAtCompileTime = Cols;
MaxRowsAtCompileTime = Rows,
MaxColsAtCompileTime = Cols;
Flags = LinearAccessBit | DirectAccessBit | ZeroDiagBit,
CoeffReadCost = NumTraits::ReadCost
};
};

template
class ZeroMatrix : public MatrixBase >
{
public:

//EIGEN_GENERIC_PUBLIC_INTERFACE(ZeroMatrix)

inline ZeroMatrix()
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(CoeffsVectorType);
ei_assert(coeffs.size() > 0);
}

inline int rows() const { return Rows; }
inline int cols() const { return Cols; }

inline const Scalar coeff(int row, int col) const
{
return static_cast(0);
}

//template
//const CwiseBinaryOp::Scalar>, Derived, OtherDerived>
//operator-(const MatrixBase &other) const;

//template
//const typename ProductReturnType::Type
//operator*(const MatrixBase &other) const;

};

int main(int argc, char *argv[])
{
}
======================================================
User avatar
bjacob
Registered Member
Posts
658
Karma
3
About ZeroMatrix, this is already in Eigen, see the MatrixBase::Zero() static method.

About SkewSymmetric, we're going to have that kind of thing soon, probably in 2.1. Meanwhile, if you want a model to start from, look at an expression class like CwiseUnaryOp and replace the m_matrix member by your vector....

about your error messages, notice that in the enum you should use comma (,) and not semicolon (;)... good luck.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
hengcheng
Registered Member
Posts
2
Karma
0
Thank you. I do find the zeromatrix in the code.

At this point I think I might go ahead to derive a few specialized matrices for my use and hope it will be replaced without much effort later by the new code from Eigen 2.1 release.

BTW, the compilation error was caused by failing to introducing the Eigen namespace, although I included the Eigen/Core header. When I post the code, I has no clue how these error messages happened.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell