Re: [eigen] Re: VectorBase issue

[ Thread Index | Date Index | More Archives ]

On Wed, Jun 4, 2008 at 12:03 AM, Benoît Jacob <jacob@xxxxxxxxxxxxxxx> wrote:

> Actually I think this is good in general since
> it allows to overload a MatrixBase member in Derived, and the proper
> overload will be called.

Sorry, I don't understand what you mean. Can you explain?

This is a general problem that is not only related to VectorBase:
The point is the following: let's assume an _expression_ (the Derived class) overload the method inverse() (like Quaternion). Then you have a templated method foo which takes an _expression_ like this:
template<typename OtherDerived> void foo(const MatrixBase<OtherDerived>& other) {
  blabla   other.inverse() blabla;

then the correct overload won't be called... instead you could define foo to directly takes a "const OtherDerived&" (but that's not nice because too generic) or systematically call .derived() to MatrixBase<> object:
that is, IMO, in the spirit of the CRT pattern...

to get back to VectorBase, the motivation of VectorBase was two folds:
 1 - better API by hiding vector specific methods from matrix expressions (aka compile time errors).
 2 - faster compilation for matrix code.
Another minor advantage is that all vector specific methods get grouped in a separate class.

For the first point, after a chat with Benoit, we agreed to add support for compile time checks using custom static_assert (see recent commit).
This solution is more general since it allows any kind of compile time checks. However that doesnot make MatrixBase lighter for matrix and so no compile time gain...


> So, any suggestion ? should I give up with VectorBase ? and if not, which
> options looks the best for issue 2 ?

Hey, I have an idea so we can go on with VectorBase :)

How about just leaving all the methods, including the vector-specific ones, in
MatrixBase; but then have the vector-specific ones call a special method from
VectorBase -- so that compilation will fail if VectorBase doesn't have that

Like this:

Scalar& coeffRef(int i)
return derived()._coeffRef(i);

So that the user will see a nice compiler error message :)

This works also the other way around, "only for matrices", "only for dynamic
size", "only for fixed-size", "only for matrices that have any chance of
being square" etc... we could have many such checks.

What do you think?

The main issue for me is not so much catching errors at compile time versus
runtime, this is nice but not vital. What matters more to me is reducing
compilation time, so if VectorBase can help with that it's more than welcome.


Mail converted by MHonArc 2.6.19+