Re: [eigen] eigen sqrt compilation error

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


On Fri, Jun 19, 2009 at 12:37 AM, Moritz Lenz <mlenz@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
Considering the number of times people make this error (forgetting to include it), what about including it by default? Is there a very good reason not to do it?

I wonder this too. I ran into this error when I started using Eigen, and it seems to pop up regularly on the list. What exactly is the cost of including <Eigen/Array> in the core? How much does it increase compile times? Documentation is good, but it is still too easy to use the Eigen API incorrectly like this, and the error messages are no help.

Awhile back I suggested a trick based on default arguments, which is a little ugly but does massively improve the error messages. Here it is again:

// Changes to MatrixBase
template<typename Derived> class MatrixBase
{
  private:
    struct ERROR_YOU_MUST_INCLUDE_Eigen_Array {};

  public:
    const PartialRedux<Derived, Horizontal> rowwise(ERROR_YOU_MUST_INCLUDE_Eigen_Array) const;
};

// Changes to implementation in Array module
// Defining the default argument here changes the function signature, allowing matrix.rowwise()
template<typename Derived>
const PartialRedux<Derived,Horizontal> MatrixBase<Derived>::rowwise(ERROR_YOU_MUST_INCLUDE_Eigen_Array = ERROR_YOU_MUST_INCLUDE_Eigen_Array()) const
{
  /* implementation */
}

Then when the user includes <Eigen/Array>, he effectively gets the expected zero-arg version of rowwise. If he forgets to include it, no zero-arg version exists, so mat.rowwise() should produce a compiler error along the lines of:

error: no matching function for call to 'MatrixBase<Derived>::rowwise()'
note: candidates are: const PartialRedux<Derived, 0> MatrixBase<Derived>::rowwise(MatrixBase<Derived>::ERROR_YOU_MUST_INCLUDE_Eigen_Array) const

As usual you can wrap the dummy argument in a macro to selectively hide it from doxygen.

Cheers,
Patrick


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