From 70c0174bf9cb0a7dd22c47e377f9b9efc22ba4c9 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 23 Mar 2009 14:44:44 +0000 Subject: [PATCH] * allows fixed size matrix with size==0 (via a specialization of MatrixStorage returning a null pointer). For instance this is very useful to make Tridiagonalization compile for 1x1 matrices * fix LLT and eigensolver for 1x1 matrix --- Eigen/src/Cholesky/LLT.h | 2 ++ Eigen/src/Core/Block.h | 4 ++-- Eigen/src/Core/Matrix.h | 8 +++----- Eigen/src/Core/MatrixStorage.h | 15 +++++++++++++++ Eigen/src/QR/SelfAdjointEigenSolver.h | 8 ++++++++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Eigen/src/Cholesky/LLT.h b/Eigen/src/Cholesky/LLT.h index e02b82551..66b86a204 100644 --- a/Eigen/src/Cholesky/LLT.h +++ b/Eigen/src/Cholesky/LLT.h @@ -103,6 +103,8 @@ void LLT::compute(const MatrixType& a) x = ei_real(a.coeff(0,0)); m_isPositiveDefinite = x > eps && ei_isMuchSmallerThan(ei_imag(a.coeff(0,0)), RealScalar(1)); m_matrix.coeffRef(0,0) = ei_sqrt(x); + if(size==1) + return; m_matrix.col(0).end(size-1) = a.row(0).end(size-1).adjoint() / ei_real(m_matrix.coeff(0,0)); for (int j = 1; j < size; ++j) { diff --git a/Eigen/src/Core/Block.h b/Eigen/src/Core/Block.h index 195533266..2473864d3 100644 --- a/Eigen/src/Core/Block.h +++ b/Eigen/src/Core/Block.h @@ -68,8 +68,8 @@ struct ei_traits::type _MatrixTypeNested; enum{ - RowsAtCompileTime = MatrixType::RowsAtCompileTime == 1 ? 1 : BlockRows, - ColsAtCompileTime = MatrixType::ColsAtCompileTime == 1 ? 1 : BlockCols, + RowsAtCompileTime = BlockRows, + ColsAtCompileTime = BlockCols, MaxRowsAtCompileTime = RowsAtCompileTime == 1 ? 1 : (BlockRows==Dynamic ? MatrixType::MaxRowsAtCompileTime : BlockRows), MaxColsAtCompileTime = ColsAtCompileTime == 1 ? 1 diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index fbd55e526..99f89356d 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -534,11 +534,9 @@ class Matrix static EIGEN_STRONG_INLINE void _check_template_params() { - EIGEN_STATIC_ASSERT((_Rows > 0 - && _Cols > 0 - && _MaxRows <= _Rows - && _MaxCols <= _Cols - && (_Options & (AutoAlign|RowMajor)) == _Options), + EIGEN_STATIC_ASSERT(((_MaxRows >= _Rows || _Rows==Dynamic) + && (_MaxCols >= _Cols || _Cols==Dynamic) + && (_Options & (AutoAlign|RowMajor)) == _Options), INVALID_MATRIX_TEMPLATE_PARAMETERS) } }; diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h index ba2355b8e..e3ddec433 100644 --- a/Eigen/src/Core/MatrixStorage.h +++ b/Eigen/src/Core/MatrixStorage.h @@ -85,6 +85,21 @@ template class ei_matr inline T *data() { return m_data.array; } }; +// null matrix +template class ei_matrix_storage +{ + public: + inline explicit ei_matrix_storage() {} + inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) {} + inline ei_matrix_storage(int,int,int) {} + inline void swap(ei_matrix_storage& other) {} + inline static int rows(void) {return _Rows;} + inline static int cols(void) {return _Cols;} + inline void resize(int,int,int) {} + inline const T *data() const { return 0; } + inline T *data() { return 0; } +}; + // dynamic-size matrix with fixed-size storage template class ei_matrix_storage { diff --git a/Eigen/src/QR/SelfAdjointEigenSolver.h b/Eigen/src/QR/SelfAdjointEigenSolver.h index 1c9ad513d..6d3bdf005 100644 --- a/Eigen/src/QR/SelfAdjointEigenSolver.h +++ b/Eigen/src/QR/SelfAdjointEigenSolver.h @@ -189,6 +189,14 @@ void SelfAdjointEigenSolver::compute(const MatrixType& matrix, bool assert(matrix.cols() == matrix.rows()); int n = matrix.cols(); m_eivalues.resize(n,1); + + if(n==1) + { + m_eivalues.coeffRef(0,0) = ei_real(matrix.coeff(0,0)); + m_eivec.setOnes(); + return; + } + m_eivec = matrix; // FIXME, should tridiag be a local variable of this function or an attribute of SelfAdjointEigenSolver ?