diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..13222d60a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +*.sh eol=lf +debug/msvc/*.dat eol=crlf +debug/msvc/*.natvis eol=crlf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 68cd68040..8872ad0b6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,10 @@ # 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/. +default: +# automatically cancels a job when a new pipeline for the same branch is triggered + interruptible: true + stages: - checkformat - build diff --git a/.hgeol b/.hgeol deleted file mode 100644 index 5327df161..000000000 --- a/.hgeol +++ /dev/null @@ -1,11 +0,0 @@ -[patterns] -*.sh = LF -*.MINPACK = CRLF -scripts/*.in = LF -debug/msvc/*.dat = CRLF -debug/msvc/*.natvis = CRLF -unsupported/test/mpreal/*.* = CRLF -** = native - -[repository] -native = LF diff --git a/CHANGELOG.md b/CHANGELOG.md index e9223ec4f..cd0f189de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,49 @@ ## [Unreleased] -## [3.4.0] +## [5.0.0] - 2025-09-30 -Released on August 18, 2021 +Eigen 5.0 provides many new features, performance enhancements, and bugfixes throughout Eigen’s core template expression infrastructure and linear algebra facilities. The full set of changes and related issues are too large to list here, but can be accessed via the release milestone %"5.0". + +This is the last major release to support the C++14 language standard. The master branch and subsequent releases will require support for C++17. + +### Versioning + +This release marks a transition to [Semantic Versioning](https://semver.org/). Previously, Eigen used a WORLD.MAJOR.MINOR scheme. From now on, version numbers will follow the MAJOR.MINOR.PATCH format, indicating breaking changes, new features, and bug fixes, respectively. The WORLD version will remain 3 for this and subsequent releases for posterity. See the table below: +``` +╔═════════╦═════╦═════╗ +║ Release ║ 3.4 ║ 5.0 ║ +╠═════════╬═════╬═════╣ +║ WORLD ║ 3 ║ 3 ║ +║ MAJOR ║ 4 ║ 5 ║ +║ MINOR ║ 0 ║ 0 ║ +║ PATCH ║ - ║ 0 ║ +╚═════════╩═════╩═════╝ +``` + +### Breaking changes + +* Eigen 5.X.X requires C++14. When building with GNU-compatible compilers, set `-std=c++14` or later. As part of this change, some macros such as `EIGEN_HAS_CXX11` have also been removed. +* The CMake build system has been modernized and older properties have been removed - projects relying on CMake may need to update their configurations [!485]. +* All LGPL-licensed code has been removed (i.e. Constrained Conjugate Gradient) [!1197]. These were "unsupported" anyways, and weren't widely used. +* Due to name conflicts with other projects, `Eigen::all` and `Eigen::last` have been moved to `Eigen::placeholders::all` and `Eigen::placeholders::last` [!649]. +* Any direct inclusion of an internal header (i.e. under a `../src/..` path) will result in a compilation error [!631]. +* Runtime SVD options for computing thin/full U/V have been deprecated: use compile-time options instead [!826]. +* Scalar (i.e. non-vectorized) comparisons now return masks with values of `Scalar(1)` rather than having all bits set to avoid undefined behavior [!1862]. +* BLAS return types have been changed for Eigen BLAS to `void` instead of `int` for compatibility with other BLAS implementations [!1497]. +* `Eigen::aligned_allocator` no longer inherits from `std::allocator` due to a change in the standard and the use of `allocate_at_least` [!1795]. +* Euler angles are now returned in a more canonical form, potentially resulting in a change of behavior [!1301, !1314]. +* Eigen's random number generation has changed, resulting in a change of behavior. Please do not rely on specific random numbers from Eigen - these were never guaranteed to be consistent across Eigen versions, nor are they generally consistent across platforms [!1437]. + +## [3.4.1] - 2025-09-30 + +Many bug fixes have been backported from the main branch. + +A list of new issues addressed can be found via the [3.4.1](https://gitlab.com/libeigen/eigen/-/issues?state=all&label_name%5B%5D=3.4.1) label on GitLab. + +Check the [git commit history](https://gitlab.com/libeigen/eigen/-/commits/3.4.1) for the full list of changes. + +## [3.4.0] - 2021-08-18 **Notice:** 3.4.x will be the last major release series of Eigen that will support c++03. @@ -160,9 +200,7 @@ Released on August 18, 2021 See the [announcement](https://www.eigen.tuxfamily.org/index.php?title=3.4) for more details. -## [3.3.9] - -Released on December 4, 2020. +## [3.3.9] - 2020-12-04 Changes since 3.3.8: @@ -175,9 +213,7 @@ Changes since 3.3.8: * #2012: Define coeff-wise binary array operators for base class to fix an issue when using Eigen with C++20 * Commit bfdd4a990: Fix an issue with Intel® MKL PARDISO support. -## [3.3.8] - -Released on October 5, 2020. +## [3.3.8] - 2020-10-05 Changes since 3.3.7: @@ -243,9 +279,7 @@ Changes since 3.3.7: * Commit 6c4d57dc9: Fix a gcc7 warning about bool * bool in abs2 default implementation. * Commit 89a86ed42: Fix a warning in SparseSelfAdjointView about a branch statement always evaluation to false. -## [3.3.8-rc1] - -Released on September 14, 2020. +## [3.3.8-rc1] - 2020-09-14 Changes since 3.3.7: @@ -308,17 +342,13 @@ Changes since 3.3.7: * Commit 89a86ed42: Fix a warning in SparseSelfAdjointView about a branch statement always evaluation to false. * Commit dd6de618: Fix a bug with half-precision floats on GPUs. -## [3.3.7] - -Released on December 11, 2018. +## [3.3.7] - 2018-12-11 Changes since 3.3.6: * #1643: Fix compilation with GCC>=6 and compiler optimization turned off. -## [3.3.6] - -Released on December 10, 2018. +## [3.3.6] - 2018-12-10 Changes since 3.3.5: @@ -340,9 +370,7 @@ Changes since 3.3.5: * Various fixes in the doc. * Various minor warning fixes/workarounds. -## [3.3.5] - -Released on July 23, 2018. +## [3.3.5] - 2018-07-23 Changes since 3.3.4: @@ -436,9 +464,7 @@ Changes since 3.3.4: * Changeset 12c9ece47d14: `SelfAdjointView<...,Mode>` causes a static assert since commit c73a77e47db8 * Changeset 899fd2ef704f: weird compilation issue in `mapped_matrix.cpp` -## [3.3.4] - -Released on June 15, 2017. +## [3.3.4] - 2017-06-15 Changes since 3.3.3: @@ -469,9 +495,7 @@ Changes since 3.3.3: * Add specializations of `std::numeric_limits` for `Eigen::half` and and `AutoDiffScalar` * Fix compilation of streaming nested Array, i.e., `std::cout << Array>` -## [3.3.3] - -Released on February 21, 2017. +## [3.3.3] - 2017-02-21 Changes since 3.3.2: @@ -502,9 +526,7 @@ Changes since 3.3.2: * Fix usage of `size_t` instead of Index in sefl-adjoint `matrix * vector` * #1378: fix doc (`DiagonalIndex` vs `Diagonal`). -## [3.3.2] - -Released on January 18, 2017. +## [3.3.2] - 2017-01-18 Changes since 3.3.1: @@ -535,9 +557,7 @@ Changes since 3.3.1: * Fix some warnings with ICC, Power8, etc. * Fix compilation with MSVC 2017 -## [3.3.1] - -Released on December 06, 2016. +## [3.3.1] - 2016-12-06 Changes since 3.3.0: @@ -558,9 +578,7 @@ Changes since 3.3.0: * Bugs #1346,#1347: make Eigen's installation relocatable. * Fix some harmless compilation warnings. -## [3.3] - -Released on November 10, 2016 +## [3.3] - 2016-11-10 For a comprehensive list of change since the 3.2 series, see this [page](https://www.eigen.tuxfamily.org/index.php?title=3.3). @@ -569,9 +587,7 @@ Main changes since 3.3-rc2: * Fix regression in printing sparse expressions. * Fix sparse solvers when using a SparseVector as the result and/or right-hand-side. -## [3.3-rc2] - -Released on November 04, 2016 +## [3.3-rc2] - 2016-11-04 For a comprehensive list of change since the 3.2 series, see this [page](https://www.eigen.tuxfamily.org/index.php?title=3.3). @@ -600,9 +616,7 @@ Main changes since 3.3-rc1: * SuiteSparse, fix SPQR for rectangular matrices * Fix compilation of `qr.inverse()` for column and full pivoting variants -## [3.2.10] - -Released on October 04, 2016 +## [3.2.10] - 2016-10-04 Changes since 3.2.9: @@ -621,9 +635,7 @@ Main fixes and improvements: * #1249: disable the use of `__builtin_prefetch` for compilers other than GCC, clang, and ICC. * #1265: fix doc of QR decompositions -## [3.3-rc1] - -Released on September 22, 2016 +## [3.3-rc1] - 2016-09-22 For a comprehensive list of change since the 3.2 series, see this [page](https://www.eigen.tuxfamily.org/index.php?title=3.3). @@ -662,9 +674,7 @@ Main changes since 3.3-beta2: * Fix vectorization logic for coeff-based product for some corner cases * Bugs #1260, #1261, #1264: several fixes in AutoDiffScalar. -## [3.3-beta2] - -Released on July 26, 2016 +## [3.3-beta2] - 2016-08-26 For a comprehensive list of change since the 3.2 series, see this [page](https://www.eigen.tuxfamily.org/index.php?title=3.3). @@ -800,9 +810,7 @@ Main changes since 3.3-beta1: * #1249: fix compilation with compilers that do not support `__builtin_prefetch` . * #1250: fix `pow()` for `AutoDiffScalar` with custom nested scalar type. -## [3.2.9] - -Released on July 18, 2016 +## [3.2.9] - 2016-08-18 Changes since 3.2.8: @@ -836,9 +844,7 @@ Changes since 3.2.8: * #1221: shutdown some GCC6's warnings. * #1175: fix index type conversion warnings in sparse to dense conversion. -## [3.2.8] - -Released on February 16, 2016 +## [3.2.8] - 2016-02-16 Changes since 3.2.7: @@ -869,9 +875,7 @@ Changes since 3.2.7: * Some warning fixes. * Several other documentation clarifications. -## [3.3-beta1] - -Released on December 16, 2015 +## [3.3-beta1] - 2015-12-16 For a comprehensive list of change since the 3.2 series, see this [page](https://www.eigen.tuxfamily.org/index.php?title=3.3). @@ -938,9 +942,7 @@ Main changes since 3.3-alpha1: * Fix ICE with VC2015 Update1. * Improve cmake install scripts. -## [3.2.7] - -Released on November 5, 2015 +## [3.2.7] - 2015-11-05 Changes since 3.2.6: @@ -966,9 +968,7 @@ Changes since 3.2.6: * unsupported/ArpackSupport is now properly installed by make install. * #1080: warning fixes -## [3.2.6] - -Released on October 1, 2015 +## [3.2.6] - 2015-10-01 Changes since 3.2.5: @@ -984,15 +984,11 @@ Changes since 3.2.5: * MKL: fix support for the 11.2 version, and fix a naming conflict (#1067) * #1033: explicit type conversion from 0 to RealScalar -## [3.3-alpha1] - -Released on September 4, 2015 +## [3.3-alpha1] - 2015-09-04 See the [announcement](https://www.eigen.tuxfamily.org/index.php?title=3.3). -## [3.2.5] - -Released on June 16, 2015 +## [3.2.5] - 2015-06-16 Changes since 3.2.4: @@ -1036,9 +1032,7 @@ Changes since 3.2.4: * #1012: enable alloca on Mac OS or if alloca is defined as macro * Doc and build system: #733, #914, #952, #961, #999 -## [3.2.4] - -Released on January 21, 2015 +## [3.2.4] - 2015-01-21 Changes since 3.2.3: @@ -1047,9 +1041,7 @@ Changes since 3.2.3: * #921: fix utilization of bitwise operation on enums in `first_aligned`. * Fix compilation with NEON on some platforms. -## [3.2.3] - -Released on December 16, 2014 +## [3.2.3] - 2014-12-16 Changes since 3.2.2: @@ -1088,9 +1080,7 @@ Changes since 3.2.2: * #861: enable posix_memalign with PGI. * Fix BiCGSTAB doc example. -## [3.2.2] - -Released on August 4, 2014 +## [3.2.2] - 2014-08-04 Changes since 3.2.1: @@ -1134,9 +1124,7 @@ Changes since 3.2.1: * #632: doc: Note that `dm2 = sm1 + dm1` is not possible * Extend AsciiQuickReference (real, imag, conjugate, rot90) -## [3.2.1] - -Released on February 26, 2014 +## [3.2.1] - 2014-02-26 Changes since 3.2.0: @@ -1181,9 +1169,7 @@ Changes since 3.2.0: * Fix a few compiler warnings (bug #317 and more). * Documentation fixes (bugs #609, #638 and #739 and more). -## [3.1.4] - -Released on August 02, 2013 +## [3.1.4] - 2013-08-02 Changes since 3.1.3: @@ -1196,18 +1182,14 @@ Changes since 3.1.3: * Fix a few warnings and compilation issues with recent compiler versions. * Documentation fixes. -## [3.0.7] - -Released on August 02, 2013 +## [3.0.7] - 2013-08-02 Changes since 3.0.6: * Fix traits of `Map`. * Fix a few warnings (#507) and documentation (#531). -## [3.2.0] - -Released on July 24, 2013. +## [3.2.0] - 2013-07-24 Major new features and optimizations since 3.1: @@ -1234,18 +1216,14 @@ Major new features and optimizations since 3.1: Eigen 3.2 represents about 600 commits since Eigen 3.1. -## [3.2-rc2] - -Released on July 19, 2013. +## [3.2-rc2] - 2013-07-19 Changes since 3.2-rc1: * Rename `DenseBase::isFinite()` to `allFinite()` to avoid a future naming collision. * Fix an ICE with ICC 11.1. -## [3.2-rc1] - -Released on July 17, 2013. +## [3.2-rc1] - 2013-07-17 Main changes since 3.2-beta1: * New features: @@ -1290,9 +1268,7 @@ Main changes since 3.2-beta1: * Fix many warnings and compilation issues with recent compiler versions. * Many other fixes including #230, #482, #542, #561, #564, #565, #566, #578, #581, #595, #597, #598, #599, #605, #606, #615. -## [3.1.3] - -Released on April 16, 2013 +## [3.1.3] - 2013-04-16 Changes since 3.1.2: @@ -1310,9 +1286,7 @@ Changes since 3.1.2: * Enable SSE with ICC even when it mimics a gcc version lower than 4.2 * Workaround [gcc-4.7 bug #53900](http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53900) (too aggressive optimization in our alignment check) -## [3.2-beta1] - -Released on March 07, 2013 +## [3.2-beta1] - 2013-03-07 Main changes since 3.1: @@ -1338,9 +1312,7 @@ Main changes since 3.1: * New compilation token `EIGEN_INITIALIZE_MATRICES_BY_NAN` to help debugging. * All bug fixes of the 3.1 branch, plus a couple of other fixes (including 211, 479, 496, 508, 552) -## [3.1.2] - -Released on Nov 05, 2012 +## [3.1.2] - 2012-11-05 Changes since 3.1.1: @@ -1364,9 +1336,7 @@ Changes since 3.1.1: * Remove stupid assert in blue norm. * Workaround a weird compilation error with MSVC. -## [3.1.1] - -Released on July 22, 2012 +## [3.1.1] - 2012-07-22 Changes since 3.1.0: * [relicense to MPL2](https://www.eigen.tuxfamily.org/index.php?title=Main_Page#License) @@ -1382,9 +1352,7 @@ Changes since 3.1.0: * Fixed Geometry module compilation under MSVC * Fixed Sparse module compilation under MSVC 2005 -## [3.0.6] - -Released on July 9, 2012 +## [3.0.6] - 2012-07-09 Changes since 3.0.5: * #447 - fix infinite recursion in `ProductBase::coeff()` @@ -1404,9 +1372,7 @@ Changes since 3.0.5: * Fix typo in NumericalDiff (unsupported module) * Fix LevenbergMarquart for non double scalar type (unsupported module) -## [3.1.0] - -Released on June 24, 2012. +## [3.1.0] - 2012-06-24 Major changes between Eigen 3.0 and Eigen 3.1: * New features @@ -1429,9 +1395,7 @@ Major changes between Eigen 3.0 and Eigen 3.1: Eigen 3.1 represents about 600 commits since Eigen 3.0. -## [3.1.0-rc2] - -Released on June 21, 2012. +## [3.1.0-rc2] - 2012-06-21 Changes since 3.1.0-rc1: * Fix a couple of compilation warnings @@ -1440,9 +1404,7 @@ Changes since 3.1.0-rc1: * #466: `RealSchur` failed on a zero matrix * Update Adolc and MPReal support modules -## [3.1.0-rc1] - -Released on June 14, 2012 +## [3.1.0-rc1] - 2012-06-14 Main changes since 3.1.0-beta1: * #466: fix a possible race condition issue. from now, multithreaded applications that call Eigen from multiple thread must initialize Eigen by calling `initParallel()`. @@ -1454,9 +1416,7 @@ Main changes since 3.1.0-beta1: * Fix ambiguous calls in the math functors * Fix BTL interface. -## [3.1.0-beta1] - -Released on June 7, 2012 +## [3.1.0-beta1] - 2012-06-07 Main changes since 3.1.0-alpha2: * **API changes** @@ -1487,9 +1447,7 @@ Main changes since 3.1.0-alpha2: * New tutorial page on Map * and many other bug fixes such as: #417, #419, #450 -## [3.0.5] - -Released February 10, 2012 +## [3.0.5] - 2012-02-10 Changes since 3.0.4: * #417 - fix nesting of `Map` expressions @@ -1503,9 +1461,7 @@ Changes since 3.0.4: * Changeset 4432 - fix asserts in eigenvalue decompositions * Changeset 4416 - fix MSVC integer overflow warning -## [3.1.0-alpha2] - -Released February 6, 2012 +## [3.1.0-alpha2] - 2012-02-06 Main changes since 3.0.1-alpha1: * New optional support for Intel MKL and other BLAS including: ([details](http://eigen.tuxfamily.org/dox-devel/TopicUsingIntelMKL.html)) @@ -1532,9 +1488,7 @@ Main changes since 3.0.1-alpha1: * and many other bug fixes such as: #406, #410, #398, #396, #394, #354, #352, #301, -## [3.1.0-alpha1] - -Released December 6, 2011 +## [3.1.0-alpha1] - 2011-12-06 Main changes since 3.0: * Officially supported set of sparse modules. See this [page](http://eigen.tuxfamily.org/dox-devel/TutorialSparse.html) for an overview of the features. Main changes: @@ -1555,10 +1509,7 @@ Main changes since 3.0: * All the fixes and improvements of the 3.0 branch up to the 3.0.4 release (see below) - -## [3.0.4] - -Released December 6, 2011 +## [3.0.4] - 2011-12-06 Changes since 3.0.3: @@ -1572,9 +1523,7 @@ Changes since 3.0.3: * Fix compilation issue with `QuaternionBase::cast` -## [2.0.17] - -Released December 6, 2011 +## [2.0.17] - 2011-12-06 Changes since 2.0.16: @@ -1582,9 +1531,7 @@ Changes since 2.0.16: * Fix a typo in ParametrizedLine documentation -## [3.0.3] - -Released October 6, 2011 +## [3.0.3] - 2011-10-06 Changes since 3.0.2: @@ -1596,9 +1543,7 @@ Changes since 3.0.2: * Several improvements to the documentation. -## [3.0.2] - -Released August 26, 2011 +## [3.0.2] - 2011-08-26 Changes since 3.0.1: @@ -1615,9 +1560,7 @@ Changes since 3.0.1: * fix a few documentation issues. -## [3.0.1] - -Released May 30, 2011 +## [3.0.1] - 2011-05-30 Changes since 3.0.0: @@ -1634,9 +1577,7 @@ Changes since 3.0.0: * Fix Qt support in Transform. * Improved documentation. -## [2.0.16] - -Released May 28, 2011 +## [2.0.16] - 2011-05-28 Changes since 2.0.15: @@ -1647,18 +1588,16 @@ Changes since 2.0.15: * New feature: support for `part`. * Fix bug in SparseLU::setOrderingMethod. -## [3.0.0] +## [3.0.0] - 2011-03-19 -Released March 19, 2011, at the [meeting](https://www.eigen.tuxfamily.org/index.php?title=Paris_2011_Meeting). +Released at the [meeting](https://www.eigen.tuxfamily.org/index.php?title=Paris_2011_Meeting). See the [Eigen 3.0 release notes](https://www.eigen.tuxfamily.org/index.php?title=3.0). Only change since 3.0-rc1: * Fixed compilation of the unsupported 'openglsupport' test. -## [3.0-rc1] - -Released March 14, 2011. +## [3.0-rc1] - 2011-03-14 Main changes since 3.0-beta4: @@ -1677,9 +1616,7 @@ Main changes since 3.0-beta4: * more compiler warnings fixes * fixed GDB pretty-printer for dynamic-size matrices (#210) -## [3.0-beta4] - -Released February 28, 2011. +## [3.0-beta4] - 2011-02-28 Main changes since 3.0-beta3: @@ -1715,9 +1652,7 @@ Main changes since 3.0-beta3: * misc documentation improvements * improve documentation of plugins -## [3.0-beta3] - -Released February 12, 2011. +## [3.0-beta3] - 2011-02-12 The biggest news is that the API is now **100% stable**. @@ -1763,9 +1698,7 @@ Main changes since 3.0-beta2: * imported a copy of the Eigen 2 test suite, made sure that Eigen 3 passes it. That also allowed to fix several issues. -## [3.0-beta2] - -Released October 15, 2010. +## [3.0-beta2] - 2010-10-15 Main changes since 3.0-beta1: @@ -1790,9 +1723,7 @@ Main changes since 3.0-beta1: * Remove the Taucs backend (obsolete). * Remove the old SVD class (was causing too much troubles, a new decompozition based on bidiagonalisation/householder should come back soon, `JacobiSVD` can be used meanwhile). -## [2.0.15] - -Released July 16, 2010 +## [2.0.15] - 2010-07-16 Changes since 2.0.14: @@ -1803,15 +1734,11 @@ Changes since 2.0.14: * Fix for ICC in SSE code. * Fix some C++ issues found by Clang (patch by Nick Lewycky). -## [3.0-beta1] - -Released July 5, 2010 +## [3.0-beta1] - 2010-07-05 See the [announcement](https://www.eigen.tuxfamily.org/index.php?title=3.0). -## [2.0.14] - -Released June 22, 2010 +## [2.0.14] - 2010-06-22 Changes since 2.0.13: @@ -1819,9 +1746,7 @@ Changes since 2.0.13: * Fix #142: LU of fixed-size matrices was causing dynamic memory allocation (patch by Stuart Glaser). * Fix #127: remove useless static keywords (also fixes warnings with clang++). -## [2.0.13] - -Released June 10, 2010 +## [2.0.13] - 2010-06-10 Changes since 2.0.12: @@ -1836,9 +1761,7 @@ Changes since 2.0.12: * Fix compilation of the BTL benchmarks. * Some dox updates. -## [2.0.12] - -Released February 12, 2010 +## [2.0.12] - 2010-02-12 Changes since 2.0.11: @@ -1854,9 +1777,7 @@ Changes since 2.0.11: * Backport improvements to benchmarking code. * Documentation fixes -## [2.0.11] - -Released January 10, 2010 +## [2.0.11] - 2010-01-10 Changes since 2.0.10: @@ -1869,9 +1790,7 @@ Changes since 2.0.10: * Fix MSVC 2010 compatibility. * Some documentation improvements. -## [2.0.10] - -Released November 25, 2009 +## [2.0.10] - 2009-11-25 Changes since 2.0.9: @@ -1887,27 +1806,21 @@ Changes since 2.0.9: * fix compilation with MSVC 2010 * adjust to repository name change -## [2.0.9] - -Released October 24, 2009 +## [2.0.9] - 2009-10-24 Changes since 2.0.8: * Really fix installation and the pkg-config file. * Install the `NewStdVector` header that was introduced in 2.0.6. -## [2.0.8] - -Released October 23, 2009 +## [2.0.8] - 2009-10-23 Changes since 2.0.7: * fix installation error introduced in 2.0.7: it was choking on the pkg-config file eigen2.pc not being found. The fix had been proposed long ago by Ingmar Vanhassel for the development branch, and when recently the pkg-config support was back-ported to the 2.0 branch, nobody thought of backporting this fix too, and apparently nobody tested "make install" ! * SVD: add default constructor. Users were relying on the compiler to generate one, and apparenty 2.0.7 triggered a little MSVC 2008 subtlety in this respect. Also added an assert. -## [2.0.7] - -Released October 22, 2009 +## [2.0.7] - 2009-10-22 Changes since 2.0.6: @@ -1922,9 +1835,7 @@ Changes since 2.0.6: * add pkg-config support by Rhys Ulerich. * documentation fix and doc-generation-script updates by Thomas Capricelli -## [2.0.6] - -Released September 23, 2009 +## [2.0.6] - 2009-09-23 Changes since 2.0.5: @@ -1938,9 +1849,7 @@ Changes since 2.0.5: * fix a warning in `ei_aligned_malloc`; fixed by backporting the body from the devel branch; may result in a different choice of system aligned malloc function. * update the documentation. -## [2.0.5] - -Released August 22, 2009 +## [2.0.5] - 2009-08-22 Changes since 2.0.4: @@ -1959,9 +1868,7 @@ Changes since 2.0.4: * fix the option to build a binary library, although it's not very useful and will be removed * add basic .hgignore file and script to build the docs (thanks to Thomas Capricelli) -## [2.0.4] - -Released August 1, 2009 +## [2.0.4] - 2009-08-01 Changes since 2.0.3: * Several fixes in the overloaded new and delete operators. Thanks to Hauke Heibel. @@ -1975,9 +1882,7 @@ Changes since 2.0.3: * several ctest improvements: use our own dashboard, use a separate project for the 2.0 branch. * documentation: improvement on the pages on unaligned arrays (the online copies have been updated immediately). -## [2.0.3] - -Released June 21, 2009 +## [2.0.3] - 2009-06-21 Changes since 2.0.2: * precision and reliability fixes in various algorithms, especially LLT, QR, Tridiagonalization, and also a precision improvement in LU. @@ -1987,9 +1892,7 @@ Changes since 2.0.2: * backport documentation improvements on transpose() and adjoint() * updates in the Sparse module (was needed to support KDE 4.3) -## [2.0.2] - -Released May 22, 2009 +## [2.0.2] - 2009-05-22 Changes since 2.0.1: * Fix `linearRegression()` compilation, actually it is reimplemented using the better fitHyperplane() which does total least-squares. @@ -1999,9 +1902,7 @@ Changes since 2.0.1: * Fix compatibility with the old GCC 3.3: it is now fully supported again. * Fix warnings with recent GCC (4.4.0 and 4.3.3). -## [2.0.1] - -Released April 14, 2009 +## [2.0.1] - 2009-04-14 Changes since 2.0.0: * disable alignment altogether on exotic platforms on which we don't vectorize anyway. This allows e.g. to use Eigen on ARM platforms. @@ -2014,6 +1915,6 @@ Changes since 2.0.0: * fix wrong static assertion (patch by Markus Moll) * add missing operators in `aligned_allocator` (thanks to Hauke Heibel) -## [2.0.0] +## [2.0.0] - 2009-02-02 -Released February 2, 2009 \ No newline at end of file +First public release. \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 67f1bdfbe..928da3d9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,15 +100,28 @@ endif() # Version Info. #============================================================================== -# Automatically parse the version number from header files. -file(READ "${PROJECT_SOURCE_DIR}/Eigen/src/Core/util/Macros.h" _eigen_version_header) -string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}") -set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}") -string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}") -set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}") -string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}") -set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}") -set(EIGEN_VERSION_NUMBER ${EIGEN_WORLD_VERSION}.${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION}) +# If version information is not provided, automatically parse the version number +# from header files. +file(READ "${PROJECT_SOURCE_DIR}/Eigen/Version" _eigen_version_header) +if (NOT DEFINED EIGEN_WORLD_VERSION) + string(REGEX MATCH "define[ \t]+EIGEN_WORLD_VERSION[ \t]+([0-9]+)" _eigen_world_version_match "${_eigen_version_header}") + set(EIGEN_WORLD_VERSION "${CMAKE_MATCH_1}") +endif() +if (NOT DEFINED EIGEN_MAJOR_VERSION) + string(REGEX MATCH "define[ \t]+EIGEN_MAJOR_VERSION[ \t]+([0-9]+)" _eigen_major_version_match "${_eigen_version_header}") + set(EIGEN_MAJOR_VERSION "${CMAKE_MATCH_1}") +endif() +if (NOT DEFINED EIGEN_MINOR_VERSION) + string(REGEX MATCH "define[ \t]+EIGEN_MINOR_VERSION[ \t]+([0-9]+)" _eigen_minor_version_match "${_eigen_version_header}") + set(EIGEN_MINOR_VERSION "${CMAKE_MATCH_1}") +endif() +if (NOT DEFINED EIGEN_PATCH_VERSION) + string(REGEX MATCH "define[ \t]+EIGEN_PATCH_VERSION[ \t]+([0-9]+)" _eigen_patch_version_match "${_eigen_version_header}") + set(EIGEN_PATCH_VERSION "${CMAKE_MATCH_1}") +endif() +if (NOT DEFINED EIGEN_PRERELEASE_VERSION) + set(EIGEN_PRERELEASE_VERSION "dev") +endif() # If we are in a git repo, extract a changeset. if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git) @@ -119,16 +132,32 @@ endif() # extract the git rev number from the git output... if(EIGEN_GIT_OUTPUT) -string(REGEX MATCH "^([0-9;a-f]+).*" EIGEN_GIT_CHANGESET_MATCH "${EIGEN_GIT_OUTPUT}") -set(EIGEN_GIT_REVNUM "${CMAKE_MATCH_1}") + string(REGEX MATCH "^([0-9;a-f]+).*" EIGEN_GIT_CHANGESET_MATCH "${EIGEN_GIT_OUTPUT}") + set(EIGEN_GIT_REVNUM "${CMAKE_MATCH_1}") endif() -#...and show it next to the version number -if(EIGEN_GIT_REVNUM) - set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER} (git rev ${EIGEN_GIT_REVNUM})") + +if (NOT DEFINED EIGEN_BUILD_VERSION AND DEFINED EIGEN_GIT_REVNUM) + string(SUBSTRING "${EIGEN_GIT_REVNUM}" 0 8 EIGEN_BUILD_VERSION) else() - set(EIGEN_VERSION "${EIGEN_VERSION_NUMBER}") + set(EIGEN_BUILD_VERSION "") endif() +# The EIGEN_VERSION_NUMBER must be of the form . +# The EIGEN_VERSION_STRING can contain the preprelease/build strings. +set(EIGEN_VERSION_NUMBER "${EIGEN_MAJOR_VERSION}.${EIGEN_MINOR_VERSION}.${EIGEN_PATCH_VERSION}") +set(EIGEN_VERSION_STRING "${EIGEN_VERSION_NUMBER}") +if (NOT "x${EIGEN_PRERELEASE_VERSION}" STREQUAL "x") + set(EIGEN_VERSION_STRING "${EIGEN_VERSION_STRING}-${EIGEN_PRERELEASE_VERSION}") +endif() +if (NOT "x${EIGEN_BUILD_VERSION}" STREQUAL "x") + set(EIGEN_VERSION_STRING "${EIGEN_VERSION_STRING}+${EIGEN_BUILD_VERSION}") +endif() + + +# Generate version file. +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/Version.in" + "${CMAKE_CURRENT_BINARY_DIR}/include/Eigen/Version") + #============================================================================== # Install Path Configuration. #============================================================================== @@ -176,11 +205,6 @@ endforeach() # Eigen Library. #============================================================================== -set ( EIGEN_VERSION_STRING ${EIGEN_VERSION_NUMBER} ) -set ( EIGEN_VERSION_MAJOR ${EIGEN_WORLD_VERSION} ) -set ( EIGEN_VERSION_MINOR ${EIGEN_MAJOR_VERSION} ) -set ( EIGEN_VERSION_PATCH ${EIGEN_MINOR_VERSION} ) - # Alias Eigen_*_DIR to Eigen3_*_DIR: set(Eigen_SOURCE_DIR ${Eigen3_SOURCE_DIR}) set(Eigen_BINARY_DIR ${Eigen3_BINARY_DIR}) @@ -193,6 +217,9 @@ target_include_directories (eigen INTERFACE $ ) +# Eigen requires at least C++14 +target_compile_features (eigen INTERFACE cxx_std_14) + # Export as title case Eigen set_target_properties (eigen PROPERTIES EXPORT_NAME Eigen) @@ -212,6 +239,9 @@ if(EIGEN_BUILD_PKGCONFIG) endif() install(DIRECTORY Eigen DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel) +# Replace the "Version" header file with the generated one. +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/Eigen/Version + DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen/ COMPONENT Devel) install(TARGETS eigen EXPORT Eigen3Targets) @@ -225,25 +255,10 @@ if(EIGEN_BUILD_CMAKE_PACKAGE) NO_CHECK_REQUIRED_COMPONENTS_MACRO # Eigen does not provide components ) - # NOTE Remove the first code path once the minimum required CMake version is - # bumped to 3.14 or above. - if (CMAKE_VERSION VERSION_LESS 3.14) - # Remove CMAKE_SIZEOF_VOID_P from Eigen3ConfigVersion.cmake since Eigen does - # not depend on architecture specific settings or libraries. More - # specifically, an Eigen3Config.cmake generated from a 64 bit target can be - # used for 32 bit targets as well (and vice versa). - set (_Eigen3_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) - unset (CMAKE_SIZEOF_VOID_P) - write_basic_package_version_file (Eigen3ConfigVersion.cmake - VERSION ${EIGEN_VERSION_NUMBER} - COMPATIBILITY SameMajorVersion) - set (CMAKE_SIZEOF_VOID_P ${_Eigen3_CMAKE_SIZEOF_VOID_P}) - else (CMAKE_VERSION VERSION_LESS 3.14) - write_basic_package_version_file (Eigen3ConfigVersion.cmake - VERSION ${EIGEN_VERSION_NUMBER} - COMPATIBILITY SameMajorVersion - ARCH_INDEPENDENT) - endif (CMAKE_VERSION VERSION_LESS 3.14) + set(CVF_VERSION "${EIGEN_VERSION_NUMBER}") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/Eigen3ConfigVersion.cmake.in" + "Eigen3ConfigVersion.cmake" + @ONLY) # The Eigen target will be located in the Eigen3 namespace. Other CMake # targets can refer to it using Eigen3::Eigen. @@ -787,5 +802,5 @@ if(PROJECT_IS_TOP_LEVEL) endif() message(STATUS "") -message(STATUS "Configured Eigen ${EIGEN_VERSION_NUMBER}") +message(STATUS "Configured Eigen ${EIGEN_VERSION_STRING}") message(STATUS "") diff --git a/Eigen/Core b/Eigen/Core index 3988c8e84..e5a4e631f 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -11,6 +11,9 @@ #ifndef EIGEN_CORE_MODULE_H #define EIGEN_CORE_MODULE_H +// Eigen version information. +#include "Version" + // first thing Eigen does: stop the compiler from reporting useless warnings. #include "src/Core/util/DisableStupidWarnings.h" @@ -92,6 +95,7 @@ #include #include +#include #include // for std::is_nothrow_move_assignable @@ -102,6 +106,11 @@ #include #endif +// for std::bit_cast() +#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L +#include +#endif + // for outputting debug info #ifdef EIGEN_DEBUG_ASSIGN #include @@ -121,7 +130,6 @@ #undef isfinite #include #include -#include #include #include #ifndef EIGEN_SYCL_LOCAL_THREAD_DIM0 @@ -192,36 +200,51 @@ using std::ptrdiff_t; #include "src/Core/arch/Default/BFloat16.h" #include "src/Core/arch/Default/GenericPacketMathFunctionsFwd.h" -#if defined EIGEN_VECTORIZE_SSE +#if defined EIGEN_VECTORIZE_AVX512 #include "src/Core/arch/SSE/PacketMath.h" #include "src/Core/arch/SSE/Reductions.h" -#include "src/Core/arch/SSE/Complex.h" -#include "src/Core/arch/SSE/TypeCasting.h" -#include "src/Core/arch/SSE/MathFunctions.h" -#endif - -#if defined EIGEN_VECTORIZE_AVX #include "src/Core/arch/AVX/PacketMath.h" #include "src/Core/arch/AVX/Reductions.h" -#include "src/Core/arch/AVX/Complex.h" -#include "src/Core/arch/AVX/TypeCasting.h" -#include "src/Core/arch/AVX/MathFunctions.h" -#endif - -#if defined EIGEN_VECTORIZE_AVX512 #include "src/Core/arch/AVX512/PacketMath.h" #include "src/Core/arch/AVX512/Reductions.h" -#include "src/Core/arch/AVX512/Complex.h" -#include "src/Core/arch/AVX512/TypeCasting.h" -#include "src/Core/arch/AVX512/MathFunctions.h" -#include "src/Core/arch/AVX512/TrsmKernel.h" -#endif - #if defined EIGEN_VECTORIZE_AVX512FP16 #include "src/Core/arch/AVX512/PacketMathFP16.h" +#endif +#include "src/Core/arch/SSE/TypeCasting.h" +#include "src/Core/arch/AVX/TypeCasting.h" +#include "src/Core/arch/AVX512/TypeCasting.h" +#if defined EIGEN_VECTORIZE_AVX512FP16 #include "src/Core/arch/AVX512/TypeCastingFP16.h" +#endif +#include "src/Core/arch/SSE/Complex.h" +#include "src/Core/arch/AVX/Complex.h" +#include "src/Core/arch/AVX512/Complex.h" +#include "src/Core/arch/SSE/MathFunctions.h" +#include "src/Core/arch/AVX/MathFunctions.h" +#include "src/Core/arch/AVX512/MathFunctions.h" +#if defined EIGEN_VECTORIZE_AVX512FP16 #include "src/Core/arch/AVX512/MathFunctionsFP16.h" #endif +#include "src/Core/arch/AVX512/TrsmKernel.h" +#elif defined EIGEN_VECTORIZE_AVX +// Use AVX for floats and doubles, SSE for integers +#include "src/Core/arch/SSE/PacketMath.h" +#include "src/Core/arch/SSE/Reductions.h" +#include "src/Core/arch/SSE/TypeCasting.h" +#include "src/Core/arch/SSE/Complex.h" +#include "src/Core/arch/AVX/PacketMath.h" +#include "src/Core/arch/AVX/Reductions.h" +#include "src/Core/arch/AVX/TypeCasting.h" +#include "src/Core/arch/AVX/Complex.h" +#include "src/Core/arch/SSE/MathFunctions.h" +#include "src/Core/arch/AVX/MathFunctions.h" +#elif defined EIGEN_VECTORIZE_SSE +#include "src/Core/arch/SSE/PacketMath.h" +#include "src/Core/arch/SSE/Reductions.h" +#include "src/Core/arch/SSE/TypeCasting.h" +#include "src/Core/arch/SSE/MathFunctions.h" +#include "src/Core/arch/SSE/Complex.h" +#endif #if defined(EIGEN_VECTORIZE_ALTIVEC) || defined(EIGEN_VECTORIZE_VSX) #include "src/Core/arch/AltiVec/PacketMath.h" @@ -312,6 +335,7 @@ using std::ptrdiff_t; #include "src/Core/Product.h" #include "src/Core/CoreEvaluators.h" #include "src/Core/AssignEvaluator.h" +#include "src/Core/RealView.h" #include "src/Core/Assign.h" #include "src/Core/ArrayBase.h" diff --git a/Eigen/Version b/Eigen/Version new file mode 100644 index 000000000..164c87f62 --- /dev/null +++ b/Eigen/Version @@ -0,0 +1,14 @@ +#ifndef EIGEN_VERSION_H +#define EIGEN_VERSION_H + +// The "WORLD" version will forever remain "3" for the "Eigen3" library. +#define EIGEN_WORLD_VERSION 3 +// As of Eigen3 5.0.0, we have moved to Semantic Versioning (semver.org). +#define EIGEN_MAJOR_VERSION 5 +#define EIGEN_MINOR_VERSION 0 +#define EIGEN_PATCH_VERSION 1 +#define EIGEN_PRERELEASE_VERSION "dev" +#define EIGEN_BUILD_VERSION "master" +#define EIGEN_VERSION_STRING "5.0.1-dev+master" + +#endif // EIGEN_VERSION_H diff --git a/Eigen/src/Core/CoreEvaluators.h b/Eigen/src/Core/CoreEvaluators.h index 162175edc..4efe49476 100644 --- a/Eigen/src/Core/CoreEvaluators.h +++ b/Eigen/src/Core/CoreEvaluators.h @@ -707,7 +707,7 @@ struct unary_evaluator, ArgType>, In Index packetOffset = offset * PacketSize; Index actualRow = IsRowMajor ? row : row + packetOffset; Index actualCol = IsRowMajor ? col + packetOffset : col; - eigen_assert(check_array_bounds(actualRow, actualCol, 0, count) && "Array index out of bounds"); + eigen_assert(check_array_bounds(actualRow, actualCol, begin, count) && "Array index out of bounds"); return m_argImpl.template packetSegment(actualRow, actualCol, begin, count); } template @@ -715,8 +715,8 @@ struct unary_evaluator, ArgType>, In Index offset) const { constexpr int PacketSize = unpacket_traits::size; Index packetOffset = offset * PacketSize; - Index actualIndex = index + packetOffset + begin; - eigen_assert(check_array_bounds(actualIndex, 0, count) && "Array index out of bounds"); + Index actualIndex = index + packetOffset; + eigen_assert(check_array_bounds(actualIndex, begin, count) && "Array index out of bounds"); return m_argImpl.template packetSegment(actualIndex, begin, count); } @@ -1048,22 +1048,33 @@ struct ternary_evaluator, IndexBased Data m_d; }; -// specialization for expressions like (a < b).select(c, d) to enable full vectorization template -struct evaluator, Arg1, Arg2, - CwiseBinaryOp, CmpLhsType, CmpRhsType>>> - : public ternary_evaluator< - CwiseTernaryOp, Arg1, Arg2, - CwiseBinaryOp, CmpLhsType, CmpRhsType>>> { +struct scalar_boolean_select_spec { using DummyTernaryOp = scalar_boolean_select_op; using DummyArg3 = CwiseBinaryOp, CmpLhsType, CmpRhsType>; using DummyXprType = CwiseTernaryOp; - using TernaryOp = scalar_boolean_select_op; - using Arg3 = CwiseBinaryOp, CmpLhsType, CmpRhsType>; + // only use the typed comparison if it is vectorized + static constexpr bool UseTyped = functor_traits>::PacketAccess; + using CondScalar = std::conditional_t; + + using TernaryOp = scalar_boolean_select_op; + using Arg3 = CwiseBinaryOp, CmpLhsType, CmpRhsType>; using XprType = CwiseTernaryOp; using Base = ternary_evaluator; +}; + +// specialization for expressions like (a < b).select(c, d) to enable full vectorization +template +struct evaluator, Arg1, Arg2, + CwiseBinaryOp, CmpLhsType, CmpRhsType>>> + : public scalar_boolean_select_spec::Base { + using Helper = scalar_boolean_select_spec; + using Base = typename Helper::Base; + using DummyXprType = typename Helper::DummyXprType; + using Arg3 = typename Helper::Arg3; + using XprType = typename Helper::XprType; EIGEN_DEVICE_FUNC explicit evaluator(const DummyXprType& xpr) : Base(XprType(xpr.arg1(), xpr.arg2(), Arg3(xpr.arg3().lhs(), xpr.arg3().rhs()))) {} @@ -1569,50 +1580,6 @@ struct block_evaluator -struct evaluator> - : evaluator_base> { - typedef Select XprType; - enum { - CoeffReadCost = evaluator::CoeffReadCost + - plain_enum_max(evaluator::CoeffReadCost, evaluator::CoeffReadCost), - - Flags = (unsigned int)evaluator::Flags & evaluator::Flags & HereditaryBits, - - Alignment = plain_enum_min(evaluator::Alignment, evaluator::Alignment) - }; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE explicit evaluator(const XprType& select) - : m_conditionImpl(select.conditionMatrix()), m_thenImpl(select.thenMatrix()), m_elseImpl(select.elseMatrix()) { - EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost); - } - - typedef typename XprType::CoeffReturnType CoeffReturnType; - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index row, Index col) const { - if (m_conditionImpl.coeff(row, col)) - return m_thenImpl.coeff(row, col); - else - return m_elseImpl.coeff(row, col); - } - - EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { - if (m_conditionImpl.coeff(index)) - return m_thenImpl.coeff(index); - else - return m_elseImpl.coeff(index); - } - - protected: - evaluator m_conditionImpl; - evaluator m_thenImpl; - evaluator m_elseImpl; -}; - // -------------------- Replicate -------------------- template diff --git a/Eigen/src/Core/CwiseNullaryOp.h b/Eigen/src/Core/CwiseNullaryOp.h index 13a542a02..e4c5fedc3 100644 --- a/Eigen/src/Core/CwiseNullaryOp.h +++ b/Eigen/src/Core/CwiseNullaryOp.h @@ -235,8 +235,7 @@ DenseBase::Constant(const Scalar& value) { * \sa LinSpaced(Index,const Scalar&, const Scalar&), setLinSpaced(Index,const Scalar&,const Scalar&) */ template -EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase< - Derived>::RandomAccessLinSpacedReturnType +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::RandomAccessLinSpacedReturnType DenseBase::LinSpaced(Sequential_t, Index size, const Scalar& low, const Scalar& high) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) return DenseBase::NullaryExpr(size, internal::linspaced_op(low, high, size)); @@ -247,8 +246,7 @@ DenseBase::LinSpaced(Sequential_t, Index size, const Scalar& low, const * \sa LinSpaced(const Scalar&, const Scalar&) */ template -EIGEN_DEPRECATED EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase< - Derived>::RandomAccessLinSpacedReturnType +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const typename DenseBase::RandomAccessLinSpacedReturnType DenseBase::LinSpaced(Sequential_t, const Scalar& low, const Scalar& high) { EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 4f6894280..c81e1d109 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -306,12 +306,12 @@ class DenseBase EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(Index size, const Scalar& value); EIGEN_DEVICE_FUNC static const ConstantReturnType Constant(const Scalar& value); - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, - const Scalar& low, - const Scalar& high); - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, - const Scalar& low, - const Scalar& high); + EIGEN_DEPRECATED_WITH_REASON("The method may result in accuracy loss. Use .EqualSpaced() instead.") + EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, Index size, const Scalar& low, + const Scalar& high); + EIGEN_DEPRECATED_WITH_REASON("The method may result in accuracy loss. Use .EqualSpaced() instead.") + EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Sequential_t, const Scalar& low, + const Scalar& high); EIGEN_DEVICE_FUNC static const RandomAccessLinSpacedReturnType LinSpaced(Index size, const Scalar& low, const Scalar& high); @@ -367,7 +367,12 @@ class DenseBase EIGEN_DEVICE_FUNC inline bool allFinite() const; EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*=(const Scalar& other); + template ::value, typename = std::enable_if_t> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator*=(const RealScalar& other); + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator/=(const Scalar& other); + template ::value, typename = std::enable_if_t> + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator/=(const RealScalar& other); typedef internal::add_const_on_value_type_t::type> EvalReturnType; /** \returns the matrix or vector obtained by evaluating this expression. @@ -597,6 +602,13 @@ class DenseBase inline const_iterator end() const; inline const_iterator cend() const; + using RealViewReturnType = std::conditional_t::IsComplex, RealView, Derived&>; + using ConstRealViewReturnType = + std::conditional_t::IsComplex, RealView, const Derived&>; + + EIGEN_DEVICE_FUNC RealViewReturnType realView(); + EIGEN_DEVICE_FUNC ConstRealViewReturnType realView() const; + #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::DenseBase #define EIGEN_DOC_BLOCK_ADDONS_NOT_INNER_PANEL #define EIGEN_DOC_BLOCK_ADDONS_INNER_PANEL_IF(COND) diff --git a/Eigen/src/Core/Fill.h b/Eigen/src/Core/Fill.h index 9d4ecd445..779ef26ab 100644 --- a/Eigen/src/Core/Fill.h +++ b/Eigen/src/Core/Fill.h @@ -78,8 +78,9 @@ template struct eigen_fill_impl { using Scalar = typename Xpr::Scalar; static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const Scalar& val) { + const Scalar val_copy = val; using std::fill_n; - fill_n(dst.data(), dst.size(), val); + fill_n(dst.data(), dst.size(), val_copy); } template static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const SrcXpr& src) { @@ -114,17 +115,15 @@ struct eigen_zero_impl { template struct eigen_zero_impl { using Scalar = typename Xpr::Scalar; - static constexpr size_t max_bytes = (std::numeric_limits::max)(); static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst) { - const size_t num_bytes = dst.size() * sizeof(Scalar); - if (num_bytes == 0) return; + const std::ptrdiff_t num_bytes = dst.size() * static_cast(sizeof(Scalar)); + if (num_bytes <= 0) return; void* dst_ptr = static_cast(dst.data()); #ifndef EIGEN_NO_DEBUG - if (num_bytes > max_bytes) throw_std_bad_alloc(); eigen_assert((dst_ptr != nullptr) && "null pointer dereference error!"); #endif EIGEN_USING_STD(memset); - memset(dst_ptr, 0, num_bytes); + memset(dst_ptr, 0, static_cast(num_bytes)); } template static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void run(Xpr& dst, const SrcXpr& src) { diff --git a/Eigen/src/Core/GenericPacketMath.h b/Eigen/src/Core/GenericPacketMath.h index 4877288e2..6c5370b44 100644 --- a/Eigen/src/Core/GenericPacketMath.h +++ b/Eigen/src/Core/GenericPacketMath.h @@ -65,7 +65,7 @@ struct default_packet_traits { HasAbsDiff = 0, HasBlend = 0, // This flag is used to indicate whether packet comparison is supported. - // pcmp_eq, pcmp_lt and pcmp_le should be defined for it to be true. + // pcmp_eq and pcmp_lt should be defined for it to be true. HasCmp = 0, HasDiv = 0, @@ -253,6 +253,12 @@ struct preinterpret_generic { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Packet run(const Packet& a) { return a; } }; +template +struct preinterpret_generic::as_real, ComplexPacket, false> { + using RealPacket = typename unpacket_traits::as_real; + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE RealPacket run(const ComplexPacket& a) { return a.v; } +}; + /** \internal \returns reinterpret_cast(a) */ template EIGEN_DEVICE_FUNC inline Target preinterpret(const Packet& a) { @@ -426,30 +432,6 @@ EIGEN_DEVICE_FUNC inline Packet pzero(const Packet& a) { return pzero_impl::run(a); } -/** \internal \returns a <= b as a bit mask */ -template -EIGEN_DEVICE_FUNC inline Packet pcmp_le(const Packet& a, const Packet& b) { - return a <= b ? ptrue(a) : pzero(a); -} - -/** \internal \returns a < b as a bit mask */ -template -EIGEN_DEVICE_FUNC inline Packet pcmp_lt(const Packet& a, const Packet& b) { - return a < b ? ptrue(a) : pzero(a); -} - -/** \internal \returns a == b as a bit mask */ -template -EIGEN_DEVICE_FUNC inline Packet pcmp_eq(const Packet& a, const Packet& b) { - return a == b ? ptrue(a) : pzero(a); -} - -/** \internal \returns a < b or a==NaN or b==NaN as a bit mask */ -template -EIGEN_DEVICE_FUNC inline Packet pcmp_lt_or_nan(const Packet& a, const Packet& b) { - return a >= b ? pzero(a) : ptrue(a); -} - template struct bit_and { EIGEN_DEVICE_FUNC constexpr EIGEN_ALWAYS_INLINE T operator()(const T& a, const T& b) const { return a & b; } @@ -576,6 +558,30 @@ EIGEN_DEVICE_FUNC inline Packet pandnot(const Packet& a, const Packet& b) { return pand(a, pnot(b)); } +/** \internal \returns a < b as a bit mask */ +template +EIGEN_DEVICE_FUNC inline Packet pcmp_lt(const Packet& a, const Packet& b) { + return a < b ? ptrue(a) : pzero(a); +} + +/** \internal \returns a == b as a bit mask */ +template +EIGEN_DEVICE_FUNC inline Packet pcmp_eq(const Packet& a, const Packet& b) { + return a == b ? ptrue(a) : pzero(a); +} + +/** \internal \returns a <= b as a bit mask */ +template +EIGEN_DEVICE_FUNC inline Packet pcmp_le(const Packet& a, const Packet& b) { + return por(pcmp_eq(a, b), pcmp_lt(a, b)); +} + +/** \internal \returns a < b or a==NaN or b==NaN as a bit mask */ +template +EIGEN_DEVICE_FUNC inline Packet pcmp_lt_or_nan(const Packet& a, const Packet& b) { + return a >= b ? pzero(a) : ptrue(a); +} + // In the general case, use bitwise select. template ::value> struct pselect_impl { @@ -638,7 +644,7 @@ struct pminmax_impl { } }; -#define EIGEN_BINARY_OP_NAN_PROPAGATION(Type, Func) [](const Type& a, const Type& b) { return Func(a, b); } +#define EIGEN_BINARY_OP_NAN_PROPAGATION(Type, Func) [](const Type& aa, const Type& bb) { return Func(aa, bb); } /** \internal \returns the min of \a a and \a b (coeff-wise). If \a a or \b b is NaN, the return value is implementation defined. */ @@ -1344,20 +1350,20 @@ struct pmadd_impl { template struct pmadd_impl::value && NumTraits::IsSigned>> { static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar pmadd(const Scalar& a, const Scalar& b, const Scalar& c) { - return numext::fma(a, b, c); + return numext::madd(a, b, c); } static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar pmsub(const Scalar& a, const Scalar& b, const Scalar& c) { - return numext::fma(a, b, Scalar(-c)); + return numext::madd(a, b, Scalar(-c)); } static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar pnmadd(const Scalar& a, const Scalar& b, const Scalar& c) { - return numext::fma(Scalar(-a), b, c); + return numext::madd(Scalar(-a), b, c); } static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE Scalar pnmsub(const Scalar& a, const Scalar& b, const Scalar& c) { - return -Scalar(numext::fma(a, b, c)); + return -Scalar(numext::madd(a, b, c)); } }; -// FMA instructions. +// Multiply-add instructions. /** \internal \returns a * b + c (coeff-wise) */ template EIGEN_DEVICE_FUNC inline Packet pmadd(const Packet& a, const Packet& b, const Packet& c) { @@ -1596,9 +1602,10 @@ EIGEN_DEVICE_FUNC inline Packet ploaduSegment(const typename unpacket_traits::type; constexpr Index PacketSize = unpacket_traits::size; eigen_assert((begin >= 0 && count >= 0 && begin + count <= PacketSize) && "invalid range"); - Scalar aux[PacketSize]; - memset(static_cast(aux), 0x00, sizeof(Scalar) * PacketSize); - smart_copy(from + begin, from + begin + count, aux + begin); + Scalar aux[PacketSize] = {}; + for (Index k = begin; k < begin + count; k++) { + aux[k] = from[k]; + } return ploadu(aux); } @@ -1619,7 +1626,9 @@ EIGEN_DEVICE_FUNC inline void pstoreuSegment(Scalar* to, const Packet& from, Ind eigen_assert((begin >= 0 && count >= 0 && begin + count <= PacketSize) && "invalid range"); Scalar aux[PacketSize]; pstoreu(aux, from); - smart_copy(aux + begin, aux + begin + count, to + begin); + for (Index k = begin; k < begin + count; k++) { + to[k] = aux[k]; + } } /** \internal copy the packet \a from in the range [begin, begin + count) to \a *to. diff --git a/Eigen/src/Core/IndexedView.h b/Eigen/src/Core/IndexedView.h index 358239ca8..10562c194 100644 --- a/Eigen/src/Core/IndexedView.h +++ b/Eigen/src/Core/IndexedView.h @@ -308,6 +308,12 @@ struct unary_evaluator, IndexBased> const XprType& m_xpr; }; +// Catch assignments to an IndexedView. +template +struct evaluator_assume_aliasing> { + static const bool value = true; +}; + } // end namespace internal } // end namespace Eigen diff --git a/Eigen/src/Core/InnerProduct.h b/Eigen/src/Core/InnerProduct.h index 9849d9b1f..686ad1379 100644 --- a/Eigen/src/Core/InnerProduct.h +++ b/Eigen/src/Core/InnerProduct.h @@ -211,8 +211,14 @@ struct scalar_inner_product_op { static constexpr bool PacketAccess = false; }; +// Partial specialization for packet access if and only if +// LhsScalar == RhsScalar == ScalarBinaryOpTraits::ReturnType. template -struct scalar_inner_product_op { +struct scalar_inner_product_op< + Scalar, + typename std::enable_if::ReturnType, Scalar>::value, + Scalar>::type, + Conj> { using result_type = Scalar; using conj_helper = conditional_conj; EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(const Scalar& a, const Scalar& b) const { diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 481e057d0..155fdad20 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -941,23 +941,43 @@ struct nearest_integer_impl { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_trunc(const Scalar& x) { return x; } }; +// Extra namespace to prevent leaking std::fma into Eigen::internal. +namespace has_fma_detail { + +template +struct has_fma_impl : public std::false_type {}; + +using std::fma; + +template +struct has_fma_impl< + T, std::enable_if_t(), std::declval(), std::declval()))>::value>> + : public std::true_type {}; + +} // namespace has_fma_detail + +template +struct has_fma : public has_fma_detail::has_fma_impl {}; + // Default implementation. -template +template struct fma_impl { - static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run(const Scalar& a, const Scalar& b, const Scalar& c) { - return a * b + c; + static_assert(has_fma::value, "No function fma(...) for type. Please provide an implementation."); +}; + +// STD or ADL version if it exists. +template +struct fma_impl::value>> { + static EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T run(const T& a, const T& b, const T& c) { + using std::fma; + return fma(a, b, c); } }; -// ADL version if it exists. -template -struct fma_impl< - T, - std::enable_if_t(), std::declval(), std::declval()))>::value>> { - static T run(const T& a, const T& b, const T& c) { return fma(a, b, c); } -}; - #if defined(EIGEN_GPUCC) +template <> +struct has_fma : public true_type {}; + template <> struct fma_impl { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float run(const float& a, const float& b, const float& c) { @@ -965,6 +985,9 @@ struct fma_impl { } }; +template <> +struct has_fma : public true_type {}; + template <> struct fma_impl { static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double run(const double& a, const double& b, const double& c) { @@ -973,6 +996,24 @@ struct fma_impl { }; #endif +// Basic multiply-add. +template +struct madd_impl { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run(const Scalar& x, const Scalar& y, const Scalar& z) { + return x * y + z; + } +}; + +// Use FMA if there is a single CPU instruction. +#ifdef EIGEN_VECTORIZE_FMA +template +struct madd_impl::value>> { + static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run(const Scalar& x, const Scalar& y, const Scalar& z) { + return fma_impl::run(x, y, z); + } +}; +#endif + } // end namespace internal /**************************************************************************** @@ -1886,15 +1927,18 @@ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar arithmetic_shift_right(const Scalar return bit_cast(bit_cast(a) >> n); } -// Use std::fma if available. -using std::fma; - // Otherwise, rely on template implementation. template EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar fma(const Scalar& x, const Scalar& y, const Scalar& z) { return internal::fma_impl::run(x, y, z); } +// Multiply-add. +template +EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar madd(const Scalar& x, const Scalar& y, const Scalar& z) { + return internal::madd_impl::run(x, y, z); +} + } // end namespace numext namespace internal { diff --git a/Eigen/src/Core/MathFunctionsImpl.h b/Eigen/src/Core/MathFunctionsImpl.h index cf8dcc3b8..c4b5da3cc 100644 --- a/Eigen/src/Core/MathFunctionsImpl.h +++ b/Eigen/src/Core/MathFunctionsImpl.h @@ -28,7 +28,7 @@ namespace internal { 2. If a is zero, approx_a_recip must be infinite with the same sign as a. 3. If a is infinite, approx_a_recip must be zero with the same sign as a. - If the preconditions are satisfied, which they are for for the _*_rcp_ps + If the preconditions are satisfied, which they are for the _*_rcp_ps instructions on x86, the result has a maximum relative error of 2 ulps, and correctly handles reciprocals of zero, infinity, and NaN. */ @@ -66,7 +66,7 @@ struct generic_reciprocal_newton_step { 2. If a is zero, approx_a_recip must be infinite with the same sign as a. 3. If a is infinite, approx_a_recip must be zero with the same sign as a. - If the preconditions are satisfied, which they are for for the _*_rcp_ps + If the preconditions are satisfied, which they are for the _*_rcp_ps instructions on x86, the result has a maximum relative error of 2 ulps, and correctly handles zero, infinity, and NaN. Positive denormals are treated as zero. @@ -116,7 +116,7 @@ struct generic_rsqrt_newton_step { 2. If a is zero, approx_rsqrt must be infinite. 3. If a is infinite, approx_rsqrt must be zero. - If the preconditions are satisfied, which they are for for the _*_rsqrt_ps + If the preconditions are satisfied, which they are for the _*_rsqrt_ps instructions on x86, the result has a maximum relative error of 2 ulps, and correctly handles zero and infinity, and NaN. Positive denormal inputs are treated as zero. diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 8d5c47e47..045993d46 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -373,12 +373,14 @@ class MatrixBase : public DenseBase { template inline JacobiSVD jacobiSvd() const; template - EIGEN_DEPRECATED inline JacobiSVD jacobiSvd(unsigned int computationOptions) const; + EIGEN_DEPRECATED_WITH_REASON("Options should be specified using method's template parameter.") + inline JacobiSVD jacobiSvd(unsigned int computationOptions) const; template inline BDCSVD bdcSvd() const; template - EIGEN_DEPRECATED inline BDCSVD bdcSvd(unsigned int computationOptions) const; + EIGEN_DEPRECATED_WITH_REASON("Options should be specified using method's template parameter.") + inline BDCSVD bdcSvd(unsigned int computationOptions) const; /////////// Geometry module /////////// @@ -391,7 +393,8 @@ class MatrixBase : public DenseBase { EIGEN_DEVICE_FUNC inline PlainObject unitOrthogonal(void) const; - EIGEN_DEPRECATED EIGEN_DEVICE_FUNC inline Matrix eulerAngles(Index a0, Index a1, Index a2) const; + EIGEN_DEPRECATED_WITH_REASON("Use .canonicalEulerAngles() instead.") + EIGEN_DEVICE_FUNC inline Matrix eulerAngles(Index a0, Index a1, Index a2) const; EIGEN_DEVICE_FUNC inline Matrix canonicalEulerAngles(Index a0, Index a1, Index a2) const; diff --git a/Eigen/src/Core/NumTraits.h b/Eigen/src/Core/NumTraits.h index 5e4e5c2ff..bf41c3bb6 100644 --- a/Eigen/src/Core/NumTraits.h +++ b/Eigen/src/Core/NumTraits.h @@ -95,9 +95,22 @@ struct default_max_digits10_impl // Integer } // end namespace internal namespace numext { -/** \internal bit-wise cast without changing the underlying bit representation. */ -// TODO: Replace by std::bit_cast (available in C++20) +/** \internal bit-wise cast without changing the underlying bit representation. */ +#if defined(__cpp_lib_bit_cast) && __cpp_lib_bit_cast >= 201806L +template +EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr Tgt bit_cast(const Src& src) { + return std::bit_cast(src); +} +#elif EIGEN_HAS_BUILTIN(__builtin_bit_cast) +template +EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC constexpr Tgt bit_cast(const Src& src) { + EIGEN_STATIC_ASSERT(std::is_trivially_copyable::value, THIS_TYPE_IS_NOT_SUPPORTED) + EIGEN_STATIC_ASSERT(std::is_trivially_copyable::value, THIS_TYPE_IS_NOT_SUPPORTED) + EIGEN_STATIC_ASSERT(sizeof(Src) == sizeof(Tgt), THIS_TYPE_IS_NOT_SUPPORTED) + return __builtin_bit_cast(Tgt, src); +} +#else template EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Tgt bit_cast(const Src& src) { // The behaviour of memcpy is not specified for non-trivially copyable types @@ -113,6 +126,7 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Tgt bit_cast(const Src& src) { memcpy(static_cast(&tgt), static_cast(&staged), sizeof(Tgt)); return tgt; } +#endif } // namespace numext // clang-format off diff --git a/Eigen/src/Core/PermutationMatrix.h b/Eigen/src/Core/PermutationMatrix.h index 4748b118a..771335451 100644 --- a/Eigen/src/Core/PermutationMatrix.h +++ b/Eigen/src/Core/PermutationMatrix.h @@ -109,6 +109,9 @@ class PermutationBase : public EigenBase { */ DenseMatrixType toDenseMatrix() const { return derived(); } + /** \returns the plain matrix representation of the permutation. */ + DenseMatrixType eval() const { return toDenseMatrix(); } + /** const version of indices(). */ const IndicesType& indices() const { return derived().indices(); } /** \returns a reference to the stored array representing the permutation. */ @@ -468,17 +471,17 @@ class PermutationWrapper : public PermutationBase -EIGEN_DEVICE_FUNC const Product operator*( +EIGEN_DEVICE_FUNC const Product operator*( const MatrixBase& matrix, const PermutationBase& permutation) { - return Product(matrix.derived(), permutation.derived()); + return Product(matrix.derived(), permutation.derived()); } /** \returns the matrix with the permutation applied to the rows. */ template -EIGEN_DEVICE_FUNC const Product operator*( +EIGEN_DEVICE_FUNC const Product operator*( const PermutationBase& permutation, const MatrixBase& matrix) { - return Product(permutation.derived(), matrix.derived()); + return Product(permutation.derived(), matrix.derived()); } template @@ -520,16 +523,16 @@ class InverseImpl : public EigenBase - friend const Product operator*(const MatrixBase& matrix, - const InverseType& trPerm) { - return Product(matrix.derived(), trPerm.derived()); + friend const Product operator*(const MatrixBase& matrix, + const InverseType& trPerm) { + return Product(matrix.derived(), trPerm.derived()); } /** \returns the matrix with the inverse permutation applied to the rows. */ template - const Product operator*(const MatrixBase& matrix) const { - return Product(derived(), matrix.derived()); + const Product operator*(const MatrixBase& matrix) const { + return Product(derived(), matrix.derived()); } }; diff --git a/Eigen/src/Core/ProductEvaluators.h b/Eigen/src/Core/ProductEvaluators.h index 1051e77bf..034603816 100644 --- a/Eigen/src/Core/ProductEvaluators.h +++ b/Eigen/src/Core/ProductEvaluators.h @@ -1269,6 +1269,22 @@ struct generic_product_impl +struct generic_product_impl + : generic_product_impl {}; + +template +struct generic_product_impl + : generic_product_impl {}; + +template +struct generic_product_impl + : generic_product_impl {}; + +template +struct generic_product_impl + : generic_product_impl {}; + } // end namespace internal } // end namespace Eigen diff --git a/Eigen/src/Core/RandomImpl.h b/Eigen/src/Core/RandomImpl.h index efba33680..1a82e6253 100644 --- a/Eigen/src/Core/RandomImpl.h +++ b/Eigen/src/Core/RandomImpl.h @@ -131,8 +131,15 @@ struct random_longdouble_impl { uint64_t randomBits[2]; long double result = 2.0L; memcpy(&randomBits, &result, Size); +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ randomBits[0] |= getRandomBits(numLowBits); randomBits[1] |= getRandomBits(numHighBits); +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + randomBits[0] |= getRandomBits(numHighBits); + randomBits[1] |= getRandomBits(numLowBits); +#else +#error Unexpected or undefined __BYTE_ORDER__ +#endif memcpy(&result, &randomBits, Size); result -= 3.0L; return result; diff --git a/Eigen/src/Core/RealView.h b/Eigen/src/Core/RealView.h new file mode 100644 index 000000000..7ba42f9a1 --- /dev/null +++ b/Eigen/src/Core/RealView.h @@ -0,0 +1,250 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2025 Charlie Schlosser +// +// This Source Code Form is subject to the terms of the Mozilla +// 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_REALVIEW_H +#define EIGEN_REALVIEW_H + +// IWYU pragma: private +#include "./InternalHeaderCheck.h" + +namespace Eigen { + +namespace internal { + +// Vectorized assignment to RealView requires array-oriented access to the real and imaginary components. +// From https://en.cppreference.com/w/cpp/numeric/complex.html: +// For any pointer to an element of an array of std::complex named p and any valid array index i, +// reinterpret_cast(p)[2 * i] is the real part of the complex number p[i], and +// reinterpret_cast(p)[2 * i + 1] is the imaginary part of the complex number p[i]. + +template +struct complex_array_access : std::false_type {}; +template <> +struct complex_array_access> : std::true_type {}; +template <> +struct complex_array_access> : std::true_type {}; +template <> +struct complex_array_access> : std::true_type {}; + +template +struct traits> : public traits { + template + static constexpr int double_size(T size, bool times_two) { + int size_as_int = int(size); + if (size_as_int == Dynamic) return Dynamic; + return times_two ? (2 * size_as_int) : size_as_int; + } + using Base = traits; + using ComplexScalar = typename Base::Scalar; + using Scalar = typename NumTraits::Real; + static constexpr int ActualDirectAccessBit = complex_array_access::value ? DirectAccessBit : 0; + static constexpr int ActualPacketAccessBit = packet_traits::Vectorizable ? PacketAccessBit : 0; + static constexpr int FlagMask = + ActualDirectAccessBit | ActualPacketAccessBit | HereditaryBits | LinearAccessBit | LvalueBit; + static constexpr int BaseFlags = int(evaluator::Flags) | int(Base::Flags); + static constexpr int Flags = BaseFlags & FlagMask; + static constexpr bool IsRowMajor = Flags & RowMajorBit; + static constexpr int RowsAtCompileTime = double_size(Base::RowsAtCompileTime, !IsRowMajor); + static constexpr int ColsAtCompileTime = double_size(Base::ColsAtCompileTime, IsRowMajor); + static constexpr int SizeAtCompileTime = size_at_compile_time(RowsAtCompileTime, ColsAtCompileTime); + static constexpr int MaxRowsAtCompileTime = double_size(Base::MaxRowsAtCompileTime, !IsRowMajor); + static constexpr int MaxColsAtCompileTime = double_size(Base::MaxColsAtCompileTime, IsRowMajor); + static constexpr int MaxSizeAtCompileTime = size_at_compile_time(MaxRowsAtCompileTime, MaxColsAtCompileTime); + static constexpr int OuterStrideAtCompileTime = double_size(outer_stride_at_compile_time::ret, true); + static constexpr int InnerStrideAtCompileTime = inner_stride_at_compile_time::ret; +}; + +template +struct evaluator> : private evaluator { + using BaseEvaluator = evaluator; + using XprType = RealView; + using ExpressionTraits = traits; + using ComplexScalar = typename ExpressionTraits::ComplexScalar; + using ComplexCoeffReturnType = typename BaseEvaluator::CoeffReturnType; + using Scalar = typename ExpressionTraits::Scalar; + + static constexpr bool IsRowMajor = ExpressionTraits::IsRowMajor; + static constexpr int Flags = ExpressionTraits::Flags; + static constexpr int CoeffReadCost = BaseEvaluator::CoeffReadCost; + static constexpr int Alignment = BaseEvaluator::Alignment; + + EIGEN_DEVICE_FUNC explicit evaluator(XprType realView) : BaseEvaluator(realView.m_xpr) {} + + template ::value, typename = std::enable_if_t> + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index row, Index col) const { + ComplexCoeffReturnType cscalar = BaseEvaluator::coeff(IsRowMajor ? row : row / 2, IsRowMajor ? col / 2 : col); + Index p = (IsRowMajor ? col : row) & 1; + return p ? numext::real(cscalar) : numext::imag(cscalar); + } + + template ::value, typename = std::enable_if_t> + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(Index row, Index col) const { + ComplexCoeffReturnType cscalar = BaseEvaluator::coeff(IsRowMajor ? row : row / 2, IsRowMajor ? col / 2 : col); + Index p = (IsRowMajor ? col : row) & 1; + return reinterpret_cast(cscalar)[p]; + } + + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index row, Index col) { + ComplexScalar& cscalar = BaseEvaluator::coeffRef(IsRowMajor ? row : row / 2, IsRowMajor ? col / 2 : col); + Index p = (IsRowMajor ? col : row) & 1; + return reinterpret_cast(cscalar)[p]; + } + + template ::value, typename = std::enable_if_t> + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar coeff(Index index) const { + ComplexCoeffReturnType cscalar = BaseEvaluator::coeff(index / 2); + Index p = index & 1; + return p ? numext::real(cscalar) : numext::imag(cscalar); + } + + template ::value, typename = std::enable_if_t> + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const { + ComplexCoeffReturnType cscalar = BaseEvaluator::coeff(index / 2); + Index p = index & 1; + return reinterpret_cast(cscalar)[p]; + } + + constexpr EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) { + ComplexScalar& cscalar = BaseEvaluator::coeffRef(index / 2); + Index p = index & 1; + return reinterpret_cast(cscalar)[p]; + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packet(Index row, Index col) const { + constexpr int RealPacketSize = unpacket_traits::size; + using ComplexPacket = typename find_packet_by_size::type; + EIGEN_STATIC_ASSERT((find_packet_by_size::value), + MISSING COMPATIBLE COMPLEX PACKET TYPE) + eigen_assert(((IsRowMajor ? col : row) % 2 == 0) && "the inner index must be even"); + + Index crow = IsRowMajor ? row : row / 2; + Index ccol = IsRowMajor ? col / 2 : col; + ComplexPacket cpacket = BaseEvaluator::template packet(crow, ccol); + return preinterpret(cpacket); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packet(Index index) const { + constexpr int RealPacketSize = unpacket_traits::size; + using ComplexPacket = typename find_packet_by_size::type; + EIGEN_STATIC_ASSERT((find_packet_by_size::value), + MISSING COMPATIBLE COMPLEX PACKET TYPE) + eigen_assert((index % 2 == 0) && "the index must be even"); + + Index cindex = index / 2; + ComplexPacket cpacket = BaseEvaluator::template packet(cindex); + return preinterpret(cpacket); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packetSegment(Index row, Index col, Index begin, Index count) const { + constexpr int RealPacketSize = unpacket_traits::size; + using ComplexPacket = typename find_packet_by_size::type; + EIGEN_STATIC_ASSERT((find_packet_by_size::value), + MISSING COMPATIBLE COMPLEX PACKET TYPE) + eigen_assert(((IsRowMajor ? col : row) % 2 == 0) && "the inner index must be even"); + eigen_assert((begin % 2 == 0) && (count % 2 == 0) && "begin and count must be even"); + + Index crow = IsRowMajor ? row : row / 2; + Index ccol = IsRowMajor ? col / 2 : col; + Index cbegin = begin / 2; + Index ccount = count / 2; + ComplexPacket cpacket = BaseEvaluator::template packetSegment(crow, ccol, cbegin, ccount); + return preinterpret(cpacket); + } + + template + EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketType packetSegment(Index index, Index begin, Index count) const { + constexpr int RealPacketSize = unpacket_traits::size; + using ComplexPacket = typename find_packet_by_size::type; + EIGEN_STATIC_ASSERT((find_packet_by_size::value), + MISSING COMPATIBLE COMPLEX PACKET TYPE) + eigen_assert((index % 2 == 0) && "the index must be even"); + eigen_assert((begin % 2 == 0) && (count % 2 == 0) && "begin and count must be even"); + + Index cindex = index / 2; + Index cbegin = begin / 2; + Index ccount = count / 2; + ComplexPacket cpacket = BaseEvaluator::template packetSegment(cindex, cbegin, ccount); + return preinterpret(cpacket); + } +}; + +} // namespace internal + +template +class RealView : public internal::dense_xpr_base>::type { + using ExpressionTraits = internal::traits; + EIGEN_STATIC_ASSERT(NumTraits::IsComplex, SCALAR MUST BE COMPLEX) + public: + using Scalar = typename ExpressionTraits::Scalar; + using Nested = RealView; + + EIGEN_DEVICE_FUNC explicit RealView(Xpr& xpr) : m_xpr(xpr) {} + EIGEN_DEVICE_FUNC constexpr Index rows() const noexcept { return Xpr::IsRowMajor ? m_xpr.rows() : 2 * m_xpr.rows(); } + EIGEN_DEVICE_FUNC constexpr Index cols() const noexcept { return Xpr::IsRowMajor ? 2 * m_xpr.cols() : m_xpr.cols(); } + EIGEN_DEVICE_FUNC constexpr Index size() const noexcept { return 2 * m_xpr.size(); } + EIGEN_DEVICE_FUNC constexpr Index innerStride() const noexcept { return m_xpr.innerStride(); } + EIGEN_DEVICE_FUNC constexpr Index outerStride() const noexcept { return 2 * m_xpr.outerStride(); } + EIGEN_DEVICE_FUNC void resize(Index rows, Index cols) { + m_xpr.resize(Xpr::IsRowMajor ? rows : rows / 2, Xpr::IsRowMajor ? cols / 2 : cols); + } + EIGEN_DEVICE_FUNC void resize(Index size) { m_xpr.resize(size / 2); } + EIGEN_DEVICE_FUNC Scalar* data() { return reinterpret_cast(m_xpr.data()); } + EIGEN_DEVICE_FUNC const Scalar* data() const { return reinterpret_cast(m_xpr.data()); } + + EIGEN_DEVICE_FUNC RealView(const RealView&) = default; + + EIGEN_DEVICE_FUNC RealView& operator=(const RealView& other); + + template + EIGEN_DEVICE_FUNC RealView& operator=(const RealView& other); + + template + EIGEN_DEVICE_FUNC RealView& operator=(const DenseBase& other); + + protected: + friend struct internal::evaluator>; + Xpr& m_xpr; +}; + +template +EIGEN_DEVICE_FUNC RealView& RealView::operator=(const RealView& other) { + internal::call_assignment(*this, other); + return *this; +} + +template +template +EIGEN_DEVICE_FUNC RealView& RealView::operator=(const RealView& other) { + internal::call_assignment(*this, other); + return *this; +} + +template +template +EIGEN_DEVICE_FUNC RealView& RealView::operator=(const DenseBase& other) { + internal::call_assignment(*this, other.derived()); + return *this; +} + +template +EIGEN_DEVICE_FUNC typename DenseBase::RealViewReturnType DenseBase::realView() { + return RealViewReturnType(derived()); +} + +template +EIGEN_DEVICE_FUNC typename DenseBase::ConstRealViewReturnType DenseBase::realView() const { + return ConstRealViewReturnType(derived()); +} + +} // namespace Eigen + +#endif // EIGEN_REALVIEW_H diff --git a/Eigen/src/Core/Select.h b/Eigen/src/Core/Select.h index 0fa5f1e17..61a67c2f7 100644 --- a/Eigen/src/Core/Select.h +++ b/Eigen/src/Core/Select.h @@ -15,7 +15,7 @@ namespace Eigen { -/** \class Select +/** \typedef Select * \ingroup Core_Module * * \brief Expression of a coefficient wise version of the C++ ternary operator ?: @@ -24,73 +24,16 @@ namespace Eigen { * \tparam ThenMatrixType the type of the \em then expression * \tparam ElseMatrixType the type of the \em else expression * - * This class represents an expression of a coefficient wise version of the C++ ternary operator ?:. + * This type represents an expression of a coefficient wise version of the C++ ternary operator ?:. * It is the return type of DenseBase::select() and most of the time this is the only way it is used. * * \sa DenseBase::select(const DenseBase&, const DenseBase&) const */ - -namespace internal { template -struct traits > : traits { - typedef typename traits::Scalar Scalar; - typedef Dense StorageKind; - typedef typename traits::XprKind XprKind; - typedef typename ConditionMatrixType::Nested ConditionMatrixNested; - typedef typename ThenMatrixType::Nested ThenMatrixNested; - typedef typename ElseMatrixType::Nested ElseMatrixNested; - enum { - RowsAtCompileTime = ConditionMatrixType::RowsAtCompileTime, - ColsAtCompileTime = ConditionMatrixType::ColsAtCompileTime, - MaxRowsAtCompileTime = ConditionMatrixType::MaxRowsAtCompileTime, - MaxColsAtCompileTime = ConditionMatrixType::MaxColsAtCompileTime, - Flags = (unsigned int)ThenMatrixType::Flags & ElseMatrixType::Flags & RowMajorBit - }; -}; -} // namespace internal - -template -class Select : public internal::dense_xpr_base >::type, - internal::no_assignment_operator { - public: - typedef typename internal::dense_xpr_base