Skip to content
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_ORDERINGMETHODS_MODULE_H #ifndef EIGEN_ORDERINGMETHODS_MODULE_H
#define EIGEN_ORDERINGMETHODS_MODULE_H #define EIGEN_ORDERINGMETHODS_MODULE_H
......
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_PASTIXSUPPORT_MODULE_H #ifndef EIGEN_PASTIXSUPPORT_MODULE_H
#define EIGEN_PASTIXSUPPORT_MODULE_H #define EIGEN_PASTIXSUPPORT_MODULE_H
...@@ -5,7 +12,6 @@ ...@@ -5,7 +12,6 @@
#include "src/Core/util/DisableStupidWarnings.h" #include "src/Core/util/DisableStupidWarnings.h"
#include <complex.h>
extern "C" { extern "C" {
#include <pastix_nompi.h> #include <pastix_nompi.h>
#include <pastix.h> #include <pastix.h>
...@@ -35,12 +41,8 @@ extern "C" { ...@@ -35,12 +41,8 @@ extern "C" {
* *
*/ */
#include "src/misc/Solve.h"
#include "src/misc/SparseSolve.h"
#include "src/PaStiXSupport/PaStiXSupport.h" #include "src/PaStiXSupport/PaStiXSupport.h"
#include "src/Core/util/ReenableStupidWarnings.h" #include "src/Core/util/ReenableStupidWarnings.h"
#endif // EIGEN_PASTIXSUPPORT_MODULE_H #endif // EIGEN_PASTIXSUPPORT_MODULE_H
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_PARDISOSUPPORT_MODULE_H #ifndef EIGEN_PARDISOSUPPORT_MODULE_H
#define EIGEN_PARDISOSUPPORT_MODULE_H #define EIGEN_PARDISOSUPPORT_MODULE_H
...@@ -7,8 +14,6 @@ ...@@ -7,8 +14,6 @@
#include <mkl_pardiso.h> #include <mkl_pardiso.h>
#include <unsupported/Eigen/SparseExtra>
/** \ingroup Support_modules /** \ingroup Support_modules
* \defgroup PardisoSupport_Module PardisoSupport module * \defgroup PardisoSupport_Module PardisoSupport module
* *
......
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_QR_MODULE_H #ifndef EIGEN_QR_MODULE_H
#define EIGEN_QR_MODULE_H #define EIGEN_QR_MODULE_H
...@@ -15,31 +22,26 @@ ...@@ -15,31 +22,26 @@
* *
* This module provides various QR decompositions * This module provides various QR decompositions
* This module also provides some MatrixBase methods, including: * This module also provides some MatrixBase methods, including:
* - MatrixBase::qr(), * - MatrixBase::householderQr()
* - MatrixBase::colPivHouseholderQr()
* - MatrixBase::fullPivHouseholderQr()
* *
* \code * \code
* #include <Eigen/QR> * #include <Eigen/QR>
* \endcode * \endcode
*/ */
#include "src/misc/Solve.h"
#include "src/QR/HouseholderQR.h" #include "src/QR/HouseholderQR.h"
#include "src/QR/FullPivHouseholderQR.h" #include "src/QR/FullPivHouseholderQR.h"
#include "src/QR/ColPivHouseholderQR.h" #include "src/QR/ColPivHouseholderQR.h"
#include "src/QR/CompleteOrthogonalDecomposition.h"
#ifdef EIGEN_USE_LAPACKE #ifdef EIGEN_USE_LAPACKE
#include "src/QR/HouseholderQR_MKL.h" #include "src/misc/lapacke.h"
#include "src/QR/ColPivHouseholderQR_MKL.h" #include "src/QR/HouseholderQR_LAPACKE.h"
#endif #include "src/QR/ColPivHouseholderQR_LAPACKE.h"
#ifdef EIGEN2_SUPPORT
#include "src/Eigen2Support/QR.h"
#endif #endif
#include "src/Core/util/ReenableStupidWarnings.h" #include "src/Core/util/ReenableStupidWarnings.h"
#ifdef EIGEN2_SUPPORT
#include "Eigenvalues"
#endif
#endif // EIGEN_QR_MODULE_H #endif // EIGEN_QR_MODULE_H
/* vim: set filetype=cpp et sw=2 ts=2 ai: */ /* vim: set filetype=cpp et sw=2 ts=2 ai: */
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_QTMALLOC_MODULE_H #ifndef EIGEN_QTMALLOC_MODULE_H
#define EIGEN_QTMALLOC_MODULE_H #define EIGEN_QTMALLOC_MODULE_H
...@@ -8,7 +14,7 @@ ...@@ -8,7 +14,7 @@
#include "src/Core/util/DisableStupidWarnings.h" #include "src/Core/util/DisableStupidWarnings.h"
void *qMalloc(size_t size) void *qMalloc(std::size_t size)
{ {
return Eigen::internal::aligned_malloc(size); return Eigen::internal::aligned_malloc(size);
} }
...@@ -18,7 +24,7 @@ void qFree(void *ptr) ...@@ -18,7 +24,7 @@ void qFree(void *ptr)
Eigen::internal::aligned_free(ptr); Eigen::internal::aligned_free(ptr);
} }
void *qRealloc(void *ptr, size_t size) void *qRealloc(void *ptr, std::size_t size)
{ {
void* newPtr = Eigen::internal::aligned_malloc(size); void* newPtr = Eigen::internal::aligned_malloc(size);
memcpy(newPtr, ptr, size); memcpy(newPtr, ptr, size);
......
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_SPQRSUPPORT_MODULE_H #ifndef EIGEN_SPQRSUPPORT_MODULE_H
#define EIGEN_SPQRSUPPORT_MODULE_H #define EIGEN_SPQRSUPPORT_MODULE_H
...@@ -21,8 +28,6 @@ ...@@ -21,8 +28,6 @@
* *
*/ */
#include "src/misc/Solve.h"
#include "src/misc/SparseSolve.h"
#include "src/CholmodSupport/CholmodSupport.h" #include "src/CholmodSupport/CholmodSupport.h"
#include "src/SPQRSupport/SuiteSparseQRSupport.h" #include "src/SPQRSupport/SuiteSparseQRSupport.h"
......
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_SVD_MODULE_H #ifndef EIGEN_SVD_MODULE_H
#define EIGEN_SVD_MODULE_H #define EIGEN_SVD_MODULE_H
...@@ -12,23 +19,26 @@ ...@@ -12,23 +19,26 @@
* *
* *
* This module provides SVD decomposition for matrices (both real and complex). * This module provides SVD decomposition for matrices (both real and complex).
* This decomposition is accessible via the following MatrixBase method: * Two decomposition algorithms are provided:
* - JacobiSVD implementing two-sided Jacobi iterations is numerically very accurate, fast for small matrices, but very slow for larger ones.
* - BDCSVD implementing a recursive divide & conquer strategy on top of an upper-bidiagonalization which remains fast for large problems.
* These decompositions are accessible via the respective classes and following MatrixBase methods:
* - MatrixBase::jacobiSvd() * - MatrixBase::jacobiSvd()
* - MatrixBase::bdcSvd()
* *
* \code * \code
* #include <Eigen/SVD> * #include <Eigen/SVD>
* \endcode * \endcode
*/ */
#include "src/misc/Solve.h" #include "src/misc/RealSvd2x2.h"
#include "src/SVD/UpperBidiagonalization.h"
#include "src/SVD/SVDBase.h"
#include "src/SVD/JacobiSVD.h" #include "src/SVD/JacobiSVD.h"
#include "src/SVD/BDCSVD.h"
#if defined(EIGEN_USE_LAPACKE) && !defined(EIGEN_USE_LAPACKE_STRICT) #if defined(EIGEN_USE_LAPACKE) && !defined(EIGEN_USE_LAPACKE_STRICT)
#include "src/SVD/JacobiSVD_MKL.h" #include "src/misc/lapacke.h"
#endif #include "src/SVD/JacobiSVD_LAPACKE.h"
#include "src/SVD/UpperBidiagonalization.h"
#ifdef EIGEN2_SUPPORT
#include "src/Eigen2Support/SVD.h"
#endif #endif
#include "src/Core/util/ReenableStupidWarnings.h" #include "src/Core/util/ReenableStupidWarnings.h"
......
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_SPARSE_MODULE_H #ifndef EIGEN_SPARSE_MODULE_H
#define EIGEN_SPARSE_MODULE_H #define EIGEN_SPARSE_MODULE_H
...@@ -11,14 +18,16 @@ ...@@ -11,14 +18,16 @@
* - \ref SparseQR_Module * - \ref SparseQR_Module
* - \ref IterativeLinearSolvers_Module * - \ref IterativeLinearSolvers_Module
* *
* \code \code
* #include <Eigen/Sparse> #include <Eigen/Sparse>
* \endcode \endcode
*/ */
#include "SparseCore" #include "SparseCore"
#include "OrderingMethods" #include "OrderingMethods"
#ifndef EIGEN_MPL2_ONLY
#include "SparseCholesky" #include "SparseCholesky"
#endif
#include "SparseLU" #include "SparseLU"
#include "SparseQR" #include "SparseQR"
#include "IterativeLinearSolvers" #include "IterativeLinearSolvers"
......
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
#error The SparseCholesky module has nothing to offer in MPL2 only mode #error The SparseCholesky module has nothing to offer in MPL2 only mode
#endif #endif
#include "src/misc/Solve.h"
#include "src/misc/SparseSolve.h"
#include "src/SparseCholesky/SimplicialCholesky.h" #include "src/SparseCholesky/SimplicialCholesky.h"
#ifndef EIGEN_MPL2_ONLY #ifndef EIGEN_MPL2_ONLY
......
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_SPARSECORE_MODULE_H #ifndef EIGEN_SPARSECORE_MODULE_H
#define EIGEN_SPARSECORE_MODULE_H #define EIGEN_SPARSECORE_MODULE_H
...@@ -26,37 +33,35 @@ ...@@ -26,37 +33,35 @@
* This module depends on: Core. * This module depends on: Core.
*/ */
namespace Eigen {
/** The type used to identify a general sparse storage. */
struct Sparse {};
}
#include "src/SparseCore/SparseUtil.h" #include "src/SparseCore/SparseUtil.h"
#include "src/SparseCore/SparseMatrixBase.h" #include "src/SparseCore/SparseMatrixBase.h"
#include "src/SparseCore/SparseAssign.h"
#include "src/SparseCore/CompressedStorage.h" #include "src/SparseCore/CompressedStorage.h"
#include "src/SparseCore/AmbiVector.h" #include "src/SparseCore/AmbiVector.h"
#include "src/SparseCore/SparseCompressedBase.h"
#include "src/SparseCore/SparseMatrix.h" #include "src/SparseCore/SparseMatrix.h"
#include "src/SparseCore/SparseMap.h"
#include "src/SparseCore/MappedSparseMatrix.h" #include "src/SparseCore/MappedSparseMatrix.h"
#include "src/SparseCore/SparseVector.h" #include "src/SparseCore/SparseVector.h"
#include "src/SparseCore/SparseBlock.h" #include "src/SparseCore/SparseRef.h"
#include "src/SparseCore/SparseTranspose.h"
#include "src/SparseCore/SparseCwiseUnaryOp.h" #include "src/SparseCore/SparseCwiseUnaryOp.h"
#include "src/SparseCore/SparseCwiseBinaryOp.h" #include "src/SparseCore/SparseCwiseBinaryOp.h"
#include "src/SparseCore/SparseTranspose.h"
#include "src/SparseCore/SparseBlock.h"
#include "src/SparseCore/SparseDot.h" #include "src/SparseCore/SparseDot.h"
#include "src/SparseCore/SparsePermutation.h"
#include "src/SparseCore/SparseRedux.h" #include "src/SparseCore/SparseRedux.h"
#include "src/SparseCore/SparseFuzzy.h" #include "src/SparseCore/SparseView.h"
#include "src/SparseCore/SparseDiagonalProduct.h"
#include "src/SparseCore/ConservativeSparseSparseProduct.h" #include "src/SparseCore/ConservativeSparseSparseProduct.h"
#include "src/SparseCore/SparseSparseProductWithPruning.h" #include "src/SparseCore/SparseSparseProductWithPruning.h"
#include "src/SparseCore/SparseProduct.h" #include "src/SparseCore/SparseProduct.h"
#include "src/SparseCore/SparseDenseProduct.h" #include "src/SparseCore/SparseDenseProduct.h"
#include "src/SparseCore/SparseDiagonalProduct.h"
#include "src/SparseCore/SparseTriangularView.h"
#include "src/SparseCore/SparseSelfAdjointView.h" #include "src/SparseCore/SparseSelfAdjointView.h"
#include "src/SparseCore/SparseTriangularView.h"
#include "src/SparseCore/TriangularSolver.h" #include "src/SparseCore/TriangularSolver.h"
#include "src/SparseCore/SparseView.h" #include "src/SparseCore/SparsePermutation.h"
#include "src/SparseCore/SparseFuzzy.h"
#include "src/SparseCore/SparseSolverBase.h"
#include "src/Core/util/ReenableStupidWarnings.h" #include "src/Core/util/ReenableStupidWarnings.h"
......
...@@ -20,9 +20,6 @@ ...@@ -20,9 +20,6 @@
* Please, see the documentation of the SparseLU class for more details. * Please, see the documentation of the SparseLU class for more details.
*/ */
#include "src/misc/Solve.h"
#include "src/misc/SparseSolve.h"
// Ordering interface // Ordering interface
#include "OrderingMethods" #include "OrderingMethods"
......
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_SPARSEQR_MODULE_H #ifndef EIGEN_SPARSEQR_MODULE_H
#define EIGEN_SPARSEQR_MODULE_H #define EIGEN_SPARSEQR_MODULE_H
...@@ -21,9 +28,6 @@ ...@@ -21,9 +28,6 @@
* *
*/ */
#include "src/misc/Solve.h"
#include "src/misc/SparseSolve.h"
#include "OrderingMethods" #include "OrderingMethods"
#include "src/SparseCore/SparseColEtree.h" #include "src/SparseCore/SparseColEtree.h"
#include "src/SparseQR/SparseQR.h" #include "src/SparseQR/SparseQR.h"
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "Core" #include "Core"
#include <deque> #include <deque>
#if (defined(_MSC_VER) && defined(_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(...) #define EIGEN_DEFINE_STL_DEQUE_SPECIALIZATION(...)
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "Core" #include "Core"
#include <list> #include <list>
#if (defined(_MSC_VER) && defined(_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(...) #define EIGEN_DEFINE_STL_LIST_SPECIALIZATION(...)
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "Core" #include "Core"
#include <vector> #include <vector>
#if (defined(_MSC_VER) && defined(_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(...) #define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...)
......
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_SUPERLUSUPPORT_MODULE_H #ifndef EIGEN_SUPERLUSUPPORT_MODULE_H
#define EIGEN_SUPERLUSUPPORT_MODULE_H #define EIGEN_SUPERLUSUPPORT_MODULE_H
...@@ -36,6 +43,8 @@ namespace Eigen { struct SluMatrix; } ...@@ -36,6 +43,8 @@ namespace Eigen { struct SluMatrix; }
* - class SuperLU: a supernodal sequential LU factorization. * - class SuperLU: a supernodal sequential LU factorization.
* - class SuperILU: a supernodal sequential incomplete LU factorization (to be used as a preconditioner for iterative methods). * - class SuperILU: a supernodal sequential incomplete LU factorization (to be used as a preconditioner for iterative methods).
* *
* \warning This wrapper requires at least versions 4.0 of SuperLU. The 3.x versions are not supported.
*
* \warning When including this module, you have to use SUPERLU_EMPTY instead of EMPTY which is no longer defined because it is too polluting. * \warning When including this module, you have to use SUPERLU_EMPTY instead of EMPTY which is no longer defined because it is too polluting.
* *
* \code * \code
...@@ -48,12 +57,8 @@ namespace Eigen { struct SluMatrix; } ...@@ -48,12 +57,8 @@ namespace Eigen { struct SluMatrix; }
* *
*/ */
#include "src/misc/Solve.h"
#include "src/misc/SparseSolve.h"
#include "src/SuperLUSupport/SuperLUSupport.h" #include "src/SuperLUSupport/SuperLUSupport.h"
#include "src/Core/util/ReenableStupidWarnings.h" #include "src/Core/util/ReenableStupidWarnings.h"
#endif // EIGEN_SUPERLUSUPPORT_MODULE_H #endif // EIGEN_SUPERLUSUPPORT_MODULE_H
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// 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_UMFPACKSUPPORT_MODULE_H #ifndef EIGEN_UMFPACKSUPPORT_MODULE_H
#define EIGEN_UMFPACKSUPPORT_MODULE_H #define EIGEN_UMFPACKSUPPORT_MODULE_H
...@@ -26,9 +33,6 @@ extern "C" { ...@@ -26,9 +33,6 @@ extern "C" {
* *
*/ */
#include "src/misc/Solve.h"
#include "src/misc/SparseSolve.h"
#include "src/UmfPackSupport/UmfPackSupport.h" #include "src/UmfPackSupport/UmfPackSupport.h"
#include "src/Core/util/ReenableStupidWarnings.h" #include "src/Core/util/ReenableStupidWarnings.h"
......
file(GLOB Eigen_src_subdirectories "*")
escape_string_as_regex(ESCAPED_CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
foreach(f ${Eigen_src_subdirectories})
if(NOT f MATCHES "\\.txt" AND NOT f MATCHES "${ESCAPED_CMAKE_CURRENT_SOURCE_DIR}/[.].+" )
add_subdirectory(${f})
endif()
endforeach()
FILE(GLOB Eigen_Cholesky_SRCS "*.h")
INSTALL(FILES
${Eigen_Cholesky_SRCS}
DESTINATION ${INCLUDE_INSTALL_DIR}/Eigen/src/Cholesky COMPONENT Devel
)
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#ifndef EIGEN_LDLT_H #ifndef EIGEN_LDLT_H
#define EIGEN_LDLT_H #define EIGEN_LDLT_H
namespace Eigen { namespace Eigen {
namespace internal { namespace internal {
template<typename MatrixType, int UpLo> struct LDLT_Traits; template<typename MatrixType, int UpLo> struct LDLT_Traits;
...@@ -28,8 +28,8 @@ namespace internal { ...@@ -28,8 +28,8 @@ namespace internal {
* *
* \brief Robust Cholesky decomposition of a matrix with pivoting * \brief Robust Cholesky decomposition of a matrix with pivoting
* *
* \param MatrixType the type of the matrix of which to compute the LDL^T Cholesky decomposition * \tparam _MatrixType the type of the matrix of which to compute the LDL^T Cholesky decomposition
* \param UpLo the triangular part that will be used for the decompositon: Lower (default) or Upper. * \tparam _UpLo the triangular part that will be used for the decompositon: Lower (default) or Upper.
* The other triangular part won't be read. * The other triangular part won't be read.
* *
* Perform a robust Cholesky decomposition of a positive semidefinite or negative semidefinite * Perform a robust Cholesky decomposition of a positive semidefinite or negative semidefinite
...@@ -43,7 +43,9 @@ namespace internal { ...@@ -43,7 +43,9 @@ namespace internal {
* Remember that Cholesky decompositions are not rank-revealing. Also, do not use a Cholesky * Remember that Cholesky decompositions are not rank-revealing. Also, do not use a Cholesky
* decomposition to determine whether a system of equations has a solution. * decomposition to determine whether a system of equations has a solution.
* *
* \sa MatrixBase::ldlt(), class LLT * This class supports the \link InplaceDecomposition inplace decomposition \endlink mechanism.
*
* \sa MatrixBase::ldlt(), SelfAdjointView::ldlt(), class LLT
*/ */
template<typename _MatrixType, int _UpLo> class LDLT template<typename _MatrixType, int _UpLo> class LDLT
{ {
...@@ -52,15 +54,15 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -52,15 +54,15 @@ template<typename _MatrixType, int _UpLo> class LDLT
enum { enum {
RowsAtCompileTime = MatrixType::RowsAtCompileTime, RowsAtCompileTime = MatrixType::RowsAtCompileTime,
ColsAtCompileTime = MatrixType::ColsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime,
Options = MatrixType::Options & ~RowMajorBit, // these are the options for the TmpMatrixType, we need a ColMajor matrix here!
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
UpLo = _UpLo UpLo = _UpLo
}; };
typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Scalar Scalar;
typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar; typedef typename NumTraits<typename MatrixType::Scalar>::Real RealScalar;
typedef typename MatrixType::Index Index; typedef Eigen::Index Index; ///< \deprecated since Eigen 3.3
typedef Matrix<Scalar, RowsAtCompileTime, 1, Options, MaxRowsAtCompileTime, 1> TmpMatrixType; typedef typename MatrixType::StorageIndex StorageIndex;
typedef Matrix<Scalar, RowsAtCompileTime, 1, 0, MaxRowsAtCompileTime, 1> TmpMatrixType;
typedef Transpositions<RowsAtCompileTime, MaxRowsAtCompileTime> TranspositionType; typedef Transpositions<RowsAtCompileTime, MaxRowsAtCompileTime> TranspositionType;
typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType; typedef PermutationMatrix<RowsAtCompileTime, MaxRowsAtCompileTime> PermutationType;
...@@ -72,11 +74,11 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -72,11 +74,11 @@ template<typename _MatrixType, int _UpLo> class LDLT
* The default constructor is useful in cases in which the user intends to * The default constructor is useful in cases in which the user intends to
* perform decompositions via LDLT::compute(const MatrixType&). * perform decompositions via LDLT::compute(const MatrixType&).
*/ */
LDLT() LDLT()
: m_matrix(), : m_matrix(),
m_transpositions(), m_transpositions(),
m_sign(internal::ZeroSign), m_sign(internal::ZeroSign),
m_isInitialized(false) m_isInitialized(false)
{} {}
/** \brief Default Constructor with memory preallocation /** \brief Default Constructor with memory preallocation
...@@ -85,7 +87,7 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -85,7 +87,7 @@ template<typename _MatrixType, int _UpLo> class LDLT
* according to the specified problem \a size. * according to the specified problem \a size.
* \sa LDLT() * \sa LDLT()
*/ */
LDLT(Index size) explicit LDLT(Index size)
: m_matrix(size, size), : m_matrix(size, size),
m_transpositions(size), m_transpositions(size),
m_temporary(size), m_temporary(size),
...@@ -96,16 +98,35 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -96,16 +98,35 @@ template<typename _MatrixType, int _UpLo> class LDLT
/** \brief Constructor with decomposition /** \brief Constructor with decomposition
* *
* This calculates the decomposition for the input \a matrix. * This calculates the decomposition for the input \a matrix.
*
* \sa LDLT(Index size) * \sa LDLT(Index size)
*/ */
LDLT(const MatrixType& matrix) template<typename InputType>
explicit LDLT(const EigenBase<InputType>& matrix)
: m_matrix(matrix.rows(), matrix.cols()), : m_matrix(matrix.rows(), matrix.cols()),
m_transpositions(matrix.rows()), m_transpositions(matrix.rows()),
m_temporary(matrix.rows()), m_temporary(matrix.rows()),
m_sign(internal::ZeroSign), m_sign(internal::ZeroSign),
m_isInitialized(false) m_isInitialized(false)
{ {
compute(matrix); compute(matrix.derived());
}
/** \brief Constructs a LDLT factorization from a given matrix
*
* This overloaded constructor is provided for \link InplaceDecomposition inplace decomposition \endlink when \c MatrixType is a Eigen::Ref.
*
* \sa LDLT(const EigenBase&)
*/
template<typename InputType>
explicit LDLT(EigenBase<InputType>& matrix)
: m_matrix(matrix.derived()),
m_transpositions(matrix.rows()),
m_temporary(matrix.rows()),
m_sign(internal::ZeroSign),
m_isInitialized(false)
{
compute(matrix.derived());
} }
/** Clear any existing decomposition /** Clear any existing decomposition
...@@ -151,13 +172,6 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -151,13 +172,6 @@ template<typename _MatrixType, int _UpLo> class LDLT
eigen_assert(m_isInitialized && "LDLT is not initialized."); eigen_assert(m_isInitialized && "LDLT is not initialized.");
return m_sign == internal::PositiveSemiDef || m_sign == internal::ZeroSign; return m_sign == internal::PositiveSemiDef || m_sign == internal::ZeroSign;
} }
#ifdef EIGEN2_SUPPORT
inline bool isPositiveDefinite() const
{
return isPositive();
}
#endif
/** \returns true if the matrix is negative (semidefinite) */ /** \returns true if the matrix is negative (semidefinite) */
inline bool isNegative(void) const inline bool isNegative(void) const
...@@ -173,37 +187,38 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -173,37 +187,38 @@ template<typename _MatrixType, int _UpLo> class LDLT
* \note_about_checking_solutions * \note_about_checking_solutions
* *
* More precisely, this method solves \f$ A x = b \f$ using the decomposition \f$ A = P^T L D L^* P \f$ * More precisely, this method solves \f$ A x = b \f$ using the decomposition \f$ A = P^T L D L^* P \f$
* by solving the systems \f$ P^T y_1 = b \f$, \f$ L y_2 = y_1 \f$, \f$ D y_3 = y_2 \f$, * by solving the systems \f$ P^T y_1 = b \f$, \f$ L y_2 = y_1 \f$, \f$ D y_3 = y_2 \f$,
* \f$ L^* y_4 = y_3 \f$ and \f$ P x = y_4 \f$ in succession. If the matrix \f$ A \f$ is singular, then * \f$ L^* y_4 = y_3 \f$ and \f$ P x = y_4 \f$ in succession. If the matrix \f$ A \f$ is singular, then
* \f$ D \f$ will also be singular (all the other matrices are invertible). In that case, the * \f$ D \f$ will also be singular (all the other matrices are invertible). In that case, the
* least-square solution of \f$ D y_3 = y_2 \f$ is computed. This does not mean that this function * least-square solution of \f$ D y_3 = y_2 \f$ is computed. This does not mean that this function
* computes the least-square solution of \f$ A x = b \f$ is \f$ A \f$ is singular. * computes the least-square solution of \f$ A x = b \f$ is \f$ A \f$ is singular.
* *
* \sa MatrixBase::ldlt() * \sa MatrixBase::ldlt(), SelfAdjointView::ldlt()
*/ */
template<typename Rhs> template<typename Rhs>
inline const internal::solve_retval<LDLT, Rhs> inline const Solve<LDLT, Rhs>
solve(const MatrixBase<Rhs>& b) const solve(const MatrixBase<Rhs>& b) const
{ {
eigen_assert(m_isInitialized && "LDLT is not initialized."); eigen_assert(m_isInitialized && "LDLT is not initialized.");
eigen_assert(m_matrix.rows()==b.rows() eigen_assert(m_matrix.rows()==b.rows()
&& "LDLT::solve(): invalid number of rows of the right hand side matrix b"); && "LDLT::solve(): invalid number of rows of the right hand side matrix b");
return internal::solve_retval<LDLT, Rhs>(*this, b.derived()); return Solve<LDLT, Rhs>(*this, b.derived());
} }
#ifdef EIGEN2_SUPPORT
template<typename OtherDerived, typename ResultType>
bool solve(const MatrixBase<OtherDerived>& b, ResultType *result) const
{
*result = this->solve(b);
return true;
}
#endif
template<typename Derived> template<typename Derived>
bool solveInPlace(MatrixBase<Derived> &bAndX) const; bool solveInPlace(MatrixBase<Derived> &bAndX) const;
LDLT& compute(const MatrixType& matrix); template<typename InputType>
LDLT& compute(const EigenBase<InputType>& matrix);
/** \returns an estimate of the reciprocal condition number of the matrix of
* which \c *this is the LDLT decomposition.
*/
RealScalar rcond() const
{
eigen_assert(m_isInitialized && "LDLT is not initialized.");
return internal::rcond_estimate_helper(m_l1_norm, *this);
}
template <typename Derived> template <typename Derived>
LDLT& rankUpdate(const MatrixBase<Derived>& w, const RealScalar& alpha=1); LDLT& rankUpdate(const MatrixBase<Derived>& w, const RealScalar& alpha=1);
...@@ -220,6 +235,13 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -220,6 +235,13 @@ template<typename _MatrixType, int _UpLo> class LDLT
MatrixType reconstructedMatrix() const; MatrixType reconstructedMatrix() const;
/** \returns the adjoint of \c *this, that is, a const reference to the decomposition itself as the underlying matrix is self-adjoint.
*
* This method is provided for compatibility with other matrix decompositions, thus enabling generic code such as:
* \code x = decomposition.adjoint().solve(b) \endcode
*/
const LDLT& adjoint() const { return *this; };
inline Index rows() const { return m_matrix.rows(); } inline Index rows() const { return m_matrix.rows(); }
inline Index cols() const { return m_matrix.cols(); } inline Index cols() const { return m_matrix.cols(); }
...@@ -231,11 +253,17 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -231,11 +253,17 @@ template<typename _MatrixType, int _UpLo> class LDLT
ComputationInfo info() const ComputationInfo info() const
{ {
eigen_assert(m_isInitialized && "LDLT is not initialized."); eigen_assert(m_isInitialized && "LDLT is not initialized.");
return Success; return m_info;
} }
#ifndef EIGEN_PARSED_BY_DOXYGEN
template<typename RhsType, typename DstType>
EIGEN_DEVICE_FUNC
void _solve_impl(const RhsType &rhs, DstType &dst) const;
#endif
protected: protected:
static void check_template_parameters() static void check_template_parameters()
{ {
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar); EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar);
...@@ -248,10 +276,12 @@ template<typename _MatrixType, int _UpLo> class LDLT ...@@ -248,10 +276,12 @@ template<typename _MatrixType, int _UpLo> class LDLT
* is not stored), and the diagonal entries correspond to D. * is not stored), and the diagonal entries correspond to D.
*/ */
MatrixType m_matrix; MatrixType m_matrix;
RealScalar m_l1_norm;
TranspositionType m_transpositions; TranspositionType m_transpositions;
TmpMatrixType m_temporary; TmpMatrixType m_temporary;
internal::SignMatrix m_sign; internal::SignMatrix m_sign;
bool m_isInitialized; bool m_isInitialized;
ComputationInfo m_info;
}; };
namespace internal { namespace internal {
...@@ -266,15 +296,17 @@ template<> struct ldlt_inplace<Lower> ...@@ -266,15 +296,17 @@ template<> struct ldlt_inplace<Lower>
using std::abs; using std::abs;
typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::RealScalar RealScalar; typedef typename MatrixType::RealScalar RealScalar;
typedef typename MatrixType::Index Index; typedef typename TranspositionType::StorageIndex IndexType;
eigen_assert(mat.rows()==mat.cols()); eigen_assert(mat.rows()==mat.cols());
const Index size = mat.rows(); const Index size = mat.rows();
bool found_zero_pivot = false;
bool ret = true;
if (size <= 1) if (size <= 1)
{ {
transpositions.setIdentity(); transpositions.setIdentity();
if (numext::real(mat.coeff(0,0)) > 0) sign = PositiveSemiDef; if (numext::real(mat.coeff(0,0)) > static_cast<RealScalar>(0) ) sign = PositiveSemiDef;
else if (numext::real(mat.coeff(0,0)) < 0) sign = NegativeSemiDef; else if (numext::real(mat.coeff(0,0)) < static_cast<RealScalar>(0)) sign = NegativeSemiDef;
else sign = ZeroSign; else sign = ZeroSign;
return true; return true;
} }
...@@ -286,7 +318,7 @@ template<> struct ldlt_inplace<Lower> ...@@ -286,7 +318,7 @@ template<> struct ldlt_inplace<Lower>
mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner); mat.diagonal().tail(size-k).cwiseAbs().maxCoeff(&index_of_biggest_in_corner);
index_of_biggest_in_corner += k; index_of_biggest_in_corner += k;
transpositions.coeffRef(k) = index_of_biggest_in_corner; transpositions.coeffRef(k) = IndexType(index_of_biggest_in_corner);
if(k != index_of_biggest_in_corner) if(k != index_of_biggest_in_corner)
{ {
// apply the transposition while taking care to consider only // apply the transposition while taking care to consider only
...@@ -295,7 +327,7 @@ template<> struct ldlt_inplace<Lower> ...@@ -295,7 +327,7 @@ template<> struct ldlt_inplace<Lower>
mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k)); mat.row(k).head(k).swap(mat.row(index_of_biggest_in_corner).head(k));
mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s)); mat.col(k).tail(s).swap(mat.col(index_of_biggest_in_corner).tail(s));
std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner)); std::swap(mat.coeffRef(k,k),mat.coeffRef(index_of_biggest_in_corner,index_of_biggest_in_corner));
for(int i=k+1;i<index_of_biggest_in_corner;++i) for(Index i=k+1;i<index_of_biggest_in_corner;++i)
{ {
Scalar tmp = mat.coeffRef(i,k); Scalar tmp = mat.coeffRef(i,k);
mat.coeffRef(i,k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner,i)); mat.coeffRef(i,k) = numext::conj(mat.coeffRef(index_of_biggest_in_corner,i));
...@@ -321,26 +353,44 @@ template<> struct ldlt_inplace<Lower> ...@@ -321,26 +353,44 @@ template<> struct ldlt_inplace<Lower>
if(rs>0) if(rs>0)
A21.noalias() -= A20 * temp.head(k); A21.noalias() -= A20 * temp.head(k);
} }
// In some previous versions of Eigen (e.g., 3.2.1), the scaling was omitted if the pivot // In some previous versions of Eigen (e.g., 3.2.1), the scaling was omitted if the pivot
// was smaller than the cutoff value. However, soince LDLT is not rank-revealing // was smaller than the cutoff value. However, since LDLT is not rank-revealing
// we should only make sure we do not introduce INF or NaN values. // we should only make sure that we do not introduce INF or NaN values.
// LAPACK also uses 0 as the cutoff value. // Remark that LAPACK also uses 0 as the cutoff value.
RealScalar realAkk = numext::real(mat.coeffRef(k,k)); RealScalar realAkk = numext::real(mat.coeffRef(k,k));
if((rs>0) && (abs(realAkk) > RealScalar(0))) bool pivot_is_valid = (abs(realAkk) > RealScalar(0));
if(k==0 && !pivot_is_valid)
{
// The entire diagonal is zero, there is nothing more to do
// except filling the transpositions, and checking whether the matrix is zero.
sign = ZeroSign;
for(Index j = 0; j<size; ++j)
{
transpositions.coeffRef(j) = IndexType(j);
ret = ret && (mat.col(j).tail(size-j-1).array()==Scalar(0)).all();
}
return ret;
}
if((rs>0) && pivot_is_valid)
A21 /= realAkk; A21 /= realAkk;
if(found_zero_pivot && pivot_is_valid) ret = false; // factorization failed
else if(!pivot_is_valid) found_zero_pivot = true;
if (sign == PositiveSemiDef) { if (sign == PositiveSemiDef) {
if (realAkk < 0) sign = Indefinite; if (realAkk < static_cast<RealScalar>(0)) sign = Indefinite;
} else if (sign == NegativeSemiDef) { } else if (sign == NegativeSemiDef) {
if (realAkk > 0) sign = Indefinite; if (realAkk > static_cast<RealScalar>(0)) sign = Indefinite;
} else if (sign == ZeroSign) { } else if (sign == ZeroSign) {
if (realAkk > 0) sign = PositiveSemiDef; if (realAkk > static_cast<RealScalar>(0)) sign = PositiveSemiDef;
else if (realAkk < 0) sign = NegativeSemiDef; else if (realAkk < static_cast<RealScalar>(0)) sign = NegativeSemiDef;
} }
} }
return true; return ret;
} }
// Reference for the algorithm: Davis and Hager, "Multiple Rank // Reference for the algorithm: Davis and Hager, "Multiple Rank
...@@ -356,7 +406,6 @@ template<> struct ldlt_inplace<Lower> ...@@ -356,7 +406,6 @@ template<> struct ldlt_inplace<Lower>
using numext::isfinite; using numext::isfinite;
typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::Scalar Scalar;
typedef typename MatrixType::RealScalar RealScalar; typedef typename MatrixType::RealScalar RealScalar;
typedef typename MatrixType::Index Index;
const Index size = mat.rows(); const Index size = mat.rows();
eigen_assert(mat.cols() == size && w.size()==size); eigen_assert(mat.cols() == size && w.size()==size);
...@@ -420,16 +469,16 @@ template<typename MatrixType> struct LDLT_Traits<MatrixType,Lower> ...@@ -420,16 +469,16 @@ template<typename MatrixType> struct LDLT_Traits<MatrixType,Lower>
{ {
typedef const TriangularView<const MatrixType, UnitLower> MatrixL; typedef const TriangularView<const MatrixType, UnitLower> MatrixL;
typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitUpper> MatrixU; typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitUpper> MatrixU;
static inline MatrixL getL(const MatrixType& m) { return m; } static inline MatrixL getL(const MatrixType& m) { return MatrixL(m); }
static inline MatrixU getU(const MatrixType& m) { return m.adjoint(); } static inline MatrixU getU(const MatrixType& m) { return MatrixU(m.adjoint()); }
}; };
template<typename MatrixType> struct LDLT_Traits<MatrixType,Upper> template<typename MatrixType> struct LDLT_Traits<MatrixType,Upper>
{ {
typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitLower> MatrixL; typedef const TriangularView<const typename MatrixType::AdjointReturnType, UnitLower> MatrixL;
typedef const TriangularView<const MatrixType, UnitUpper> MatrixU; typedef const TriangularView<const MatrixType, UnitUpper> MatrixU;
static inline MatrixL getL(const MatrixType& m) { return m.adjoint(); } static inline MatrixL getL(const MatrixType& m) { return MatrixL(m.adjoint()); }
static inline MatrixU getU(const MatrixType& m) { return m; } static inline MatrixU getU(const MatrixType& m) { return MatrixU(m); }
}; };
} // end namespace internal } // end namespace internal
...@@ -437,21 +486,35 @@ template<typename MatrixType> struct LDLT_Traits<MatrixType,Upper> ...@@ -437,21 +486,35 @@ template<typename MatrixType> struct LDLT_Traits<MatrixType,Upper>
/** Compute / recompute the LDLT decomposition A = L D L^* = U^* D U of \a matrix /** Compute / recompute the LDLT decomposition A = L D L^* = U^* D U of \a matrix
*/ */
template<typename MatrixType, int _UpLo> template<typename MatrixType, int _UpLo>
LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::compute(const MatrixType& a) template<typename InputType>
LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::compute(const EigenBase<InputType>& a)
{ {
check_template_parameters(); check_template_parameters();
eigen_assert(a.rows()==a.cols()); eigen_assert(a.rows()==a.cols());
const Index size = a.rows(); const Index size = a.rows();
m_matrix = a; m_matrix = a.derived();
// Compute matrix L1 norm = max abs column sum.
m_l1_norm = RealScalar(0);
// TODO move this code to SelfAdjointView
for (Index col = 0; col < size; ++col) {
RealScalar abs_col_sum;
if (_UpLo == Lower)
abs_col_sum = m_matrix.col(col).tail(size - col).template lpNorm<1>() + m_matrix.row(col).head(col).template lpNorm<1>();
else
abs_col_sum = m_matrix.col(col).head(col).template lpNorm<1>() + m_matrix.row(col).tail(size - col).template lpNorm<1>();
if (abs_col_sum > m_l1_norm)
m_l1_norm = abs_col_sum;
}
m_transpositions.resize(size); m_transpositions.resize(size);
m_isInitialized = false; m_isInitialized = false;
m_temporary.resize(size); m_temporary.resize(size);
m_sign = internal::ZeroSign; m_sign = internal::ZeroSign;
internal::ldlt_inplace<UpLo>::unblocked(m_matrix, m_transpositions, m_temporary, m_sign); m_info = internal::ldlt_inplace<UpLo>::unblocked(m_matrix, m_transpositions, m_temporary, m_sign) ? Success : NumericalIssue;
m_isInitialized = true; m_isInitialized = true;
return *this; return *this;
...@@ -466,18 +529,19 @@ template<typename MatrixType, int _UpLo> ...@@ -466,18 +529,19 @@ template<typename MatrixType, int _UpLo>
template<typename Derived> template<typename Derived>
LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Derived>& w, const typename LDLT<MatrixType,_UpLo>::RealScalar& sigma) LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Derived>& w, const typename LDLT<MatrixType,_UpLo>::RealScalar& sigma)
{ {
typedef typename TranspositionType::StorageIndex IndexType;
const Index size = w.rows(); const Index size = w.rows();
if (m_isInitialized) if (m_isInitialized)
{ {
eigen_assert(m_matrix.rows()==size); eigen_assert(m_matrix.rows()==size);
} }
else else
{ {
m_matrix.resize(size,size); m_matrix.resize(size,size);
m_matrix.setZero(); m_matrix.setZero();
m_transpositions.resize(size); m_transpositions.resize(size);
for (Index i = 0; i < size; i++) for (Index i = 0; i < size; i++)
m_transpositions.coeffRef(i) = i; m_transpositions.coeffRef(i) = IndexType(i);
m_temporary.resize(size); m_temporary.resize(size);
m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef; m_sign = sigma>=0 ? internal::PositiveSemiDef : internal::NegativeSemiDef;
m_isInitialized = true; m_isInitialized = true;
...@@ -488,53 +552,45 @@ LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Deri ...@@ -488,53 +552,45 @@ LDLT<MatrixType,_UpLo>& LDLT<MatrixType,_UpLo>::rankUpdate(const MatrixBase<Deri
return *this; return *this;
} }
namespace internal { #ifndef EIGEN_PARSED_BY_DOXYGEN
template<typename _MatrixType, int _UpLo, typename Rhs> template<typename _MatrixType, int _UpLo>
struct solve_retval<LDLT<_MatrixType,_UpLo>, Rhs> template<typename RhsType, typename DstType>
: solve_retval_base<LDLT<_MatrixType,_UpLo>, Rhs> void LDLT<_MatrixType,_UpLo>::_solve_impl(const RhsType &rhs, DstType &dst) const
{ {
typedef LDLT<_MatrixType,_UpLo> LDLTType; eigen_assert(rhs.rows() == rows());
EIGEN_MAKE_SOLVE_HELPERS(LDLTType,Rhs) // dst = P b
dst = m_transpositions * rhs;
template<typename Dest> void evalTo(Dest& dst) const
// dst = L^-1 (P b)
matrixL().solveInPlace(dst);
// dst = D^-1 (L^-1 P b)
// more precisely, use pseudo-inverse of D (see bug 241)
using std::abs;
const typename Diagonal<const MatrixType>::RealReturnType vecD(vectorD());
// In some previous versions, tolerance was set to the max of 1/highest and the maximal diagonal entry * epsilon
// as motivated by LAPACK's xGELSS:
// RealScalar tolerance = numext::maxi(vecD.array().abs().maxCoeff() * NumTraits<RealScalar>::epsilon(),RealScalar(1) / NumTraits<RealScalar>::highest());
// However, LDLT is not rank revealing, and so adjusting the tolerance wrt to the highest
// diagonal element is not well justified and leads to numerical issues in some cases.
// Moreover, Lapack's xSYTRS routines use 0 for the tolerance.
RealScalar tolerance = RealScalar(1) / NumTraits<RealScalar>::highest();
for (Index i = 0; i < vecD.size(); ++i)
{ {
eigen_assert(rhs().rows() == dec().matrixLDLT().rows()); if(abs(vecD(i)) > tolerance)
// dst = P b dst.row(i) /= vecD(i);
dst = dec().transpositionsP() * rhs(); else
dst.row(i).setZero();
// dst = L^-1 (P b) }
dec().matrixL().solveInPlace(dst);
// dst = D^-1 (L^-1 P b)
// more precisely, use pseudo-inverse of D (see bug 241)
using std::abs;
using std::max;
typedef typename LDLTType::MatrixType MatrixType;
typedef typename LDLTType::RealScalar RealScalar;
const typename Diagonal<const MatrixType>::RealReturnType vectorD(dec().vectorD());
// In some previous versions, tolerance was set to the max of 1/highest and the maximal diagonal entry * epsilon
// as motivated by LAPACK's xGELSS:
// RealScalar tolerance = (max)(vectorD.array().abs().maxCoeff() *NumTraits<RealScalar>::epsilon(),RealScalar(1) / NumTraits<RealScalar>::highest());
// However, LDLT is not rank revealing, and so adjusting the tolerance wrt to the highest
// diagonal element is not well justified and to numerical issues in some cases.
// Moreover, Lapack's xSYTRS routines use 0 for the tolerance.
RealScalar tolerance = RealScalar(1) / NumTraits<RealScalar>::highest();
for (Index i = 0; i < vectorD.size(); ++i) {
if(abs(vectorD(i)) > tolerance)
dst.row(i) /= vectorD(i);
else
dst.row(i).setZero();
}
// dst = L^-T (D^-1 L^-1 P b) // dst = L^-T (D^-1 L^-1 P b)
dec().matrixU().solveInPlace(dst); matrixU().solveInPlace(dst);
// dst = P^-1 (L^-T D^-1 L^-1 P b) = A^-1 b // dst = P^-1 (L^-T D^-1 L^-1 P b) = A^-1 b
dst = dec().transpositionsP().transpose() * dst; dst = m_transpositions.transpose() * dst;
}
};
} }
#endif
/** \internal use x = ldlt_object.solve(x); /** \internal use x = ldlt_object.solve(x);
* *
...@@ -588,6 +644,7 @@ MatrixType LDLT<MatrixType,_UpLo>::reconstructedMatrix() const ...@@ -588,6 +644,7 @@ MatrixType LDLT<MatrixType,_UpLo>::reconstructedMatrix() const
/** \cholesky_module /** \cholesky_module
* \returns the Cholesky decomposition with full pivoting without square root of \c *this * \returns the Cholesky decomposition with full pivoting without square root of \c *this
* \sa MatrixBase::ldlt()
*/ */
template<typename MatrixType, unsigned int UpLo> template<typename MatrixType, unsigned int UpLo>
inline const LDLT<typename SelfAdjointView<MatrixType, UpLo>::PlainObject, UpLo> inline const LDLT<typename SelfAdjointView<MatrixType, UpLo>::PlainObject, UpLo>
...@@ -598,6 +655,7 @@ SelfAdjointView<MatrixType, UpLo>::ldlt() const ...@@ -598,6 +655,7 @@ SelfAdjointView<MatrixType, UpLo>::ldlt() const
/** \cholesky_module /** \cholesky_module
* \returns the Cholesky decomposition with full pivoting without square root of \c *this * \returns the Cholesky decomposition with full pivoting without square root of \c *this
* \sa SelfAdjointView::ldlt()
*/ */
template<typename Derived> template<typename Derived>
inline const LDLT<typename MatrixBase<Derived>::PlainObject> inline const LDLT<typename MatrixBase<Derived>::PlainObject>
......