Re: [eigen] Problem extending MatrixBase

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


2010/1/19 Raphaël Poncet <raphael.poncet@xxxxxxxxx>:
> Just to report that Gael solution works here.
>
> To bjacob : I will try to use the development branch. I have two questions :

am I allowed to answer? ;)

> - Right now I inherit my array class from MatrixBase (because I need
> additional
> class data not related to linear algebra e.g. name, etc.). I use this code
> (found somewhere on the net):
>
> ************************************
>
> //! Reference: http://www.ros.org/wiki/eigen
> template<typename T>
> class GridValue : public Eigen::Matrix<T,1,Eigen::Dynamic>
> {
>   typedef Eigen::Matrix<T,1,Eigen::Dynamic> BaseClass;
>
> public:
>   // Copy constructor from any Eigen matrix type
>   template<typename OtherDerived>
>   GridValue(const Eigen::MatrixBase<OtherDerived>& other,
>         const std::string &name_)
>     : BaseClass(other), name(name_)
>   {}
>
>   // Reuse assignment operators from base class
>   using BaseClass::operator=;
>
> private:
>   std::string name;
> };
>
> ****************************************
>
> If I use the new Array class, what should this code become ? Should
> I still inherit from MatrixBase ?

I guess you meant "inherit from Matrix" ?

So no, here you would inherit Array<T,1,Eigen::Dynamic> instead of
Matrix<T,1,Eigen::Dynamic>, and in the Array world, the equivalent
class to MatrixBase is called ArrayBase. In the very unexpected case
where you want to view your array object as a linear algebra matrix
(e.g., to perform a matrix product, or a dot product), then you can
use the .matrix() method on your object. Assuming GrdValue now
inherits Array<...>, then:

GridValue<float> a, b, c;

c = a * b; // coeff wise product
MatrixXf d = a.matrix() * b.matrix().transpose(); // outer product

Does that answer your question?

> - Is there an environment variable to test for the existence of the Array
> class ?
> I would like to write something like :
>
> ***************************
>
> # ifdef EIGEN_HAVE_ARRAY_CLASS
> new code
> #else
> old code
> #endif // EIGEN_HAVE_ARRAY_CLASS
>
> ***************************
>
> This way, my code would still compile with versions of eigen installed
> from linux distros package managers.

Yes you can use:

#if EIGEN_VERSION_AT_LEAST(2,91,0)
newcode
#endif

However, I woud not recommend you to try to support both versions,
that would mean twice the work. Either you stuck with Eigen2, or you
start using Eigen3 features and forget about Eigen2 compatibility.
Here there is a draft explaining the major API differences:

http://eigen.tuxfamily.org/dox-devel/Eigen2ToEigen3.html

gael.

> Thanks,
> Rapha:el
>
> On Sun, Jan 17, 2010 at 8:12 PM, Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
> wrote:
>>
>> On Sun, Jan 17, 2010 at 7:56 PM, Aron Ahmadia <aja2111@xxxxxxxxxxxx>
>> wrote:
>> > Gael, did you mean to modify one of those lines?
>> >
>> >> const CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>
>> >> const CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>
>>
>> arf bad copy/paste, the lines to changes were:
>>
>> const typename Cwise<Derived>::ScalarAddReturnType
>>
>> I said "were", because I've just committed the fix, so if you hg pull
>> -u, then you're good.
>>
>> gael.
>>
>> >
>> > A
>> >
>> > On Sun, Jan 17, 2010 at 9:53 PM, Gael Guennebaud
>> > <gael.guennebaud@xxxxxxxxx> wrote:
>> >> I guess this is because of a recursive dependency. To make it work, in
>> >> the last two functions, replace:
>> >>
>> >> const CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>
>> >>
>> >> by
>> >>
>> >> const CwiseUnaryOp<ei_scalar_add_op<Scalar>, Derived>
>> >>
>> >> gael
>> >>
>> >> On Sun, Jan 17, 2010 at 6:42 PM, Benoit Jacob
>> >> <jacob.benoit.1@xxxxxxxxx> wrote:
>> >>> Le 17 janvier 2010 05:46, Raphaël Poncet <raphael.poncet@xxxxxxxxx> a
>> >>> écrit :
>> >>>> Hello list,
>> >>>>
>> >>>> I'm running into problems while trying to extending MatrixBase as
>> >>>> explained
>> >>>> in the wiki:
>> >>>>
>> >>>> http://eigen.tuxfamily.org/dox/CustomizingEigen.html#ExtendingMatrixBase
>> >>>>
>> >>>> I copied/pasted MatrixBaseAddons.h in my working directory. This code
>> >>>> doesn't compile
>> >>>> (with g++-4.4 or g++-4.3, using Eigen 2.0.5, the version packaged in
>> >>>> my
>> >>>> Ubuntu distro) :
>> >>> [snip]
>> >>>>
>> >>>> However, If i comment out the last 2 declarations in
>> >>>> MatrixBaseAddons.h (the
>> >>>> ones with operator+),
>> >>>> it does compile. What am I doing wrong ?
>> >>>
>> >>> Nothing it seems, I am really puzzled. I fixed an error in our
>> >>> example, there was a missing semicolon, but that wasn't it. I don't
>> >>> understand what ConstantReturnType has to do with it.
>> >>>
>> >>>>
>> >>>> P.S. Btw, I want to extend MatrixBase because I'm only using Array
>> >>>> capabilities in Eigen
>> >>>> in my code atm, and want to get rid of all the cwise()
>> >>>
>> >>> Then why don't you give the development branch a try. It has a Array
>> >>> class where all operations are implicitly cwise.
>> >>>
>> >>> Benoit
>> >>>
>> >>>
>> >>>
>> >>
>> >>
>> >>
>> >
>> >
>> >
>>
>>
>
>



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