Re: [eigen] patches for EIGEN_STATIC_ASSERT |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] patches for EIGEN_STATIC_ASSERT
- From: "Benoit Jacob" <jacob.benoit.1@xxxxxxxxx>
- Date: Thu, 18 Dec 2008 04:57:04 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=AEmik0olUjuaPz4ww58cABV3zXTNQAB0IrTM3nIDeh8=; b=nJn6TuIwXcXCnynnlRJKyaKe7d+kxDUP1pIwrz2mJHcFxO74daWDo3bWP2SOR4RXAF gt8jHVBqORHS3fecUOcZXcwohrTYmOyy0PpmpN+xS8JWirIhlu0vlpiHGC/mw8JNcMbS qdkhXe/AZIPKssvdhRHX29XZT74JIbeGKIyjE=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=r24qlA8QxirDhyly+7j1Ba7BmP5lMfxQi6Fe6YUljNfBCWH6ZcdL1x9qw0cnJJsvvj 1Kp1+7qsZqJmd/iLNHULl440IhL8uNGUpW+O1VS3ZCL9Fovr6NSZFJfFrbih4FJPzg6L oKpDhjdKOnXIQBWza/miFUE8hWs1Illcn5hTA=
Thanks for your patches. In principle I like them, buy my GCC 4.3
doesn't seem to (see below)... which shows that these things are
immensely compiler-dependent and that it's going to be difficult to
find a good solution for everyone.
So I make this counter-proposal to you: how about simply turning off
the MSVC warning with a #pragma ?
In order to test the effect of your patches with GCC, I tried this program:
#include <Eigen/Core>
int main() {
Eigen::Matrix4d m;
Eigen::Matrix2d n;
std::cout << (m + n) << std::endl;
}
First of all I had to add a static assert in CwiseBinaryOp.h to guard
that as somehow we had forgotten to. So, please 'svn up' before if you
want to try.
With the current Eigen, the whole compiler output I get (gcc 4.3) is:
=== BEGIN GCC OUTPUT =================================
cuisine/trunk/kdesupport/eigen2/Eigen/src/Core/CwiseBinaryOp.h: In
constructor 'Eigen::CwiseBinaryOp<BinaryOp, Lhs,
Rhs>::CwiseBinaryOp(const Lhs&, const Rhs&, const BinaryOp&) [with
BinaryOp = Eigen::ei_scalar_sum_op<double>, Lhs =
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Rhs = Eigen::Matrix<double, 2,
2, 0, 2, 2>]':
cuisine/trunk/kdesupport/eigen2/Eigen/src/Core/CwiseBinaryOp.h:181:
instantiated from 'const
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<typename
Eigen::ei_traits<T>::Scalar>, Derived, OtherDerived>
Eigen::MatrixBase<Derived>::operator+(const
Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived =
Eigen::Matrix<double, 2, 2, 0, 2, 2>, Derived = Eigen::Matrix<double,
4, 4, 0, 4, 4>]'
xdfk.cpp:5: instantiated from here
cuisine/trunk/kdesupport/eigen2/Eigen/src/Core/CwiseBinaryOp.h:105:
error: 'you_mixed_matrices_of_different_sizes' is not a member of
'Eigen::ei_static_assert<false>'
=== END GCC OUTPUT =================================
....which is pretty good. i'd even say it's optimal: the error message
is uncluttered, printed at the end, and the only other stuff printed
is the back-trace.
With your 1st patch, the compilation of this program.... succeeds (no
compiler output at all)! So i get a binary that of course failed on an
assertion at runtime.
With your 2nd patch, the compiler output is:
=== BEGIN GCC OUTPUT =================================
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/CwiseBinaryOp.h:
In constructor 'Eigen::CwiseBinaryOp<BinaryOp, Lhs,
Rhs>::CwiseBinaryOp(const Lhs&, const Rhs&, const BinaryOp&) [with
BinaryOp = Eigen::ei_scalar_sum_op<double>, Lhs =
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Rhs = Eigen::Matrix<double, 2,
2, 0, 2, 2>]':
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/CwiseBinaryOp.h:180:
instantiated from 'const
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<typename
Eigen::ei_traits<T>::Scalar>, Derived, OtherDerived>
Eigen::MatrixBase<Derived>::operator+(const
Eigen::MatrixBase<OtherDerived>&) const [with OtherDerived =
Eigen::Matrix<double, 2, 2, 0, 2, 2>, Derived = Eigen::Matrix<double,
4, 4, 0, 4, 4>]'
xdfk.cpp:5: instantiated from here
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/CwiseBinaryOp.h:102:
error: template argument for 'template<bool condition, class message>
struct Eigen::ei_static_assert' uses local type
'Eigen::CwiseBinaryOp<BinaryOp, Lhs, Rhs>::CwiseBinaryOp(const Lhs&,
const Rhs&, const BinaryOp&) [with BinaryOp =
Eigen::ei_scalar_sum_op<double>, Lhs = Eigen::Matrix<double, 4, 4, 0,
4, 4>, Rhs = Eigen::Matrix<double, 2, 2, 0, 2,
2>]::ERROR_you_mixed_different_numeric_types__you_need_to_use_the_cast_method_of_MatrixBase_to_cast_numeric_types_explicitly'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/CwiseBinaryOp.h:102:
error: trying to instantiate 'template<bool condition, class
message> struct Eigen::ei_static_assert'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Assign.h: In
member function 'Derived& Eigen::MatrixBase<Derived>::lazyAssign(const
Eigen::MatrixBase<OtherDerived>&) [with OtherDerived =
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Derived = Eigen::Matrix<double,
4, 4, 0, 4, 4>]':
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Matrix.h:424:
instantiated from 'Eigen::Matrix<_Scalar, _Rows, _Cols, _StorageOrder,
_MaxRows, _MaxCols>::Matrix(const Eigen::Matrix<_Scalar, _Rows, _Cols,
_StorageOrder, _MaxRows, _MaxCols>&) [with _Scalar = double, int _Rows
= 4, int _Cols = 4, int _StorageOrder = 0, int _MaxRows = 4, int
_MaxCols = 4]'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/MatrixBase.h:487:
instantiated from 'const typename Eigen::ei_eval<T,
(Eigen::ei_traits::Flags & Eigen::SparseBit)>::type
Eigen::MatrixBase<Derived>::eval() const [with Derived =
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<double>,
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<double, 2, 2, 0,
2, 2> >]'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/IO.h:180:
instantiated from 'std::ostream& Eigen::operator<<(std::ostream&,
const Eigen::MatrixBase<Derived>&) [with Derived =
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<double>,
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<double, 2, 2, 0,
2, 2> >]'
xdfk.cpp:5: instantiated from here
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Assign.h:403:
error: template argument for 'template<bool condition, class message>
struct Eigen::ei_static_assert' uses local type
'Eigen::MatrixBase<Derived>::lazyAssign(const
Eigen::MatrixBase<OtherDerived>&) [with OtherDerived =
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Derived = Eigen::Matrix<double,
4, 4, 0, 4, 4>]::ERROR_you_mixed_matrices_of_different_sizes'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Assign.h:403:
error: trying to instantiate 'template<bool condition, class
message> struct Eigen::ei_static_assert'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Assign.h: In
member function 'Derived& Eigen::MatrixBase<Derived>::lazyAssign(const
Eigen::MatrixBase<OtherDerived>&) [with OtherDerived =
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<double>,
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<double, 2, 2, 0,
2, 2> >, Derived = Eigen::Matrix<double, 4, 4, 0, 4, 4>]':
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Assign.h:420:
instantiated from 'static Derived& Eigen::ei_assign_selector<Derived,
OtherDerived, false, false>::run(Derived&, const OtherDerived&) [with
Derived = Eigen::Matrix<double, 4, 4, 0, 4, 4>, OtherDerived =
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<double>,
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<double, 2, 2, 0,
2, 2> >]'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Matrix.h:417:
instantiated from 'Eigen::Matrix<_Scalar, _Rows, _Cols, _StorageOrder,
_MaxRows, _MaxCols>::Matrix(const Eigen::MatrixBase<OtherDerived>&)
[with OtherDerived =
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<double>,
Eigen::Matrix<double, 4,4, 0, 4, 4>, Eigen::Matrix<double, 2, 2, 0, 2,
2> >, _Scalar = double, int _Rows = 4, int _Cols = 4, int
_StorageOrder = 0, int _MaxRows = 4, int _MaxCols = 4]'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/MatrixBase.h:487:
instantiated from 'const typename Eigen::ei_eval<T,
(Eigen::ei_traits::Flags & Eigen::SparseBit)>::type
Eigen::MatrixBase<Derived>::eval() const [with Derived =
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<double>,
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<double, 2, 2, 0,
2, 2> >]'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/IO.h:180:
instantiated from 'std::ostream& Eigen::operator<<(std::ostream&,
const Eigen::MatrixBase<Derived>&) [with Derived =
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<double>,
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<double, 2, 2, 0,
2,2> >]'
xdfk.cpp:5: instantiated from here
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Assign.h:403:
error: template argument for 'template<bool condition, class message>
struct Eigen::ei_static_assert' uses local type
'Eigen::MatrixBase<Derived>::lazyAssign(const
Eigen::MatrixBase<OtherDerived>&) [with OtherDerived =
Eigen::CwiseBinaryOp<Eigen::ei_scalar_sum_op<double>,
Eigen::Matrix<double, 4, 4, 0, 4, 4>, Eigen::Matrix<double, 2, 2, 0,
2, 2> >, Derived = Eigen::Matrix<double, 4, 4, 0, 4,
4>]::ERROR_you_mixed_matrices_of_different_sizes'
cuisine/trunk/kdesupport/eigen2-patch2/Eigen/src/Core/Assign.h:403:
error: trying to instantiate 'template<bool condition, class
message> struct Eigen::ei_static_assert'
=== END GCC OUTPUT =================================
Cheers,
Benoit
2008/12/18 Kenneth Riddile <kfriddile@xxxxxxxxx>:
> When used under MSVC on warning level 4, EIGEN_STATIC_ASSERT currently issues a "conditional expression is constant" warning every time it's used, and these can really add up. I've attached two patches that both solve this problem in different ways:
>
> StaticAssert_h_1.patch simply replaces the if statement inside the EIGEN_STATIC_ASSERT macro with a scope-block, and is the simpler of the two fixes.
>
> StaticAssert_h_2.patch is a more fundamental change to EIGEN_STATIC_ASSERT. It's advantage is that you don't have to update the enum containing the error messages each time you add a new message. You can simply pass in any textual message that is a valid C++ identifier (all of the existing ones are). The disadvantage to this method over the current implementation is that the compiler output is slightly less "pretty", but it's still obvious that a compile-time assert has failed and the error message should be prominently displayed by any good compiler.
>
> -Kenny Riddile
>
>
> --- On Wed, 12/17/08, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
>
>> From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
>> Subject: Re: [eigen] New Eigen users forum!
>> To: eigen@xxxxxxxxxxxxxxxxxxx
>> Date: Wednesday, December 17, 2008, 4:06 PM
>> And that being said, as long as it keeps reasonable (like it
>> is
>> currently), I don't mind a certain amount of user
>> questions on the
>> mailing list. So if you prefer asking questions on the
>> list, by me
>> it's ok.
>>
>> Cheers,
>> Benoit
>>
>> 2008/12/17 Keir Mierle <mierle@xxxxxxxxx>:
>> > Is having a separate forum really a good idea? It
>> seems the eigen community
>> > is pretty small. Wouldn't it be better to
>> encourage traffic on this list
>> > instead of balkanizing discussion?
>> >
>> > Keir
>> >
>> > On Wed, Dec 17, 2008 at 12:52 PM, Benoit Jacob
>> <jacob.benoit.1@xxxxxxxxx>
>> > wrote:
>> >>
>> >> Hi List,
>> >>
>> >> We just opened a users forum here:
>> >> http://forum.kde.org/eigen-f-74.html
>> >>
>> >> I'm trying to get people to use it for getting
>> support with using
>> >> Eigen. Ideally we'd have a community of users
>> able to help each
>> >> other... Until that's the case at least I am
>> reading the forum and
>> >> will answer questions; that's far less
>> time-consuming for me than
>> >> IRC (i'm easily distracted away from work).
>> >>
>> >> Of course IRC and this mailing list continue as
>> usual! The mailing
>> >> list is perfect for discussing eigen development,
>> asking a licensing
>> >> question, reporting a bug, submitting a patch; IRC
>> is great for a
>> >> friendly chat or a very interactive technical
>> discussion, but we can't
>> >> always be online.
>> >>
>> >> Cheers,
>> >> Benoit
>> >>
>> >> ---
>> >>
>> >
>> >
>>
>> ---
---