From 53026d29d41e81065b28631445e8eb5c4044c187 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 31 Jan 2017 14:22:42 +0100 Subject: [PATCH 01/13] bug #478: fix regression in the eigen decomposition of zero matrices. --- Eigen/src/Eigenvalues/ComplexEigenSolver.h | 6 ++++-- Eigen/src/Eigenvalues/RealSchur.h | 12 ++++++++++++ test/eigensolver_complex.cpp | 9 +++++++++ test/eigensolver_generic.cpp | 9 +++++++++ test/eigensolver_selfadjoint.cpp | 9 +++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Eigenvalues/ComplexEigenSolver.h b/Eigen/src/Eigenvalues/ComplexEigenSolver.h index ec3b1633e..dc5fae06a 100644 --- a/Eigen/src/Eigenvalues/ComplexEigenSolver.h +++ b/Eigen/src/Eigenvalues/ComplexEigenSolver.h @@ -250,7 +250,7 @@ template class ComplexEigenSolver EigenvectorType m_matX; private: - void doComputeEigenvectors(const RealScalar& matrixnorm); + void doComputeEigenvectors(RealScalar matrixnorm); void sortEigenvalues(bool computeEigenvectors); }; @@ -284,10 +284,12 @@ ComplexEigenSolver::compute(const EigenBase& matrix, bool template -void ComplexEigenSolver::doComputeEigenvectors(const RealScalar& matrixnorm) +void ComplexEigenSolver::doComputeEigenvectors(RealScalar matrixnorm) { const Index n = m_eivalues.size(); + matrixnorm = numext::maxi(matrixnorm,(std::numeric_limits::min)()); + // Compute X such that T = X D X^(-1), where D is the diagonal of T. // The matrix X is unit triangular. m_matX = EigenvectorType::Zero(n, n); diff --git a/Eigen/src/Eigenvalues/RealSchur.h b/Eigen/src/Eigenvalues/RealSchur.h index d6a339f07..f5c86041d 100644 --- a/Eigen/src/Eigenvalues/RealSchur.h +++ b/Eigen/src/Eigenvalues/RealSchur.h @@ -248,12 +248,24 @@ template template RealSchur& RealSchur::compute(const EigenBase& matrix, bool computeU) { + const Scalar considerAsZero = (std::numeric_limits::min)(); + eigen_assert(matrix.cols() == matrix.rows()); Index maxIters = m_maxIters; if (maxIters == -1) maxIters = m_maxIterationsPerRow * matrix.rows(); Scalar scale = matrix.derived().cwiseAbs().maxCoeff(); + if(scale void eigensolver(const MatrixType& m) ComplexEigenSolver eig(a.adjoint() * a); eig.compute(a.adjoint() * a); } + + // regression test for bug 478 + { + a.setZero(); + ComplexEigenSolver ei3(a); + VERIFY_IS_EQUAL(ei3.info(), Success); + VERIFY_IS_MUCH_SMALLER_THAN(ei3.eigenvalues().norm(),RealScalar(1)); + VERIFY((ei3.eigenvectors().transpose()*ei3.eigenvectors().transpose()).eval().isIdentity()); + } } template void eigensolver_verify_assert(const MatrixType& m) diff --git a/test/eigensolver_generic.cpp b/test/eigensolver_generic.cpp index e18fbf687..d0e644d4b 100644 --- a/test/eigensolver_generic.cpp +++ b/test/eigensolver_generic.cpp @@ -76,6 +76,15 @@ template void eigensolver(const MatrixType& m) EigenSolver eig(a.adjoint() * a); eig.compute(a.adjoint() * a); } + + // regression test for bug 478 + { + a.setZero(); + EigenSolver ei3(a); + VERIFY_IS_EQUAL(ei3.info(), Success); + VERIFY_IS_MUCH_SMALLER_THAN(ei3.eigenvalues().norm(),RealScalar(1)); + VERIFY((ei3.eigenvectors().transpose()*ei3.eigenvectors().transpose()).eval().isIdentity()); + } } template void eigensolver_verify_assert(const MatrixType& m) diff --git a/test/eigensolver_selfadjoint.cpp b/test/eigensolver_selfadjoint.cpp index 4ed126116..39ad4130e 100644 --- a/test/eigensolver_selfadjoint.cpp +++ b/test/eigensolver_selfadjoint.cpp @@ -180,6 +180,15 @@ template void selfadjointeigensolver(const MatrixType& m) SelfAdjointEigenSolver eig(a.adjoint() * a); eig.compute(a.adjoint() * a); } + + // regression test for bug 478 + { + a.setZero(); + SelfAdjointEigenSolver ei3(a); + VERIFY_IS_EQUAL(ei3.info(), Success); + VERIFY_IS_MUCH_SMALLER_THAN(ei3.eigenvalues().norm(),RealScalar(1)); + VERIFY((ei3.eigenvectors().transpose()*ei3.eigenvectors().transpose()).eval().isIdentity()); + } } template From 645a8e32a556f2dff312c7c31d3622709d4960ad Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 31 Jan 2017 16:22:54 +0100 Subject: [PATCH 02/13] Fix compilation of JacobiSVD for vectors type --- Eigen/src/SVD/JacobiSVD.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index e0cfb6283..1337ae987 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -200,10 +200,12 @@ public: ColsAtCompileTime = MatrixType::ColsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, - Options = MatrixType::Options + TrOptions = RowsAtCompileTime==1 ? (MatrixType::Options & ~(RowMajor)) + : ColsAtCompileTime==1 ? (MatrixType::Options | RowMajor) + : MatrixType::Options }; - typedef Matrix + typedef Matrix TransposeTypeWithSameStorageOrder; void allocate(const JacobiSVD& svd) From 0eceea4efd47bb2a1bfb72903fbd14a5d32c5ced Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 1 Feb 2017 23:36:40 +0100 Subject: [PATCH 03/13] Define EIGEN_COMP_GNUC to reflect version number: 47, 48, 49, 50, 60, ... --- Eigen/src/Core/util/Macros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index ab0550895..5db9e4fe5 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -23,7 +23,7 @@ /// \internal EIGEN_COMP_GNUC set to 1 for all compilers compatible with GCC #ifdef __GNUC__ - #define EIGEN_COMP_GNUC 1 + #define EIGEN_COMP_GNUC (__GNUC__*10+__GNUC_MINOR__) #else #define EIGEN_COMP_GNUC 0 #endif From 84090027c49638cdc0025ef1baba1855bcbcd858 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 1 Feb 2017 23:37:44 +0100 Subject: [PATCH 04/13] Disable a part of the unit test for gcc 4.8 --- test/indexed_view.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 909d2351d..86342dc0a 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -297,7 +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_COMP_CLANG) || (EIGEN_COMP_CLANG>=308 && !defined(__apple_build_version__)) +#if !( EIGEN_COMP_CLANG && ((EIGEN_COMP_CLANG<309) || defined(__apple_build_version__)) || EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<49) 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}}) ); From fcd257039b7fba59d3c968f62c7e7d0f37cbaf3b Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 1 Feb 2017 15:30:49 -0800 Subject: [PATCH 05/13] Replaced EIGEN_DEVICE_FUNC template with template EIGEN_DEVICE_FUNC to make the code compile with nvcc8. --- Eigen/src/plugins/BlockMethods.h | 46 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Eigen/src/plugins/BlockMethods.h b/Eigen/src/plugins/BlockMethods.h index 2d5a4e507..c116f0e0f 100644 --- a/Eigen/src/plugins/BlockMethods.h +++ b/Eigen/src/plugins/BlockMethods.h @@ -78,8 +78,8 @@ EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL /// /// \sa class Block, fix, fix(int) /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename FixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -92,8 +92,8 @@ block(Index startRow, Index startCol, NRowsType blockRows, NColsType blockCols) } /// This is the const version of block(Index,Index,NRowsType,NColsType) -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstFixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -124,8 +124,8 @@ EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename FixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -138,8 +138,8 @@ topRightCorner(NRowsType cRows, NColsType cCols) } /// This is the const version of topRightCorner(NRowsType, NColsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstFixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -229,8 +229,8 @@ EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename FixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -243,8 +243,8 @@ topLeftCorner(NRowsType cRows, NColsType cCols) } /// This is the const version of topLeftCorner(Index, Index). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstFixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -333,8 +333,8 @@ EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename FixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -348,8 +348,8 @@ bottomRightCorner(NRowsType cRows, NColsType cCols) } /// This is the const version of bottomRightCorner(NRowsType, NColsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstFixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -454,8 +454,8 @@ bottomLeftCorner(NRowsType cRows, NColsType cCols) } /// This is the const version of bottomLeftCorner(NRowsType, NColsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename ConstFixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -558,8 +558,8 @@ topRows(NRowsType n) } /// This is the const version of topRows(NRowsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstNRowsBlockXpr::value>::Type #else @@ -619,8 +619,8 @@ EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename NRowsBlockXpr::value>::Type #else @@ -633,8 +633,8 @@ bottomRows(NRowsType n) } /// This is the const version of bottomRows(NRowsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstNRowsBlockXpr::value>::Type #else @@ -709,8 +709,8 @@ middleRows(Index startRow, NRowsType n) } /// This is the const version of middleRows(Index,NRowsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstNRowsBlockXpr::value>::Type #else @@ -771,8 +771,8 @@ EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename NColsBlockXpr::value>::Type #else @@ -785,8 +785,8 @@ leftCols(NColsType n) } /// This is the const version of leftCols(NColsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstNColsBlockXpr::value>::Type #else @@ -846,8 +846,8 @@ EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename NColsBlockXpr::value>::Type #else @@ -922,8 +922,8 @@ EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(column-major) /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename NColsBlockXpr::value>::Type #else @@ -936,8 +936,8 @@ middleCols(Index startCol, NColsType numCols) } /// This is the const version of middleCols(Index,NColsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstNColsBlockXpr::value>::Type #else @@ -1130,8 +1130,8 @@ inline ConstRowXpr row(Index i) const /// /// \sa block(Index,Index,NRowsType,NColsType), fix, fix(int), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename FixedSegmentReturnType::value>::Type #else @@ -1146,8 +1146,8 @@ segment(Index start, NType n) /// This is the const version of segment(Index,NType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstFixedSegmentReturnType::value>::Type #else @@ -1180,8 +1180,8 @@ segment(Index start, NType n) const /// /// \sa class Block, block(Index,Index) /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename FixedSegmentReturnType::value>::Type #else @@ -1195,8 +1195,8 @@ head(NType n) } /// This is the const version of head(NType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstFixedSegmentReturnType::value>::Type #else @@ -1244,8 +1244,8 @@ tail(NType n) } /// This is the const version of tail(Index). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstFixedSegmentReturnType::value>::Type #else From 2db75c07a608ab07fbbdd6a3215e39c7e7943445 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 1 Feb 2017 15:41:29 -0800 Subject: [PATCH 06/13] fixed the ordering of the template and EIGEN_DEVICE_FUNC keywords in a few more places to get more of the Eigen codebase to compile with nvcc again. --- Eigen/src/plugins/BlockMethods.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Eigen/src/plugins/BlockMethods.h b/Eigen/src/plugins/BlockMethods.h index c116f0e0f..5caf14469 100644 --- a/Eigen/src/plugins/BlockMethods.h +++ b/Eigen/src/plugins/BlockMethods.h @@ -439,8 +439,8 @@ EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename FixedBlockXpr::value,internal::get_fixed_value::value>::Type #else @@ -544,8 +544,8 @@ EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename NRowsBlockXpr::value>::Type #else @@ -695,8 +695,8 @@ EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(row-major) /// /// \sa block(Index,Index,NRowsType,NColsType), class Block /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename NRowsBlockXpr::value>::Type #else @@ -860,8 +860,8 @@ rightCols(NColsType n) } /// This is the const version of rightCols(NColsType). -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline const typename ConstNColsBlockXpr::value>::Type #else @@ -1229,8 +1229,8 @@ head(NType n) const /// /// \sa class Block, block(Index,Index) /// -EIGEN_DEVICE_FUNC template +EIGEN_DEVICE_FUNC #ifndef EIGEN_PARSED_BY_DOXYGEN inline typename FixedSegmentReturnType::value>::Type #else From 442e9cbb307ece9225a061a5661909a47737585e Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Wed, 1 Feb 2017 15:50:58 -0800 Subject: [PATCH 07/13] Silenced several compilation warnings --- unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h b/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h index 442c14fac..d32c20b5e 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h @@ -64,9 +64,9 @@ void pack_simple(Scalar * dst, const Scalar * src, Index cols, Index rows, Index template struct libxsmm_wrapper { libxsmm_wrapper() {} - libxsmm_wrapper(int flags, int m, int n, int k, int lda, int ldb, int ldc, float alpha, float beta, int prefetch) {} - void operator()(const LhsScalar* a, const RhsScalar* b, Scalar* c) {} - void operator()(const LhsScalar* a, const RhsScalar* b, Scalar* c, const LhsScalar* ap, const RhsScalar* bp, const Scalar* cp) {} + libxsmm_wrapper(int, int, int, int, int, int, int, float, float, int) {} + void operator()(const LhsScalar*, const RhsScalar*, Scalar*) {} + void operator()(const LhsScalar*, const RhsScalar*, Scalar*, const LhsScalar*, const RhsScalar*, const Scalar*) {} }; template<> @@ -682,7 +682,9 @@ protected: } m_can_use_xsmm = true; - #endif +#else + EIGEN_UNUSED_VARIABLE(eval_op_indices); +#endif } #if defined(EIGEN_VECTORIZE_AVX) && defined(EIGEN_USE_LIBXSMM) From 4254b3eda34346a28518f6b2b6a8ff8c8368d3d3 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 3 Feb 2017 15:22:35 +0100 Subject: [PATCH 08/13] bug #1389: MSVC's std containers do not properly align in 64 bits mode if the requested alignment is larger than 16 bytes (e.g., with AVX) --- Eigen/StdDeque | 2 +- Eigen/StdList | 2 +- Eigen/StdVector | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Eigen/StdDeque b/Eigen/StdDeque index be3a7f82b..bc68397be 100644 --- a/Eigen/StdDeque +++ b/Eigen/StdDeque @@ -14,7 +14,7 @@ #include "Core" #include -#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 /* MSVC auto aligns in 64 bit builds */ +#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ #define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...) diff --git a/Eigen/StdList b/Eigen/StdList index 07ba1297b..4c6262c08 100644 --- a/Eigen/StdList +++ b/Eigen/StdList @@ -13,7 +13,7 @@ #include "Core" #include -#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 /* MSVC auto aligns in 64 bit builds */ +#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ #define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...) diff --git a/Eigen/StdVector b/Eigen/StdVector index fdfc37766..0c4697ad5 100644 --- a/Eigen/StdVector +++ b/Eigen/StdVector @@ -14,7 +14,7 @@ #include "Core" #include -#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 /* MSVC auto aligns in 64 bit builds */ +#if EIGEN_COMP_MSVC && EIGEN_OS_WIN64 && (EIGEN_MAX_STATIC_ALIGN_BYTES<=16) /* MSVC auto aligns up to 16 bytes in 64 bit builds */ #define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...) From fc8fd5fd24d3dce28b7fafa538b67e61dd667f6e Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 7 Feb 2017 17:19:59 +0100 Subject: [PATCH 09/13] Improve multi-threading heuristic for matrix products with a small number of columns. --- Eigen/src/Core/products/Parallelizer.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Eigen/src/Core/products/Parallelizer.h b/Eigen/src/Core/products/Parallelizer.h index 3477d7182..c2f084c82 100644 --- a/Eigen/src/Core/products/Parallelizer.h +++ b/Eigen/src/Core/products/Parallelizer.h @@ -104,13 +104,14 @@ void parallelize_gemm(const Functor& func, Index rows, Index cols, Index depth, // - the sizes are large enough // compute the maximal number of threads from the size of the product: - // FIXME this has to be fine tuned + // This first heuristic takes into account that the product kernel is fully optimized when working with nr columns at once. Index size = transpose ? rows : cols; - Index pb_max_threads = std::max(1,size / 32); + Index pb_max_threads = std::max(1,size / Functor::Traits::nr); + // compute the maximal number of threads from the total amount of work: double work = static_cast(rows) * static_cast(cols) * static_cast(depth); - double kMinTaskSize = 50000; // Heuristic. + double kMinTaskSize = 50000; // FIXME improve this heuristic. pb_max_threads = std::max(1, std::min(pb_max_threads, work / kMinTaskSize)); // compute the number of threads we are going to use From dd58462e63b0738842da5e509558ea12cabecee2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Wed, 8 Feb 2017 23:50:38 +0100 Subject: [PATCH 10/13] fixed inlining issue with clang-cl on visual studio (grafted from 7962ac1a5855e8b7a60d5d90e61365b71f5501a5 ) --- Eigen/src/Core/AssignEvaluator.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/AssignEvaluator.h b/Eigen/src/Core/AssignEvaluator.h index 489935b83..b0ec7b7ca 100644 --- a/Eigen/src/Core/AssignEvaluator.h +++ b/Eigen/src/Core/AssignEvaluator.h @@ -515,7 +515,7 @@ struct dense_assignment_loop template struct dense_assignment_loop { - EIGEN_DEVICE_FUNC static inline void run(Kernel &kernel) + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) { typedef typename Kernel::Scalar Scalar; typedef typename Kernel::PacketType PacketType; @@ -563,7 +563,7 @@ struct dense_assignment_loop template struct dense_assignment_loop { - EIGEN_DEVICE_FUNC static inline void run(Kernel &kernel) + EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE void run(Kernel &kernel) { typedef typename Kernel::DstEvaluatorType::XprType DstXprType; typedef typename Kernel::PacketType PacketType; From 0256c52359281f6685532ba8f1d517fbb91b46c6 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 10 Feb 2017 13:41:52 +0100 Subject: [PATCH 11/13] Include clang in the list of non strict MSVC (just to be sure) --- Eigen/src/Core/util/Macros.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 5db9e4fe5..bc033959c 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -80,8 +80,8 @@ // 2015 14 1900 // "15" 15 1900 -/// \internal EIGEN_COMP_MSVC_STRICT set to 1 if the compiler is really Microsoft Visual C++ and not ,e.g., ICC -#if EIGEN_COMP_MSVC && !(EIGEN_COMP_ICC) +/// \internal EIGEN_COMP_MSVC_STRICT set to 1 if the compiler is really Microsoft Visual C++ and not ,e.g., ICC or clang-cl +#if EIGEN_COMP_MSVC && !(EIGEN_COMP_ICC || EIGEN_COMP_LLVM || EIGEN_COMP_CLANG) #define EIGEN_COMP_MSVC_STRICT _MSC_VER #else #define EIGEN_COMP_MSVC_STRICT 0 From a1ff24f96a1280cd7d7395f739d8f265150879bb Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 10 Feb 2017 13:59:32 +0100 Subject: [PATCH 12/13] Fix prunning in (sparse*sparse).pruned() when the result is nearly dense. --- Eigen/src/SparseCore/AmbiVector.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Eigen/src/SparseCore/AmbiVector.h b/Eigen/src/SparseCore/AmbiVector.h index 1233e164e..8a5cc91f2 100644 --- a/Eigen/src/SparseCore/AmbiVector.h +++ b/Eigen/src/SparseCore/AmbiVector.h @@ -336,7 +336,7 @@ class AmbiVector<_Scalar,_StorageIndex>::Iterator { do { ++m_cachedIndex; - } while (m_cachedIndex::Iterator ListEl* EIGEN_RESTRICT llElements = reinterpret_cast(m_vector.m_buffer); do { m_currentEl = llElements[m_currentEl].next; - } while (m_currentEl>=0 && abs(llElements[m_currentEl].value)=0 && abs(llElements[m_currentEl].value)<=m_epsilon); if (m_currentEl<0) { m_cachedIndex = -1; @@ -363,9 +363,9 @@ class AmbiVector<_Scalar,_StorageIndex>::Iterator protected: const AmbiVector& m_vector; // the target vector - StorageIndex m_currentEl; // the current element in sparse/linked-list mode + StorageIndex m_currentEl; // the current element in sparse/linked-list mode RealScalar m_epsilon; // epsilon used to prune zero coefficients - StorageIndex m_cachedIndex; // current coordinate + StorageIndex m_cachedIndex; // current coordinate Scalar m_cachedValue; // current value bool m_isDense; // mode of the vector }; From 8b3cc54c42d6f2cc7db6f2a56da0e6510782b747 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Fri, 10 Feb 2017 13:08:49 -0800 Subject: [PATCH 13/13] Added a new EIGEN_HAS_INDEXED_VIEW define that set to 0 for older compilers that are known to fail to compile the indexed views (I used the define from the indexed_views.cpp test). Only include the indexed view methods when the compiler supports the code. This makes it possible to use Eigen again in complex code bases such as TensorFlow and older compilers such as gcc 4.8 --- Eigen/src/Core/util/Macros.h | 6 ++++++ Eigen/src/plugins/IndexedViewMethods.h | 5 ++--- test/indexed_view.cpp | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index bc033959c..0e2863306 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -349,6 +349,12 @@ # define __has_feature(x) 0 #endif +#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 +#else +#define EIGEN_HAS_INDEXED_VIEW 0 +#endif + // Upperbound on the C++ version to use. // Expected values are 03, 11, 14, 17, etc. // By default, let's use an arbitrarily large C++ version. diff --git a/Eigen/src/plugins/IndexedViewMethods.h b/Eigen/src/plugins/IndexedViewMethods.h index b2cc2944a..5e28ec71c 100644 --- a/Eigen/src/plugins/IndexedViewMethods.h +++ b/Eigen/src/plugins/IndexedViewMethods.h @@ -7,7 +7,7 @@ // 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/. -#ifndef EIGEN_PARSED_BY_DOXYGEN +#if !defined(EIGEN_PARSED_BY_DOXYGEN) && EIGEN_HAS_INDEXED_VIEW // This file is automatically included twice to generate const and non-const versions @@ -256,5 +256,4 @@ template IndexedView_or_VectorBlock operator()(const Indices& indices); -#endif // EIGEN_PARSED_BY_DOXYGEN - +#endif // EIGEN_PARSED_BY_DOXYGEN && EIGEN_HAS_INDEXED_VIEW diff --git a/test/indexed_view.cpp b/test/indexed_view.cpp index 86342dc0a..4cbc00639 100644 --- a/test/indexed_view.cpp +++ b/test/indexed_view.cpp @@ -79,6 +79,7 @@ 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; @@ -297,7 +298,6 @@ 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_COMP_CLANG && ((EIGEN_COMP_CLANG<309) || defined(__apple_build_version__)) || EIGEN_COMP_GNUC_STRICT && EIGEN_COMP_GNUC<49) 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,7 +310,6 @@ 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 @@ -366,6 +365,7 @@ 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()