diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 8767e1f50..605a05e84 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -328,10 +328,10 @@ template class MatrixBase /////////// LU module /////////// - inline const FullPivLU fullPivLu() const; - inline const PartialPivLU partialPivLu() const; + template inline const FullPivLU fullPivLu() const; + template inline const PartialPivLU partialPivLu() const; - inline const PartialPivLU lu() const; + template inline const PartialPivLU lu() const; EIGEN_DEVICE_FUNC inline const Inverse inverse() const; diff --git a/Eigen/src/Core/util/ForwardDeclarations.h b/Eigen/src/Core/util/ForwardDeclarations.h index a00b14914..8963019a9 100644 --- a/Eigen/src/Core/util/ForwardDeclarations.h +++ b/Eigen/src/Core/util/ForwardDeclarations.h @@ -270,8 +270,8 @@ typedef lapack_int DefaultPermutationIndex; typedef int DefaultPermutationIndex; #endif -template class FullPivLU; -template class PartialPivLU; +template class FullPivLU; +template class PartialPivLU; namespace internal { template struct inverse_impl; } diff --git a/Eigen/src/LU/FullPivLU.h b/Eigen/src/LU/FullPivLU.h index 259b549b9..d02dcc10f 100644 --- a/Eigen/src/LU/FullPivLU.h +++ b/Eigen/src/LU/FullPivLU.h @@ -15,12 +15,12 @@ namespace Eigen { namespace internal { -template struct traits > +template struct traits > : traits { typedef MatrixXpr XprKind; typedef SolverStorage StorageKind; - typedef int StorageIndex; + typedef PermutationIndex_ StorageIndex; enum { Flags = 0 }; }; @@ -59,8 +59,8 @@ template struct traits > * * \sa MatrixBase::fullPivLu(), MatrixBase::determinant(), MatrixBase::inverse() */ -template class FullPivLU - : public SolverBase > +template class FullPivLU + : public SolverBase > { public: typedef MatrixType_ MatrixType; @@ -72,10 +72,11 @@ template class FullPivLU MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }; - typedef typename internal::plain_row_type::type IntRowVectorType; - typedef typename internal::plain_col_type::type IntColVectorType; - typedef PermutationMatrix PermutationQType; - typedef PermutationMatrix PermutationPType; + using PermutationIndex = PermutationIndex_; + typedef typename internal::plain_row_type::type IntRowVectorType; + typedef typename internal::plain_col_type::type IntColVectorType; + typedef PermutationMatrix PermutationQType; + typedef PermutationMatrix PermutationPType; typedef typename MatrixType::PlainObject PlainObject; /** @@ -437,14 +438,14 @@ template class FullPivLU bool m_isInitialized, m_usePrescribedThreshold; }; -template -FullPivLU::FullPivLU() +template +FullPivLU::FullPivLU() : m_isInitialized(false), m_usePrescribedThreshold(false) { } -template -FullPivLU::FullPivLU(Index rows, Index cols) +template +FullPivLU::FullPivLU(Index rows, Index cols) : m_lu(rows, cols), m_p(rows), m_q(cols), @@ -455,9 +456,9 @@ FullPivLU::FullPivLU(Index rows, Index cols) { } -template +template template -FullPivLU::FullPivLU(const EigenBase& matrix) +FullPivLU::FullPivLU(const EigenBase& matrix) : m_lu(matrix.rows(), matrix.cols()), m_p(matrix.rows()), m_q(matrix.cols()), @@ -469,9 +470,9 @@ FullPivLU::FullPivLU(const EigenBase& matrix) compute(matrix.derived()); } -template +template template -FullPivLU::FullPivLU(EigenBase& matrix) +FullPivLU::FullPivLU(EigenBase& matrix) : m_lu(matrix.derived()), m_p(matrix.rows()), m_q(matrix.cols()), @@ -483,11 +484,10 @@ FullPivLU::FullPivLU(EigenBase& matrix) computeInPlace(); } -template -void FullPivLU::computeInPlace() +template +void FullPivLU::computeInPlace() { - // the permutations are stored as int indices, so just to be sure: - eigen_assert(m_lu.rows()<=NumTraits::highest() && m_lu.cols()<=NumTraits::highest()); + eigen_assert(m_lu.rows()<=NumTraits::highest() && m_lu.cols()<=NumTraits::highest()); m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff(); @@ -574,8 +574,8 @@ void FullPivLU::computeInPlace() m_isInitialized = true; } -template -typename internal::traits::Scalar FullPivLU::determinant() const +template +typename internal::traits::Scalar FullPivLU::determinant() const { eigen_assert(m_isInitialized && "LU is not initialized."); eigen_assert(m_lu.rows() == m_lu.cols() && "You can't take the determinant of a non-square matrix!"); @@ -585,8 +585,8 @@ typename internal::traits::Scalar FullPivLU::determinant /** \returns the matrix represented by the decomposition, * i.e., it returns the product: \f$ P^{-1} L U Q^{-1} \f$. * This function is provided for debug purposes. */ -template -MatrixType FullPivLU::reconstructedMatrix() const +template +MatrixType FullPivLU::reconstructedMatrix() const { eigen_assert(m_isInitialized && "LU is not initialized."); const Index smalldim = (std::min)(m_lu.rows(), m_lu.cols()); @@ -610,11 +610,12 @@ MatrixType FullPivLU::reconstructedMatrix() const /********* Implementation of kernel() **************************************************/ namespace internal { -template -struct kernel_retval > - : kernel_retval_base > +template +struct kernel_retval > + : kernel_retval_base > { - EIGEN_MAKE_KERNEL_HELPERS(FullPivLU) + using DecompositionType = FullPivLU; + EIGEN_MAKE_KERNEL_HELPERS(DecompositionType) enum { MaxSmallDimAtCompileTime = min_size_prefer_fixed( MatrixType::MaxColsAtCompileTime, @@ -696,11 +697,12 @@ struct kernel_retval > /***** Implementation of image() *****************************************************/ -template -struct image_retval > - : image_retval_base > +template +struct image_retval > + : image_retval_base > { - EIGEN_MAKE_IMAGE_HELPERS(FullPivLU) + using DecompositionType = FullPivLU; + EIGEN_MAKE_IMAGE_HELPERS(DecompositionType) enum { MaxSmallDimAtCompileTime = min_size_prefer_fixed( MatrixType::MaxColsAtCompileTime, @@ -737,9 +739,9 @@ struct image_retval > } // end namespace internal #ifndef EIGEN_PARSED_BY_DOXYGEN -template +template template -void FullPivLU::_solve_impl(const RhsType &rhs, DstType &dst) const +void FullPivLU::_solve_impl(const RhsType &rhs, DstType &dst) const { /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}. * So we proceed as follows: @@ -784,9 +786,9 @@ void FullPivLU::_solve_impl(const RhsType &rhs, DstType &dst) const dst.row(permutationQ().indices().coeff(i)).setZero(); } -template +template template -void FullPivLU::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const +void FullPivLU::_solve_impl_transposed(const RhsType &rhs, DstType &dst) const { /* The decomposition PAQ = LU can be rewritten as A = P^{-1} L U Q^{-1}, * and since permutations are real and unitary, we can write this @@ -842,10 +844,10 @@ namespace internal { /***** Implementation of inverse() *****************************************************/ -template -struct Assignment >, internal::assign_op::Scalar>, Dense2Dense> +template +struct Assignment >, internal::assign_op::Scalar>, Dense2Dense> { - typedef FullPivLU LuType; + typedef FullPivLU LuType; typedef Inverse SrcXprType; static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op &) { @@ -863,10 +865,11 @@ struct Assignment >, internal::assign_ * \sa class FullPivLU */ template -inline const FullPivLU::PlainObject> +template +inline const FullPivLU::PlainObject, PermutationIndex> MatrixBase::fullPivLu() const { - return FullPivLU(eval()); + return FullPivLU(eval()); } } // end namespace Eigen diff --git a/Eigen/src/LU/PartialPivLU.h b/Eigen/src/LU/PartialPivLU.h index 137739892..bee743794 100644 --- a/Eigen/src/LU/PartialPivLU.h +++ b/Eigen/src/LU/PartialPivLU.h @@ -16,12 +16,12 @@ namespace Eigen { namespace internal { -template struct traits > +template struct traits > : traits { typedef MatrixXpr XprKind; typedef SolverStorage StorageKind; - typedef int StorageIndex; + typedef PermutationIndex_ StorageIndex; typedef traits BaseTraits; enum { Flags = BaseTraits::Flags & RowMajorBit, @@ -75,8 +75,8 @@ struct enable_if_ref,Derived> { * * \sa MatrixBase::partialPivLu(), MatrixBase::determinant(), MatrixBase::inverse(), MatrixBase::computeInverse(), class FullPivLU */ -template class PartialPivLU - : public SolverBase > +template class PartialPivLU + : public SolverBase > { public: @@ -89,8 +89,9 @@ template class PartialPivLU MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }; - typedef PermutationMatrix PermutationType; - typedef Transpositions TranspositionType; + using PermutationIndex = PermutationIndex_; + typedef PermutationMatrix PermutationType; + typedef Transpositions TranspositionType; typedef typename MatrixType::PlainObject PlainObject; /** @@ -279,8 +280,8 @@ template class PartialPivLU bool m_isInitialized; }; -template -PartialPivLU::PartialPivLU() +template +PartialPivLU::PartialPivLU() : m_lu(), m_p(), m_rowsTranspositions(), @@ -290,8 +291,8 @@ PartialPivLU::PartialPivLU() { } -template -PartialPivLU::PartialPivLU(Index size) +template +PartialPivLU::PartialPivLU(Index size) : m_lu(size, size), m_p(size), m_rowsTranspositions(size), @@ -301,9 +302,9 @@ PartialPivLU::PartialPivLU(Index size) { } -template +template template -PartialPivLU::PartialPivLU(const EigenBase& matrix) +PartialPivLU::PartialPivLU(const EigenBase& matrix) : m_lu(matrix.rows(),matrix.cols()), m_p(matrix.rows()), m_rowsTranspositions(matrix.rows()), @@ -314,9 +315,9 @@ PartialPivLU::PartialPivLU(const EigenBase& matrix) compute(matrix.derived()); } -template +template template -PartialPivLU::PartialPivLU(EigenBase& matrix) +PartialPivLU::PartialPivLU(EigenBase& matrix) : m_lu(matrix.derived()), m_p(matrix.rows()), m_rowsTranspositions(matrix.rows()), @@ -520,11 +521,10 @@ void partial_lu_inplace(MatrixType& lu, TranspositionType& row_transpositions, t } // end namespace internal -template -void PartialPivLU::compute() +template +void PartialPivLU::compute() { - // the row permutation is stored as int indices, so just to be sure: - eigen_assert(m_lu.rows()::highest()); + eigen_assert(m_lu.rows()::highest()); if(m_lu.cols()>0) m_l1_norm = m_lu.cwiseAbs().colwise().sum().maxCoeff(); @@ -545,8 +545,8 @@ void PartialPivLU::compute() m_isInitialized = true; } -template -typename PartialPivLU::Scalar PartialPivLU::determinant() const +template +typename PartialPivLU::Scalar PartialPivLU::determinant() const { eigen_assert(m_isInitialized && "PartialPivLU is not initialized."); return Scalar(m_det_p) * m_lu.diagonal().prod(); @@ -555,8 +555,8 @@ typename PartialPivLU::Scalar PartialPivLU::determinant( /** \returns the matrix represented by the decomposition, * i.e., it returns the product: P^{-1} L U. * This function is provided for debug purpose. */ -template -MatrixType PartialPivLU::reconstructedMatrix() const +template +MatrixType PartialPivLU::reconstructedMatrix() const { eigen_assert(m_isInitialized && "LU is not initialized."); // LU @@ -574,10 +574,10 @@ MatrixType PartialPivLU::reconstructedMatrix() const namespace internal { /***** Implementation of inverse() *****************************************************/ -template -struct Assignment >, internal::assign_op::Scalar>, Dense2Dense> +template +struct Assignment >, internal::assign_op::Scalar>, Dense2Dense> { - typedef PartialPivLU LuType; + typedef PartialPivLU LuType; typedef Inverse SrcXprType; static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op &) { @@ -595,10 +595,11 @@ struct Assignment >, internal::assi * \sa class PartialPivLU */ template -inline const PartialPivLU::PlainObject> +template +inline const PartialPivLU::PlainObject, PermutationIndex> MatrixBase::partialPivLu() const { - return PartialPivLU(eval()); + return PartialPivLU(eval()); } /** \lu_module @@ -610,10 +611,11 @@ MatrixBase::partialPivLu() const * \sa class PartialPivLU */ template -inline const PartialPivLU::PlainObject> +template +inline const PartialPivLU::PlainObject, PermutationIndex> MatrixBase::lu() const { - return PartialPivLU(eval()); + return PartialPivLU(eval()); } } // end namespace Eigen diff --git a/test/lu.cpp b/test/lu.cpp index 1bbadcbf0..3369f82a2 100644 --- a/test/lu.cpp +++ b/test/lu.cpp @@ -19,7 +19,6 @@ typename MatrixType::RealScalar matrix_l1_norm(const MatrixType& m) { template void lu_non_invertible() { - STATIC_CHECK(( internal::is_same::StorageIndex,int>::value )); typedef typename MatrixType::RealScalar RealScalar; /* this test covers the following files: @@ -163,8 +162,6 @@ template void lu_partial_piv(Index size = MatrixType::ColsA m1.setRandom(); PartialPivLU plu(m1); - STATIC_CHECK(( internal::is_same::StorageIndex,int>::value )); - VERIFY_IS_APPROX(m1, plu.reconstructedMatrix()); check_solverbase(m1, plu, size, size, size);