From 4a4a72951fc6175e7e5ee3bcdc96a2c8b7160e68 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 11 Feb 2017 10:28:44 +0100 Subject: [PATCH 1/9] Fix previous commits: disbale only problematic indexed view methods for old compilers instead of disabling everything. Tested with gcc 4.7 (c++03) and gcc 4.8 (c++03 & c++11) --- Eigen/src/plugins/IndexedViewMethods.h | 10 ++++++++-- test/indexed_view.cpp | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Eigen/src/plugins/IndexedViewMethods.h b/Eigen/src/plugins/IndexedViewMethods.h index 81e463623..22c1666c5 100644 --- a/Eigen/src/plugins/IndexedViewMethods.h +++ b/Eigen/src/plugins/IndexedViewMethods.h @@ -7,7 +7,6 @@ // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -#if EIGEN_HAS_INDEXED_VIEW #if !defined(EIGEN_PARSED_BY_DOXYGEN) // This file is automatically included twice to generate const and non-const versions @@ -113,6 +112,8 @@ operator()(const RowIndices& rowIndices, const ColIndices& colIndices) EIGEN_IND return Base::operator()(internal::eval_expr_given_size(rowIndices,rows()),internal::eval_expr_given_size(colIndices,cols())); } +#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE + // The folowing three overloads are needed to handle raw Index[N] arrays. template @@ -139,6 +140,8 @@ operator()(const RowIndicesT (&rowIndices)[RowIndicesN], const ColIndicesT (&col (derived(), rowIndices, colIndices); } +#endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE + // Overloads for 1D vectors/arrays template @@ -182,6 +185,8 @@ operator()(const IndexType& id) EIGEN_INDEXED_VIEW_METHOD_CONST return Base::operator()(internal::eval_expr_given_size(id,size())); } +#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE + template typename internal::enable_if >::type @@ -202,6 +207,8 @@ operator()(const IndicesT (&indices)[IndicesN]) EIGEN_INDEXED_VIEW_METHOD_CONST (derived(), indices, IvcIndex(0)); } +#endif // EIGEN_HAS_STATIC_ARRAY_TEMPLATE + #undef EIGEN_INDEXED_VIEW_METHOD_CONST #undef EIGEN_INDEXED_VIEW_METHOD_TYPE @@ -258,4 +265,3 @@ IndexedView_or_VectorBlock operator()(const Indices& indices); #endif // EIGEN_PARSED_BY_DOXYGEN -#endif // EIGEN_HAS_INDEXED_VIEW diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 4cbc00639..7245cf378 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -79,7 +79,6 @@ is_same_seq_type(const T1& a, const T2& b) void check_indexed_view() { -#if EIGEN_HAS_INDEXED_VIEW using Eigen::placeholders::all; using Eigen::placeholders::last; using Eigen::placeholders::end; @@ -298,6 +297,7 @@ void check_indexed_view() VERIFY_IS_APPROX( (A(std::array{{1,3,5}}, std::array{{9,6,3,0}})), A(seqN(1,3,2), seqN(9,4,-3)) ); +#if EIGEN_HAS_STATIC_ARRAY_TEMPLATE VERIFY_IS_APPROX( A({3, 1, 6, 5}, all), A(std::array{{3, 1, 6, 5}}, all) ); VERIFY_IS_APPROX( A(all,{3, 1, 6, 5}), A(all,std::array{{3, 1, 6, 5}}) ); VERIFY_IS_APPROX( A({1,3,5},{3, 1, 6, 5}), A(std::array{{1,3,5}},std::array{{3, 1, 6, 5}}) ); @@ -310,6 +310,7 @@ void check_indexed_view() VERIFY_IS_APPROX( b({3, 1, 6, 5}), b(std::array{{3, 1, 6, 5}}) ); VERIFY_IS_EQUAL( b({1,3,5}).SizeAtCompileTime, 3 ); +#endif #endif @@ -365,7 +366,6 @@ void check_indexed_view() VERIFY( is_same_eq( cA.middleRows<3>(1), cA.middleRows(1,fix<3>)) ); } -#endif // EIGEN_HAS_INDEXED_VIEW } void test_indexed_view() From 6486d4fc959a91743f9330e460c13ee4b2e10723 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 11 Feb 2017 10:29:10 +0100 Subject: [PATCH 2/9] Worakound gcc 4.7 issue in c++11. --- Eigen/src/Core/ArithmeticSequence.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/ArithmeticSequence.h b/Eigen/src/Core/ArithmeticSequence.h index 99b954432..ada1571f1 100644 --- a/Eigen/src/Core/ArithmeticSequence.h +++ b/Eigen/src/Core/ArithmeticSequence.h @@ -14,7 +14,7 @@ namespace Eigen { namespace internal { -#if !EIGEN_HAS_CXX11 +#if (!EIGEN_HAS_CXX11) || !((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48) template struct aseq_negate {}; template<> struct aseq_negate { @@ -138,7 +138,7 @@ protected: public: -#if EIGEN_HAS_CXX11 +#if EIGEN_HAS_CXX11 && ((!EIGEN_COMP_GNUC) || EIGEN_COMP_GNUC>=48) auto reverse() const -> decltype(Eigen::seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr)) { return seqN(m_first+(m_size+fix<-1>())*m_incr,m_size,-m_incr); } From e43016367af7b2a4b27c9a1633eee52d6c00dc76 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 11 Feb 2017 10:34:18 +0100 Subject: [PATCH 3/9] Forgot to include a file in previous commit --- Eigen/src/Core/util/Macros.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 0e2863306..12531e342 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -349,10 +349,12 @@ # define __has_feature(x) 0 #endif +// Some old compilers do not support template specializations like: +// template void foo(const T x[N]); #if !( EIGEN_COMP_CLANG && ((EIGEN_COMP_CLANG<309) || defined(__apple_build_version__)) || EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<49) -#define EIGEN_HAS_INDEXED_VIEW 1 +#define EIGEN_HAS_STATIC_ARRAY_TEMPLATE 1 #else -#define EIGEN_HAS_INDEXED_VIEW 0 +#define EIGEN_HAS_STATIC_ARRAY_TEMPLATE 0 #endif // Upperbound on the C++ version to use. From c16ee72b2093ae635b1f07ffd95626c3a86dbbfe Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 11 Feb 2017 10:35:01 +0100 Subject: [PATCH 4/9] bug #1392: fix #include with mpl2-only --- Eigen/Sparse | 2 ++ test/mpl2only.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Eigen/Sparse b/Eigen/Sparse index a2ef7a665..136e681a1 100644 --- a/Eigen/Sparse +++ b/Eigen/Sparse @@ -25,7 +25,9 @@ #include "SparseCore" #include "OrderingMethods" +#ifndef EIGEN_MPL2_ONLY #include "SparseCholesky" +#endif #include "SparseLU" #include "SparseQR" #include "IterativeLinearSolvers" diff --git a/test/mpl2only.cpp b/test/mpl2only.cpp index 5ef0d2b2e..7d04d6bba 100644 --- a/test/mpl2only.cpp +++ b/test/mpl2only.cpp @@ -12,7 +12,9 @@ #include #include #include +#include #include +#include int main() { From b3750990d551bc55949c0312a68233e99fc7961a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 11 Feb 2017 23:24:06 +0100 Subject: [PATCH 5/9] Workaround some gcc 4.7 warnings --- Eigen/src/Core/IndexedView.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Eigen/src/Core/IndexedView.h b/Eigen/src/Core/IndexedView.h index 63878428e..8c57a277c 100644 --- a/Eigen/src/Core/IndexedView.h +++ b/Eigen/src/Core/IndexedView.h @@ -19,8 +19,8 @@ struct traits > : traits { enum { - RowsAtCompileTime = array_size::value, - ColsAtCompileTime = array_size::value, + RowsAtCompileTime = int(array_size::value), + ColsAtCompileTime = int(array_size::value), MaxRowsAtCompileTime = RowsAtCompileTime != Dynamic ? int(RowsAtCompileTime) : int(traits::MaxRowsAtCompileTime), MaxColsAtCompileTime = ColsAtCompileTime != Dynamic ? int(ColsAtCompileTime) : int(traits::MaxColsAtCompileTime), @@ -29,8 +29,8 @@ struct traits > : (MaxColsAtCompileTime==1&&MaxRowsAtCompileTime!=1) ? 0 : XprTypeIsRowMajor, - RowIncr = get_compile_time_incr::value, - ColIncr = get_compile_time_incr::value, + RowIncr = int(get_compile_time_incr::value), + ColIncr = int(get_compile_time_incr::value), InnerIncr = IsRowMajor ? ColIncr : RowIncr, OuterIncr = IsRowMajor ? RowIncr : ColIncr, @@ -51,7 +51,7 @@ struct traits > // FIXME we deal with compile-time strides if and only if we have DirectAccessBit flag, // but this is too strict regarding negative strides... - DirectAccessMask = (InnerIncr!=UndefinedIncr && OuterIncr!=UndefinedIncr && InnerIncr>=0 && OuterIncr>=0) ? DirectAccessBit : 0, + DirectAccessMask = (int(InnerIncr)!=UndefinedIncr && int(OuterIncr)!=UndefinedIncr && InnerIncr>=0 && OuterIncr>=0) ? DirectAccessBit : 0, FlagsRowMajorBit = IsRowMajor ? RowMajorBit : 0, FlagsLvalueBit = is_lvalue::value ? LvalueBit : 0, Flags = (traits::Flags & (HereditaryBits | DirectAccessMask)) | FlagsLvalueBit | FlagsRowMajorBit From e7ebe52bfb4b0653e69217d9beac75ca7949e165 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 13 Feb 2017 09:46:20 +0100 Subject: [PATCH 6/9] bug #1391: include IO.h before DenseBase to enable its usage in DenseBase plugins. --- Eigen/Core | 2 +- Eigen/src/Core/DenseBase.h | 12 +++++++++++- Eigen/src/Core/IO.h | 14 -------------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Eigen/Core b/Eigen/Core index 9f1c63826..d18835613 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -432,6 +432,7 @@ using std::ptrdiff_t; #include "src/Core/util/IndexedViewHelper.h" #include "src/Core/ArithmeticSequence.h" +#include "src/Core/IO.h" #include "src/Core/DenseCoeffsBase.h" #include "src/Core/DenseBase.h" #include "src/Core/MatrixBase.h" @@ -480,7 +481,6 @@ using std::ptrdiff_t; #include "src/Core/Redux.h" #include "src/Core/Visitor.h" #include "src/Core/Fuzzy.h" -#include "src/Core/IO.h" #include "src/Core/Swap.h" #include "src/Core/CommaInitializer.h" #include "src/Core/GeneralProduct.h" diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index a8229cf03..fc807577b 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -463,7 +463,17 @@ template class DenseBase EIGEN_DEVICE_FUNC void visit(Visitor& func) const; - inline const WithFormat format(const IOFormat& fmt) const; + /** \returns a WithFormat proxy object allowing to print a matrix the with given + * format \a fmt. + * + * See class IOFormat for some examples. + * + * \sa class IOFormat, class WithFormat + */ + inline const WithFormat format(const IOFormat& fmt) const + { + return WithFormat(derived(), fmt); + } /** \returns the unique coefficient of a 1x1 expression */ EIGEN_DEVICE_FUNC diff --git a/Eigen/src/Core/IO.h b/Eigen/src/Core/IO.h index 644228c3f..da7fd6cce 100644 --- a/Eigen/src/Core/IO.h +++ b/Eigen/src/Core/IO.h @@ -109,20 +109,6 @@ class WithFormat IOFormat m_format; }; -/** \returns a WithFormat proxy object allowing to print a matrix the with given - * format \a fmt. - * - * See class IOFormat for some examples. - * - * \sa class IOFormat, class WithFormat - */ -template -inline const WithFormat -DenseBase::format(const IOFormat& fmt) const -{ - return WithFormat(derived(), fmt); -} - namespace internal { // NOTE: This helper is kept for backward compatibility with previous code specializing From 3453b00a1ef895a4b2eb5f349ab0bf2d50ca0535 Mon Sep 17 00:00:00 2001 From: Jonathan Hseu Date: Sat, 11 Feb 2017 21:45:32 -0800 Subject: [PATCH 7/9] Fix vector indexing with uint64_t --- Eigen/src/Core/util/Meta.h | 24 +++++++++++++----------- test/basicstuff.cpp | 13 +++++++++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index ee0531b32..11c089020 100755 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -97,17 +97,19 @@ template<> struct is_arithmetic { enum { value = true }; }; template<> struct is_arithmetic { enum { value = true }; }; template<> struct is_arithmetic { enum { value = true }; }; -template struct is_integral { enum { value = false }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; +template struct is_integral { enum { value = false }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; +template<> struct is_integral { enum { value = true }; }; template struct add_const { typedef const T type; }; template struct add_const { typedef T& type; }; diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index 99d91f9da..52b89c0d6 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -49,6 +49,19 @@ template void basicStuff(const MatrixType& m) v1[r] = x; VERIFY_IS_APPROX(x, v1[r]); + // test fetching with various index types. + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + x = v1(static_cast(r)); + VERIFY_IS_APPROX( v1, v1); VERIFY_IS_NOT_APPROX( v1, 2*v1); VERIFY_IS_MUCH_SMALLER_THAN( vzero, v1); From 707343094637b112d49089372a0a8e0a06b0b34c Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 13 Feb 2017 17:14:04 +0100 Subject: [PATCH 8/9] Fix overflow and make use of long long in c++11 only. --- test/basicstuff.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index 52b89c0d6..c346ce6cb 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -50,17 +50,20 @@ template void basicStuff(const MatrixType& m) VERIFY_IS_APPROX(x, v1[r]); // test fetching with various index types. - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); - x = v1(static_cast(r)); + Index r1 = internal::random(0, numext::mini(Index(127),rows-1)); + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); +#if EIGEN_HAS_CXX11 + x = v1(static_cast(r1)); + x = v1(static_cast(r1)); +#endif VERIFY_IS_APPROX( v1, v1); VERIFY_IS_NOT_APPROX( v1, 2*v1); From 5937c4ae32feec178d56282694f06ed16cfe7352 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 13 Feb 2017 17:14:26 +0100 Subject: [PATCH 9/9] Fall back is_integral to std::is_integral in c++11 --- Eigen/src/Core/util/Meta.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/util/Meta.h b/Eigen/src/Core/util/Meta.h index 11c089020..90eda6e70 100755 --- a/Eigen/src/Core/util/Meta.h +++ b/Eigen/src/Core/util/Meta.h @@ -97,6 +97,9 @@ template<> struct is_arithmetic { enum { value = true }; }; template<> struct is_arithmetic { enum { value = true }; }; template<> struct is_arithmetic { enum { value = true }; }; +#if EIGEN_HAS_CXX11 +using std::is_integral; +#else template struct is_integral { enum { value = false }; }; template<> struct is_integral { enum { value = true }; }; template<> struct is_integral { enum { value = true }; }; @@ -108,8 +111,8 @@ template<> struct is_integral { enum { value = true }; } template<> struct is_integral { enum { value = true }; }; template<> struct is_integral { enum { value = true }; }; template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; -template<> struct is_integral { enum { value = true }; }; +#endif + template struct add_const { typedef const T type; }; template struct add_const { typedef T& type; };