Re: [eigen] eigen sqrt compilation error |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] eigen sqrt compilation error
- From: Patrick Mihelich <patrick.mihelich@xxxxxxxxx>
- Date: Fri, 19 Jun 2009 03:29:17 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=lC4Zj2zVShJYTFEOaLH2kwSfB+KZbphoPISu9rnJHZg=; b=BAm8UMCzbTR4Us46xd76KHNnkMJK7i2ZBjyuzghk3BstmI5M0PwJ9SSSqy0NVxMalQ hhYMDB4yi4TPCM5EH7jnoV/IoyZhZCq8EMBLiFycGswPI+iQh4O4up/4x1etYVO7SS0p mRr9ul56bf5udz1VAsVlvt1lB+E2nYIQ26u8c=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=PAu4w/zPvuJg8Y2b6LxDl5ZDRQoUiymFelmi8RzirgzMgoAJwW7/IERQUHAABZ7U5v jtzp27KUE+fdfSXuNLcUI4MvzmXExF18Z39KeWOyIyjrwOfgeZeFtNXurBN8VmiaN+dJ EJ/03ro2OdqxcnvH8bUXY+D1o3cFmmFmiqoPc=
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