Re: [eigen] AnyMatrixBase

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


2010/6/9 Stefan Ulbrich <s.ulbrich@xxxxxxxxxxxxxx>:
> Hello,
>
> I've been looking for a common base class for MatrixXi and CwiseNullaryOp in oder to address both by a pointer. As I understood there doesn't exist any in order to avoid virtual classes.

There is, it's template<typename Derived> MatrixBase.

Or if you have not only Matrix but also Array into play, replace
MatrixBase by DenseBase.

> In the forum I found a thread refering to a class AnyMatrixBase which I'm unable to find in the recent development tree. A different suggestion was using variant classes.

This AnyMatrixBase is nowadays called EigenBase, but it is at the very
bottom of the class hierarchy, probably not what you want.

> How about an class exhibiting the most common methods of MatrixBase (Proxy Pattern)? This proxy could indeed be a virtual function allowing polymorphism.

No, virtual means runtime polymorphism, which is incompatible with
Eigen allowing optimizations to happen at compile time. The scheme
above, template<typename Derived> class Base, is a compile-time flavor
of polymorphism.

Benoit

>
>
> template <typename Scalar>
> class
> AnyMatrixBase {
>        public:
>        virtual Scalar operator()(int,int) const = 0;
> };
>
>
> template<typename MatrixType>
> class AnyMatrix : public AnyMatrixBase<typename ei_traits<MatrixType>::Scalar>  {
>        public:
>                typedef typename ei_traits<MatrixType>::Scalar Scalar;
>                AnyMatrix(MatrixType *m) : m_ref(m){};
>                virtual Scalar operator()(int i,int j) const {
>                        m_ref->operator()(i,j);
>                };
>        private:
>                boost::scoped_ptr<MatrixType> m_ref;
> };
>
>
> A completely different question: are there any attempts to serialize Eigen objects (e.g., like boost.serialize does)?
>
>
> Best regards
> Stefan
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/