From 6cc9dc17f2b016883260c00ff05c0a819e24bd24 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 26 Jan 2010 18:45:23 -0500 Subject: [PATCH] In LU / Inverse, decouple the output type from the input type. This has long been done in the default branch --- Eigen/src/Core/MatrixBase.h | 3 +- Eigen/src/LU/Inverse.h | 55 +++++++++++++++++++------------------ Eigen/src/LU/LU.h | 3 +- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index fd1b74735..de1b242a3 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -583,7 +583,8 @@ template class MatrixBase const LU lu() const; const PlainMatrixType inverse() const; - void computeInverse(PlainMatrixType *result) const; + template + void computeInverse(MatrixBase *result) const; Scalar determinant() const; /////////// Cholesky module /////////// diff --git a/Eigen/src/LU/Inverse.h b/Eigen/src/LU/Inverse.h index 98e7fc5d0..9e1c8cfa6 100644 --- a/Eigen/src/LU/Inverse.h +++ b/Eigen/src/LU/Inverse.h @@ -54,10 +54,10 @@ bool ei_compute_inverse_in_size2_case_with_check(const XprType& matrix, MatrixTy return true; } -template -void ei_compute_inverse_in_size3_case(const MatrixType& matrix, MatrixType* result) +template +void ei_compute_inverse_in_size3_case(const Derived& matrix, OtherDerived* result) { - typedef typename MatrixType::Scalar Scalar; + typedef typename Derived::Scalar Scalar; const Scalar det_minor00 = matrix.minor(0,0).determinant(); const Scalar det_minor10 = matrix.minor(1,0).determinant(); const Scalar det_minor20 = matrix.minor(2,0).determinant(); @@ -75,10 +75,10 @@ void ei_compute_inverse_in_size3_case(const MatrixType& matrix, MatrixType* resu result->coeffRef(2, 2) = matrix.minor(2,2).determinant() * invdet; } -template +template struct ei_compute_inverse_in_size4_case { - static void run(const MatrixType& matrix, MatrixType& result) + static void run(const Derived& matrix, OtherDerived& result) { result.coeffRef(0,0) = matrix.minor(0,0).determinant(); result.coeffRef(1,0) = -matrix.minor(0,1).determinant(); @@ -109,10 +109,10 @@ struct ei_compute_inverse_in_size4_case // here that if Intel makes this document publically available, with source code // and detailed explanations, it's because they want their CPUs to be fed with // good code, and therefore they presumably don't mind us using it in Eigen. -template -struct ei_compute_inverse_in_size4_case +template +struct ei_compute_inverse_in_size4_case { - static void run(const MatrixType& matrix, MatrixType& result) + static void run(const Derived& matrix, OtherDerived& result) { // Variables (Streaming SIMD Extensions registers) which will contain cofactors and, later, the // lines of the inverted matrix. @@ -229,50 +229,50 @@ struct ei_compute_inverse_in_size4_case *** Part 2 : selector and MatrixBase methods *** ***********************************************/ -template +template struct ei_compute_inverse { - static inline void run(const MatrixType& matrix, MatrixType* result) + static inline void run(const Derived& matrix, OtherDerived* result) { - LU lu(matrix); + LU lu(matrix); lu.computeInverse(result); } }; -template -struct ei_compute_inverse +template +struct ei_compute_inverse { - static inline void run(const MatrixType& matrix, MatrixType* result) + static inline void run(const Derived& matrix, OtherDerived* result) { - typedef typename MatrixType::Scalar Scalar; + typedef typename Derived::Scalar Scalar; result->coeffRef(0,0) = Scalar(1) / matrix.coeff(0,0); } }; -template -struct ei_compute_inverse +template +struct ei_compute_inverse { - static inline void run(const MatrixType& matrix, MatrixType* result) + static inline void run(const Derived& matrix, OtherDerived* result) { ei_compute_inverse_in_size2_case(matrix, result); } }; -template -struct ei_compute_inverse +template +struct ei_compute_inverse { - static inline void run(const MatrixType& matrix, MatrixType* result) + static inline void run(const Derived& matrix, OtherDerived* result) { ei_compute_inverse_in_size3_case(matrix, result); } }; -template -struct ei_compute_inverse +template +struct ei_compute_inverse { - static inline void run(const MatrixType& matrix, MatrixType* result) + static inline void run(const Derived& matrix, OtherDerived* result) { - ei_compute_inverse_in_size4_case::run(matrix, *result); + ei_compute_inverse_in_size4_case::run(matrix, *result); } }; @@ -290,11 +290,12 @@ struct ei_compute_inverse * \sa inverse() */ template -inline void MatrixBase::computeInverse(PlainMatrixType *result) const +template +inline void MatrixBase::computeInverse(MatrixBase *result) const { ei_assert(rows() == cols()); EIGEN_STATIC_ASSERT(NumTraits::HasFloatingPoint,NUMERIC_TYPE_MUST_BE_FLOATING_POINT) - ei_compute_inverse::run(eval(), result); + ei_compute_inverse::run(eval(), static_cast(result)); } /** \lu_module diff --git a/Eigen/src/LU/LU.h b/Eigen/src/LU/LU.h index 176e76a91..36ee886d4 100644 --- a/Eigen/src/LU/LU.h +++ b/Eigen/src/LU/LU.h @@ -297,7 +297,8 @@ template class LU * * \sa MatrixBase::computeInverse(), inverse() */ - inline void computeInverse(MatrixType *result) const + template + inline void computeInverse(ResultType *result) const { solve(MatrixType::Identity(m_lu.rows(), m_lu.cols()), result); }