diff --git a/Eigen/Core b/Eigen/Core index 67d55fee3..1f71dfdb5 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -23,10 +23,6 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . -#ifdef EIGEN2_SUPPORT -#include "Eigen2Support" -#endif - #ifndef EIGEN_CORE_H #define EIGEN_CORE_H @@ -225,5 +221,9 @@ struct Dense {}; #include "src/Core/util/EnableMSVCWarnings.h" +#ifdef EIGEN2_SUPPORT +#include "Eigen2Support" +#endif + #endif // EIGEN_CORE_H /* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/Eigen/Eigen2Support b/Eigen/Eigen2Support index b95b51dec..ccba4ff30 100644 --- a/Eigen/Eigen2Support +++ b/Eigen/Eigen2Support @@ -25,14 +25,13 @@ #ifndef EIGEN2SUPPORT_H #define EIGEN2SUPPORT_H -#include "src/Core/util/DisableMSVCWarnings.h" +#include "Array" -#ifndef EIGEN2_SUPPORT -#define EIGEN2_SUPPORT +#if (!defined(EIGEN2_SUPPORT)) || (!defined(EIGEN_CORE_H)) +#error Eigen2 support must be enabled by defining EIGEN2_SUPPORT before any other Eigen header #endif -#include "Core" -#include "Array" +#include "src/Core/util/DisableMSVCWarnings.h" namespace Eigen { @@ -40,8 +39,9 @@ namespace Eigen { * This module provides a couple of deprecated functions improving the compatibility with Eigen2. * * \code - * #include + * #define EIGEN2_SUPPORT * \endcode + * */ #include "src/Eigen2Support/Flagged.h" diff --git a/Eigen/src/Array/Reverse.h b/Eigen/src/Array/Reverse.h index a8d8310a9..7d2c34816 100644 --- a/Eigen/src/Array/Reverse.h +++ b/Eigen/src/Array/Reverse.h @@ -59,9 +59,7 @@ struct ei_traits > LinearAccess = ( (Direction==BothDirections) && (int(_MatrixTypeNested::Flags)&PacketAccessBit) ) ? LinearAccessBit : 0, - Flags = (int(_MatrixTypeNested::Flags) & (HereditaryBits | PacketAccessBit | LinearAccess)) - | (int(_MatrixTypeNested::Flags)&UpperTriangularBit ? LowerTriangularBit : 0) - | (int(_MatrixTypeNested::Flags)&LowerTriangularBit ? UpperTriangularBit : 0), + Flags = (int(_MatrixTypeNested::Flags) & (HereditaryBits | PacketAccessBit | LinearAccess)), CoeffReadCost = _MatrixTypeNested::CoeffReadCost }; diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index 4fb6d3d2c..8b13d8e2e 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -80,7 +80,7 @@ template class LDLT } /** \returns the lower triangular matrix L */ - inline TriangularView matrixL(void) const + inline TriangularView matrixL(void) const { ei_assert(m_isInitialized && "LDLT is not initialized."); return m_matrix; @@ -301,13 +301,13 @@ bool LDLT::solveInPlace(MatrixBase &bAndX) const // y = L^-1 z //matrixL().solveInPlace(bAndX); - m_matrix.template triangularView().solveInPlace(bAndX); + m_matrix.template triangularView().solveInPlace(bAndX); // w = D^-1 y bAndX = m_matrix.diagonal().asDiagonal().inverse() * bAndX; // u = L^-T w - m_matrix.adjoint().template triangularView().solveInPlace(bAndX); + m_matrix.adjoint().template triangularView().solveInPlace(bAndX); // x = P^T u for (int i = size-1; i >= 0; --i) bAndX.row(m_transpositions.coeff(i)).swap(bAndX.row(i)); diff --git a/Eigen/src/Cholesky/LLT.h b/Eigen/src/Cholesky/LLT.h index 02645b23f..8a149a316 100644 --- a/Eigen/src/Cholesky/LLT.h +++ b/Eigen/src/Cholesky/LLT.h @@ -148,7 +148,7 @@ template class LLT // forward declaration (defined at the end of this file) template struct ei_llt_inplace; -template<> struct ei_llt_inplace +template<> struct ei_llt_inplace { template static bool unblocked(MatrixType& mat) @@ -198,47 +198,47 @@ template<> struct ei_llt_inplace Block A22(m,k+bs,k+bs,rs,rs); if(!unblocked(A11)) return false; - if(rs>0) A11.adjoint().template triangularView().template solveInPlace(A21); - if(rs>0) A22.template selfadjointView().rankUpdate(A21,-1); // bottleneck + if(rs>0) A11.adjoint().template triangularView().template solveInPlace(A21); + if(rs>0) A22.template selfadjointView().rankUpdate(A21,-1); // bottleneck } return true; } }; -template<> struct ei_llt_inplace +template<> struct ei_llt_inplace { template static EIGEN_STRONG_INLINE bool unblocked(MatrixType& mat) { Transpose matt(mat); - return ei_llt_inplace::unblocked(matt); + return ei_llt_inplace::unblocked(matt); } template static EIGEN_STRONG_INLINE bool blocked(MatrixType& mat) { Transpose matt(mat); - return ei_llt_inplace::blocked(matt); + return ei_llt_inplace::blocked(matt); } }; -template struct LLT_Traits +template struct LLT_Traits { - typedef TriangularView MatrixL; - typedef TriangularView MatrixU; + typedef TriangularView MatrixL; + typedef TriangularView MatrixU; inline static MatrixL getL(const MatrixType& m) { return m; } inline static MatrixU getU(const MatrixType& m) { return m.adjoint(); } static bool inplace_decomposition(MatrixType& m) - { return ei_llt_inplace::blocked(m); } + { return ei_llt_inplace::blocked(m); } }; -template struct LLT_Traits +template struct LLT_Traits { - typedef TriangularView MatrixL; - typedef TriangularView MatrixU; + typedef TriangularView MatrixL; + typedef TriangularView MatrixU; inline static MatrixL getL(const MatrixType& m) { return m.adjoint(); } inline static MatrixU getU(const MatrixType& m) { return m; } static bool inplace_decomposition(MatrixType& m) - { return ei_llt_inplace::blocked(m); } + { return ei_llt_inplace::blocked(m); } }; /** Computes / recomputes the Cholesky decomposition A = LL^* = U^*U of \a matrix diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 4c30f30ad..7569dab58 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -405,13 +405,6 @@ template class MatrixBase template const VectorBlock start() const; template VectorBlock end(); template const VectorBlock end() const; - - template - typename ei_plain_matrix_type_column_major::type - solveTriangular(const MatrixBase& other) const; - - template - void solveTriangularInPlace(const MatrixBase& other) const; #endif protected: diff --git a/Eigen/src/Core/SelfAdjointView.h b/Eigen/src/Core/SelfAdjointView.h index 9ab8cb2c1..6d01ee495 100644 --- a/Eigen/src/Core/SelfAdjointView.h +++ b/Eigen/src/Core/SelfAdjointView.h @@ -31,7 +31,7 @@ * \brief Expression of a selfadjoint matrix from a triangular part of a dense matrix * * \param MatrixType the type of the dense matrix storing the coefficients - * \param TriangularPart can be either \c LowerTriangular or \c UpperTriangular + * \param TriangularPart can be either \c Lower or \c Upper * * This class is an expression of a sefladjoint matrix from a triangular part of a matrix * with given dense storage of the coefficients. It is the return type of MatrixBase::selfadjointView() @@ -46,7 +46,7 @@ struct ei_traits > : ei_traits::type _MatrixTypeNested; typedef MatrixType ExpressionType; enum { - Mode = TriangularPart | SelfAdjointBit, + Mode = TriangularPart | SelfAdjoint, Flags = _MatrixTypeNested::Flags & (HereditaryBits) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)), // FIXME these flags should be preserved CoeffReadCost = _MatrixTypeNested::CoeffReadCost diff --git a/Eigen/src/Core/SolveTriangular.h b/Eigen/src/Core/SolveTriangular.h index 9dc019d17..73cf77387 100644 --- a/Eigen/src/Core/SolveTriangular.h +++ b/Eigen/src/Core/SolveTriangular.h @@ -57,7 +57,7 @@ struct ei_triangular_solver_selector LhsProductTraits; typedef typename LhsProductTraits::ExtractType ActualLhsType; enum { - IsLowerTriangular = ((Mode&LowerTriangularBit)==LowerTriangularBit) + IsLower = ((Mode&Lower)==Lower) }; static void run(const Lhs& lhs, Rhs& other) { @@ -65,20 +65,20 @@ struct ei_triangular_solver_selector0; - IsLowerTriangular ? pi+=PanelWidth : pi-=PanelWidth) + for(int pi=IsLower ? 0 : size; + IsLower ? pi0; + IsLower ? pi+=PanelWidth : pi-=PanelWidth) { - int actualPanelWidth = std::min(IsLowerTriangular ? size - pi : pi, PanelWidth); + int actualPanelWidth = std::min(IsLower ? size - pi : pi, PanelWidth); - int r = IsLowerTriangular ? pi : size - pi; // remaining size + int r = IsLower ? pi : size - pi; // remaining size if (r > 0) { // let's directly call the low level product function because: // 1 - it is faster to compile // 2 - it is slighlty faster at runtime - int startRow = IsLowerTriangular ? pi : pi-actualPanelWidth; - int startCol = IsLowerTriangular ? 0 : pi; + int startRow = IsLower ? pi : pi-actualPanelWidth; + int startCol = IsLower ? 0 : pi; VectorBlock target(other,startRow,actualPanelWidth); ei_cache_friendly_product_rowmajor_times_vector( @@ -89,12 +89,12 @@ struct ei_triangular_solver_selector0) other.coeffRef(i) -= (lhs.row(i).segment(s,k).transpose().cwiseProduct(other.segment(s,k))).sum(); - if(!(Mode & UnitDiagBit)) + if(!(Mode & UnitDiag)) other.coeffRef(i) /= lhs.coeff(i,i); } } @@ -111,7 +111,7 @@ struct ei_triangular_solver_selector::size, - IsLowerTriangular = ((Mode&LowerTriangularBit)==LowerTriangularBit) + IsLower = ((Mode&Lower)==Lower) }; static void run(const Lhs& lhs, Rhs& other) @@ -120,26 +120,26 @@ struct ei_triangular_solver_selector0; - IsLowerTriangular ? pi+=PanelWidth : pi-=PanelWidth) + for(int pi=IsLower ? 0 : size; + IsLower ? pi0; + IsLower ? pi+=PanelWidth : pi-=PanelWidth) { - int actualPanelWidth = std::min(IsLowerTriangular ? size - pi : pi, PanelWidth); - int startBlock = IsLowerTriangular ? pi : pi-actualPanelWidth; - int endBlock = IsLowerTriangular ? pi + actualPanelWidth : 0; + int actualPanelWidth = std::min(IsLower ? size - pi : pi, PanelWidth); + int startBlock = IsLower ? pi : pi-actualPanelWidth; + int endBlock = IsLower ? pi + actualPanelWidth : 0; for(int k=0; k0) other.segment(s,r) -= other.coeffRef(i) * Block(lhs, s, i, r, 1); } - int r = IsLowerTriangular ? size - endBlock : startBlock; // remaining size + int r = IsLower ? size - endBlock : startBlock; // remaining size if (r > 0) { // let's directly call the low level product function because: @@ -198,16 +198,16 @@ struct ei_triangular_solver_unroller; template struct ei_triangular_solver_unroller { enum { - IsLowerTriangular = ((Mode&LowerTriangularBit)==LowerTriangularBit), - I = IsLowerTriangular ? Index : Size - Index - 1, - S = IsLowerTriangular ? 0 : I+1 + IsLower = ((Mode&Lower)==Lower), + I = IsLower ? Index : Size - Index - 1, + S = IsLower ? 0 : I+1 }; static void run(const Lhs& lhs, Rhs& rhs) { if (Index>0) rhs.coeffRef(I) -= ((lhs.row(I).template segment(S).transpose()).cwiseProduct(rhs.template segment(S))).sum(); - if(!(Mode & UnitDiagBit)) + if(!(Mode & UnitDiag)) rhs.coeffRef(I) /= lhs.coeff(I,I); ei_triangular_solver_unroller::run(lhs,rhs); @@ -245,8 +245,8 @@ void TriangularView::solveInPlace(const MatrixBase::Flags & RowMajorBit && OtherDerived::IsVectorAtCompileTime }; typedef typename ei_meta_if > : ei_traits ColsAtCompileTime = MatrixType::RowsAtCompileTime, MaxRowsAtCompileTime = MatrixType::MaxColsAtCompileTime, MaxColsAtCompileTime = MatrixType::MaxRowsAtCompileTime, - Flags = ((int(_MatrixTypeNested::Flags) ^ RowMajorBit) - & ~(LowerTriangularBit | UpperTriangularBit)) - | (int(_MatrixTypeNested::Flags)&UpperTriangularBit ? LowerTriangularBit : 0) - | (int(_MatrixTypeNested::Flags)&LowerTriangularBit ? UpperTriangularBit : 0), + Flags = (int(_MatrixTypeNested::Flags) ^ RowMajorBit), CoeffReadCost = _MatrixTypeNested::CoeffReadCost }; }; @@ -229,7 +226,7 @@ struct ei_inplace_transpose_selector; template struct ei_inplace_transpose_selector { // square matrix static void run(MatrixType& m) { - m.template triangularView().swap(m.transpose()); + m.template triangularView().swap(m.transpose()); } }; @@ -237,7 +234,7 @@ template struct ei_inplace_transpose_selector { // non square matrix static void run(MatrixType& m) { if (m.rows()==m.cols()) - m.template triangularView().swap(m.transpose()); + m.template triangularView().swap(m.transpose()); else m = m.transpose().eval(); } diff --git a/Eigen/src/Core/TriangularMatrix.h b/Eigen/src/Core/TriangularMatrix.h index 62d800fef..8411b0546 100644 --- a/Eigen/src/Core/TriangularMatrix.h +++ b/Eigen/src/Core/TriangularMatrix.h @@ -46,7 +46,7 @@ template class TriangularBase : public AnyMatrixBase }; typedef typename ei_traits::Scalar Scalar; - inline TriangularBase() { ei_assert(ei_are_flags_consistent::ret); } + inline TriangularBase() { ei_assert(!((Mode&UnitDiag) && (Mode&ZeroDiag))); } inline int rows() const { return derived().rows(); } inline int cols() const { return derived().cols(); } @@ -89,10 +89,10 @@ template class TriangularBase : public AnyMatrixBase void check_coordinates(int row, int col) { ei_assert(col>=0 && col=0 && row=row) - || (Mode==LowerTriangular && col<=row) - || ((Mode==StrictlyUpperTriangular || Mode==UnitUpperTriangular) && col>row) - || ((Mode==StrictlyLowerTriangular || Mode==UnitLowerTriangular) && col=row) + || (Mode==Lower && col<=row) + || ((Mode==StrictlyUpper || Mode==UnitUpper) && col>row) + || ((Mode==StrictlyLower || Mode==UnitLower) && col class TriangularBase : public AnyMatrixBase * \brief Base class for triangular part in a matrix * * \param MatrixType the type of the object in which we are taking the triangular part - * \param Mode the kind of triangular matrix expression to construct. Can be UpperTriangular, - * LowerTriangular, UpperSelfadjoint, or LowerSelfadjoint. This is in fact a bit field; - * it must have either UpperBit or LowerBit, and additionnaly it may have either - * TraingularBit or SelfadjointBit. + * \param Mode the kind of triangular matrix expression to construct. Can be Upper, + * Lower, UpperSelfadjoint, or LowerSelfadjoint. This is in fact a bit field; + * it must have either Upper or Lower, and additionnaly it may have either + * UnitDiag or Selfadjoint. * * This class represents a triangular part of a matrix, not necessarily square. Strictly speaking, for rectangular * matrices one should speak ok "trapezoid" parts. This class is the return type @@ -154,9 +154,10 @@ template class TriangularView enum { Mode = _Mode, - TransposeMode = (Mode & UpperTriangularBit ? LowerTriangularBit : 0) - | (Mode & LowerTriangularBit ? UpperTriangularBit : 0) - | (Mode & (ZeroDiagBit | UnitDiagBit)) + TransposeMode = (Mode & Upper ? Lower : 0) + | (Mode & Lower ? Upper : 0) + | (Mode & (UnitDiag)) + | (Mode & (ZeroDiag)) }; inline TriangularView(const MatrixType& matrix) : m_matrix(matrix) @@ -283,12 +284,12 @@ template class TriangularView const SelfAdjointView<_MatrixTypeNested,Mode> selfadjointView() const { - EIGEN_STATIC_ASSERT((Mode&UnitDiagBit)==0,PROGRAMMING_ERROR); + EIGEN_STATIC_ASSERT((Mode&UnitDiag)==0,PROGRAMMING_ERROR); return SelfAdjointView<_MatrixTypeNested,Mode>(m_matrix); } SelfAdjointView<_MatrixTypeNested,Mode> selfadjointView() { - EIGEN_STATIC_ASSERT((Mode&UnitDiagBit)==0,PROGRAMMING_ERROR); + EIGEN_STATIC_ASSERT((Mode&UnitDiag)==0,PROGRAMMING_ERROR); return SelfAdjointView<_MatrixTypeNested,Mode>(m_matrix); } @@ -304,6 +305,16 @@ template class TriangularView TriangularView,Mode>(const_cast(m_matrix)).lazyAssign(other.derived()); } + Scalar determinant() const + { + if (Mode & UnitDiag) + return 1; + else if (Mode & ZeroDiag) + return 0; + else + return m_matrix.diagonal().prod(); + } + protected: const MatrixTypeNested m_matrix; @@ -325,19 +336,19 @@ struct ei_triangular_assignment_selector { ei_triangular_assignment_selector::run(dst, src); - ei_assert( Mode == UpperTriangular || Mode == LowerTriangular - || Mode == StrictlyUpperTriangular || Mode == StrictlyLowerTriangular - || Mode == UnitUpperTriangular || Mode == UnitLowerTriangular); - if((Mode == UpperTriangular && row <= col) - || (Mode == LowerTriangular && row >= col) - || (Mode == StrictlyUpperTriangular && row < col) - || (Mode == StrictlyLowerTriangular && row > col) - || (Mode == UnitUpperTriangular && row < col) - || (Mode == UnitLowerTriangular && row > col)) + ei_assert( Mode == Upper || Mode == Lower + || Mode == StrictlyUpper || Mode == StrictlyLower + || Mode == UnitUpper || Mode == UnitLower); + if((Mode == Upper && row <= col) + || (Mode == Lower && row >= col) + || (Mode == StrictlyUpper && row < col) + || (Mode == StrictlyLower && row > col) + || (Mode == UnitUpper && row < col) + || (Mode == UnitLower && row > col)) dst.copyCoeff(row, col, src); else if(ClearOpposite) { - if (Mode&UnitDiagBit && row==col) + if (Mode&UnitDiag && row==col) dst.coeffRef(row, col) = 1; else dst.coeffRef(row, col) = 0; @@ -353,7 +364,7 @@ struct ei_triangular_assignment_selector -struct ei_triangular_assignment_selector +struct ei_triangular_assignment_selector { inline static void run(Derived1 &dst, const Derived2 &src) { @@ -370,7 +381,7 @@ struct ei_triangular_assignment_selector -struct ei_triangular_assignment_selector +struct ei_triangular_assignment_selector { inline static void run(Derived1 &dst, const Derived2 &src) { @@ -387,7 +398,7 @@ struct ei_triangular_assignment_selector -struct ei_triangular_assignment_selector +struct ei_triangular_assignment_selector { inline static void run(Derived1 &dst, const Derived2 &src) { @@ -404,7 +415,7 @@ struct ei_triangular_assignment_selector -struct ei_triangular_assignment_selector +struct ei_triangular_assignment_selector { inline static void run(Derived1 &dst, const Derived2 &src) { @@ -421,7 +432,7 @@ struct ei_triangular_assignment_selector -struct ei_triangular_assignment_selector +struct ei_triangular_assignment_selector { inline static void run(Derived1 &dst, const Derived2 &src) { @@ -440,7 +451,7 @@ struct ei_triangular_assignment_selector -struct ei_triangular_assignment_selector +struct ei_triangular_assignment_selector { inline static void run(Derived1 &dst, const Derived2 &src) { @@ -590,8 +601,8 @@ EIGEN_DEPRECATED TriangularView MatrixBase::part() /** \nonstableyet * \returns an expression of a triangular view extracted from the current matrix * - * The parameter \a Mode can have the following values: \c UpperTriangular, \c StrictlyUpperTriangular, \c UnitUpperTriangular, - * \c LowerTriangular, \c StrictlyLowerTriangular, \c UnitLowerTriangular. + * The parameter \a Mode can have the following values: \c Upper, \c StrictlyUpper, \c UnitUpper, + * \c Lower, \c StrictlyLower, \c UnitLower. * * Example: \include MatrixBase_extract.cpp * Output: \verbinclude MatrixBase_extract.out @@ -616,22 +627,22 @@ const TriangularView MatrixBase::triangularView() const /** \returns true if *this is approximately equal to an upper triangular matrix, * within the precision given by \a prec. * - * \sa isLowerTriangular(), extract(), part(), marked() + * \sa isLower(), extract(), part(), marked() */ template bool MatrixBase::isUpperTriangular(RealScalar prec) const { - RealScalar maxAbsOnUpperTriangularPart = static_cast(-1); + RealScalar maxAbsOnUpperPart = static_cast(-1); for(int j = 0; j < cols(); ++j) { int maxi = std::min(j, rows()-1); for(int i = 0; i <= maxi; ++i) { RealScalar absValue = ei_abs(coeff(i,j)); - if(absValue > maxAbsOnUpperTriangularPart) maxAbsOnUpperTriangularPart = absValue; + if(absValue > maxAbsOnUpperPart) maxAbsOnUpperPart = absValue; } } - RealScalar threshold = maxAbsOnUpperTriangularPart * prec; + RealScalar threshold = maxAbsOnUpperPart * prec; for(int j = 0; j < cols(); ++j) for(int i = j+1; i < rows(); ++i) if(ei_abs(coeff(i, j)) > threshold) return false; @@ -641,19 +652,19 @@ bool MatrixBase::isUpperTriangular(RealScalar prec) const /** \returns true if *this is approximately equal to a lower triangular matrix, * within the precision given by \a prec. * - * \sa isUpperTriangular(), extract(), part(), marked() + * \sa isUpper(), extract(), part(), marked() */ template bool MatrixBase::isLowerTriangular(RealScalar prec) const { - RealScalar maxAbsOnLowerTriangularPart = static_cast(-1); + RealScalar maxAbsOnLowerPart = static_cast(-1); for(int j = 0; j < cols(); ++j) for(int i = j; i < rows(); ++i) { RealScalar absValue = ei_abs(coeff(i,j)); - if(absValue > maxAbsOnLowerTriangularPart) maxAbsOnLowerTriangularPart = absValue; + if(absValue > maxAbsOnLowerPart) maxAbsOnLowerPart = absValue; } - RealScalar threshold = maxAbsOnLowerTriangularPart * prec; + RealScalar threshold = maxAbsOnLowerPart * prec; for(int j = 1; j < cols(); ++j) { int maxi = std::min(j, rows()-1); diff --git a/Eigen/src/Core/products/SelfadjointMatrixMatrix.h b/Eigen/src/Core/products/SelfadjointMatrixMatrix.h index 35efa752e..ac072e189 100644 --- a/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +++ b/Eigen/src/Core/products/SelfadjointMatrixMatrix.h @@ -368,10 +368,10 @@ struct SelfadjointProductMatrix SelfadjointProductMatrix(const Lhs& lhs, const Rhs& rhs) : Base(lhs,rhs) {} enum { - LhsUpLo = LhsMode&(UpperTriangularBit|LowerTriangularBit), - LhsIsSelfAdjoint = (LhsMode&SelfAdjointBit)==SelfAdjointBit, - RhsUpLo = RhsMode&(UpperTriangularBit|LowerTriangularBit), - RhsIsSelfAdjoint = (RhsMode&SelfAdjointBit)==SelfAdjointBit + LhsUpLo = LhsMode&(Upper|Lower), + LhsIsSelfAdjoint = (LhsMode&SelfAdjoint)==SelfAdjoint, + RhsUpLo = RhsMode&(Upper|Lower), + RhsIsSelfAdjoint = (RhsMode&SelfAdjoint)==SelfAdjoint }; template void scaleAndAddTo(Dest& dst, Scalar alpha) const @@ -385,12 +385,12 @@ struct SelfadjointProductMatrix * RhsBlasTraits::extractScalarFactor(m_rhs); ei_product_selfadjoint_matrix::Flags &RowMajorBit) ? RowMajor : ColMajor, LhsIsSelfAdjoint, - NumTraits::IsComplex && EIGEN_LOGICAL_XOR(LhsUpLo==UpperTriangular,bool(LhsBlasTraits::NeedToConjugate)), - EIGEN_LOGICAL_XOR(RhsUpLo==UpperTriangular, + NumTraits::IsComplex && EIGEN_LOGICAL_XOR(LhsUpLo==Upper,bool(LhsBlasTraits::NeedToConjugate)), + EIGEN_LOGICAL_XOR(RhsUpLo==Upper, ei_traits::Flags &RowMajorBit) ? RowMajor : ColMajor, RhsIsSelfAdjoint, - NumTraits::IsComplex && EIGEN_LOGICAL_XOR(RhsUpLo==UpperTriangular,bool(RhsBlasTraits::NeedToConjugate)), + NumTraits::IsComplex && EIGEN_LOGICAL_XOR(RhsUpLo==Upper,bool(RhsBlasTraits::NeedToConjugate)), ei_traits::Flags&RowMajorBit ? RowMajor : ColMajor> ::run( lhs.rows(), rhs.cols(), // sizes diff --git a/Eigen/src/Core/products/SelfadjointMatrixVector.h b/Eigen/src/Core/products/SelfadjointMatrixVector.h index 32b7f220e..1c48208b3 100644 --- a/Eigen/src/Core/products/SelfadjointMatrixVector.h +++ b/Eigen/src/Core/products/SelfadjointMatrixVector.h @@ -42,7 +42,7 @@ static EIGEN_DONT_INLINE void ei_product_selfadjoint_vector( enum { IsRowMajor = StorageOrder==RowMajor ? 1 : 0, - IsLower = UpLo == LowerTriangularBit ? 1 : 0, + IsLower = UpLo == Lower ? 1 : 0, FirstTriangular = IsRowMajor == IsLower }; @@ -170,7 +170,7 @@ struct SelfadjointProductMatrix EIGEN_PRODUCT_PUBLIC_INTERFACE(SelfadjointProductMatrix) enum { - LhsUpLo = LhsMode&(UpperTriangularBit|LowerTriangularBit) + LhsUpLo = LhsMode&(Upper|Lower) }; SelfadjointProductMatrix(const Lhs& lhs, const Rhs& rhs) : Base(lhs,rhs) {} diff --git a/Eigen/src/Core/products/SelfadjointProduct.h b/Eigen/src/Core/products/SelfadjointProduct.h index f9cdda637..8967f62be 100644 --- a/Eigen/src/Core/products/SelfadjointProduct.h +++ b/Eigen/src/Core/products/SelfadjointProduct.h @@ -47,7 +47,7 @@ struct ei_selfadjoint_product { static EIGEN_STRONG_INLINE void run(int size, int depth, const Scalar* mat, int matStride, Scalar* res, int resStride, Scalar alpha) { - ei_selfadjoint_product + ei_selfadjoint_product ::run(size, depth, mat, matStride, res, resStride, alpha); } }; @@ -100,13 +100,13 @@ struct ei_selfadjoint_product // 1 - before the diagonal => processed with gebp or skipped // 2 - the actual_mc x actual_mc symmetric block => processed with a special kernel // 3 - after the diagonal => processed with gebp or skipped - if (UpLo==LowerTriangular) + if (UpLo==Lower) gebp_kernel(res+i2, resStride, blockA, blockB, actual_mc, actual_kc, std::min(size,i2)); ei_sybb_kernel() (res+resStride*i2 + i2, resStride, blockA, blockB + actual_kc*Blocking::PacketSize*i2, actual_mc, actual_kc); - if (UpLo==UpperTriangular) + if (UpLo==Upper) { int j2 = i2+actual_mc; gebp_kernel(res+resStride*j2+i2, resStride, blockA, blockB+actual_kc*Blocking::PacketSize*j2, actual_mc, actual_kc, std::max(0,size-j2)); @@ -173,7 +173,7 @@ struct ei_sybb_kernel int actualBlockSize = std::min(BlockSize,size - j); const Scalar* actual_b = blockB+j*depth*PacketSize; - if(UpLo==UpperTriangular) + if(UpLo==Upper) gebp_kernel(res+j*resStride, resStride, blockA, actual_b, j, depth, actualBlockSize); // selfadjoint micro block @@ -186,13 +186,13 @@ struct ei_sybb_kernel for(int j1=0; j1 struct ei_selfadjoint_rank2_update_selector; template -struct ei_selfadjoint_rank2_update_selector +struct ei_selfadjoint_rank2_update_selector { static void run(Scalar* mat, int stride, const UType& u, const VType& v, Scalar alpha) { @@ -48,7 +48,7 @@ struct ei_selfadjoint_rank2_update_selector }; template -struct ei_selfadjoint_rank2_update_selector +struct ei_selfadjoint_rank2_update_selector { static void run(Scalar* mat, int stride, const UType& u, const VType& v, Scalar alpha) { @@ -87,7 +87,7 @@ SelfAdjointView& SelfAdjointView ei_selfadjoint_rank2_update_selector::ret>::type, typename ei_cleantype::ret>::type, - (IsRowMajor ? (UpLo==UpperTriangular ? LowerTriangular : UpperTriangular) : UpLo)> + (IsRowMajor ? (UpLo==Upper ? Lower : Upper) : UpLo)> ::run(const_cast(_expression().data()),_expression().stride(),actualU,actualV,actualAlpha); return *this; diff --git a/Eigen/src/Core/products/TriangularMatrixMatrix.h b/Eigen/src/Core/products/TriangularMatrixMatrix.h index 701ccb644..37617a915 100644 --- a/Eigen/src/Core/products/TriangularMatrixMatrix.h +++ b/Eigen/src/Core/products/TriangularMatrixMatrix.h @@ -75,7 +75,7 @@ struct ei_product_triangular_matrix_matrix Blocking; enum { SmallPanelWidth = EIGEN_ENUM_MAX(Blocking::mr,Blocking::nr), - IsLowerTriangular = (Mode&LowerTriangular) == LowerTriangular + IsLower = (Mode&Lower) == Lower }; int kc = std::min(Blocking::Max_kc/4,size); // cache block size along the K direction @@ -130,12 +130,12 @@ struct ei_product_triangular_matrix_matrix pack_lhs; ei_gemm_pack_rhs pack_rhs; - for(int k2=IsLowerTriangular ? size : 0; - IsLowerTriangular ? k2>0 : k20 : k2(actual_kc-k1, SmallPanelWidth); - int lengthTarget = IsLowerTriangular ? actual_kc-k1-actualPanelWidth : k1; + int lengthTarget = IsLower ? actual_kc-k1-actualPanelWidth : k1; int startBlock = actual_k2+k1; int blockBOffset = k1; @@ -158,9 +158,9 @@ struct ei_product_triangular_matrix_matrix0) { - int startTarget = IsLowerTriangular ? actual_k2+k1+actualPanelWidth : actual_k2; + int startTarget = IsLower ? actual_k2+k1+actualPanelWidth : actual_k2; pack_lhs(blockA, &lhs(startTarget,startBlock), lhsStride, actualPanelWidth, lengthTarget); @@ -182,8 +182,8 @@ struct ei_product_triangular_matrix_matrix GEPP { - int start = IsLowerTriangular ? k2 : 0; - int end = IsLowerTriangular ? size : actual_k2; + int start = IsLower ? k2 : 0; + int end = IsLower ? size : actual_k2; for(int i2=start; i2 Blocking; enum { SmallPanelWidth = EIGEN_ENUM_MAX(Blocking::mr,Blocking::nr), - IsLowerTriangular = (Mode&LowerTriangular) == LowerTriangular + IsLower = (Mode&Lower) == Lower }; int kc = std::min(Blocking::Max_kc/4,size); // cache block size along the K direction @@ -245,16 +245,16 @@ struct ei_product_triangular_matrix_matrix pack_rhs; ei_gemm_pack_rhs pack_rhs_panel; - for(int k2=IsLowerTriangular ? 0 : size; - IsLowerTriangular ? k20; - IsLowerTriangular ? k2+=kc : k2-=kc) + for(int k2=IsLower ? 0 : size; + IsLower ? k20; + IsLower ? k2+=kc : k2-=kc) { - const int actual_kc = std::min(IsLowerTriangular ? size-k2 : k2, kc); - int actual_k2 = IsLowerTriangular ? k2 : k2-actual_kc; - int rs = IsLowerTriangular ? actual_k2 : size - k2; + const int actual_kc = std::min(IsLower ? size-k2 : k2, kc); + int actual_k2 = IsLower ? k2 : k2-actual_kc; + int rs = IsLower ? actual_k2 : size - k2; Scalar* geb = blockB+actual_kc*actual_kc*Blocking::PacketSize; - pack_rhs(geb, &rhs(actual_k2,IsLowerTriangular ? 0 : k2), rhsStride, alpha, actual_kc, rs); + pack_rhs(geb, &rhs(actual_k2,IsLower ? 0 : k2), rhsStride, alpha, actual_kc, rs); // pack the triangular part of the rhs padding the unrolled blocks with zeros { @@ -262,8 +262,8 @@ struct ei_product_triangular_matrix_matrix(actual_kc-j2, SmallPanelWidth); int actual_j2 = actual_k2 + j2; - int panelOffset = IsLowerTriangular ? j2+actualPanelWidth : 0; - int panelLength = IsLowerTriangular ? actual_kc-j2-actualPanelWidth : j2; + int panelOffset = IsLower ? j2+actualPanelWidth : 0; + int panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2; // general part pack_rhs_panel(blockB+j2*actual_kc*Blocking::PacketSize, &rhs(actual_k2+panelOffset, actual_j2), rhsStride, alpha, @@ -273,9 +273,9 @@ struct ei_product_triangular_matrix_matrix(actual_kc-j2, SmallPanelWidth); - int panelLength = IsLowerTriangular ? actual_kc-j2 : j2+actualPanelWidth; - int blockOffset = IsLowerTriangular ? j2 : 0; + int panelLength = IsLower ? actual_kc-j2 : j2+actualPanelWidth; + int blockOffset = IsLower ? j2 : 0; gebp_kernel(res+i2+(actual_k2+j2)*resStride, resStride, blockA, blockB+j2*actual_kc*Blocking::PacketSize, @@ -306,7 +306,7 @@ struct ei_product_triangular_matrix_matrix::Scalar alpha) { @@ -50,17 +50,17 @@ struct ei_product_triangular_vector_selector0) res.segment(s,r) += (alpha * cjRhs.coeff(i)) * cjLhs.col(i).segment(s,r); if (HasUnitDiag) res.coeffRef(i) += alpha * cjRhs.coeff(i); } - int r = IsLowerTriangular ? size - pi - actualPanelWidth : pi; + int r = IsLower ? size - pi - actualPanelWidth : pi; if (r>0) { - int s = IsLowerTriangular ? pi+actualPanelWidth : 0; + int s = IsLower ? pi+actualPanelWidth : 0; ei_cache_friendly_product_colmajor_times_vector( r, &(lhs.const_cast_derived().coeffRef(s,pi)), lhs.stride(), @@ -77,8 +77,8 @@ struct ei_product_triangular_vector_selector::Scalar alpha) { @@ -92,17 +92,17 @@ struct ei_product_triangular_vector_selector0) res.coeffRef(i) += alpha * (cjLhs.row(i).segment(s,r).cwiseProduct(cjRhs.segment(s,r).transpose())).sum(); if (HasUnitDiag) res.coeffRef(i) += alpha * cjRhs.coeff(i); } - int r = IsLowerTriangular ? pi : size - pi - actualPanelWidth; + int r = IsLower ? pi : size - pi - actualPanelWidth; if (r>0) { - int s = IsLowerTriangular ? 0 : pi + actualPanelWidth; + int s = IsLower ? 0 : pi + actualPanelWidth; Block target(res,pi,0,actualPanelWidth,1); ei_cache_friendly_product_rowmajor_times_vector( &(lhs.const_cast_derived().coeffRef(pi,s)), lhs.stride(), diff --git a/Eigen/src/Core/products/TriangularSolverMatrix.h b/Eigen/src/Core/products/TriangularSolverMatrix.h index e49fac956..23a645d7c 100644 --- a/Eigen/src/Core/products/TriangularSolverMatrix.h +++ b/Eigen/src/Core/products/TriangularSolverMatrix.h @@ -36,7 +36,7 @@ struct ei_triangular_solve_matrix::IsComplex && Conjugate, TriStorageOrder==RowMajor ? ColMajor : RowMajor, ColMajor> ::run(size, cols, tri, triStride, _other, otherStride); @@ -60,7 +60,7 @@ struct ei_triangular_solve_matrix Blocking; enum { SmallPanelWidth = EIGEN_ENUM_MAX(Blocking::mr,Blocking::nr), - IsLowerTriangular = (Mode&LowerTriangular) == LowerTriangular + IsLower = (Mode&Lower) == Lower }; int kc = std::min(Blocking::Max_kc/4,size); // cache block size along the K direction @@ -73,11 +73,11 @@ struct ei_triangular_solve_matrix > gebp_kernel; ei_gemm_pack_lhs pack_lhs; - for(int k2=IsLowerTriangular ? 0 : size; - IsLowerTriangular ? k20; - IsLowerTriangular ? k2+=kc : k2-=kc) + for(int k2=IsLower ? 0 : size; + IsLower ? k20; + IsLower ? k2+=kc : k2-=kc) { - const int actual_kc = std::min(IsLowerTriangular ? size-k2 : k2, kc); + const int actual_kc = std::min(IsLower ? size-k2 : k2, kc); // We have selected and packed a big horizontal panel R1 of rhs. Let B be the packed copy of this panel, // and R2 the remaining part of rhs. The corresponding vertical panel of lhs is split into @@ -101,11 +101,11 @@ struct ei_triangular_solve_matrix() @@ -141,7 +141,7 @@ struct ei_triangular_solve_matrix0) { - int startTarget = IsLowerTriangular ? k2+k1+actualPanelWidth : k2-actual_kc; + int startTarget = IsLower ? k2+k1+actualPanelWidth : k2-actual_kc; pack_lhs(blockA, &tri(startTarget,startBlock), triStride, actualPanelWidth, lengthTarget); @@ -153,14 +153,14 @@ struct ei_triangular_solve_matrix GEPP { - int start = IsLowerTriangular ? k2+kc : 0; - int end = IsLowerTriangular ? size : k2-kc; + int start = IsLower ? k2+kc : 0; + int end = IsLower ? size : k2-kc; for(int i2=start; i20) { - pack_lhs(blockA, &tri(i2, IsLowerTriangular ? k2 : k2-kc), triStride, actual_kc, actual_mc); + pack_lhs(blockA, &tri(i2, IsLower ? k2 : k2-kc), triStride, actual_kc, actual_mc); gebp_kernel(_other+i2, otherStride, blockA, blockB, actual_mc, actual_kc, cols); } @@ -191,7 +191,7 @@ struct ei_triangular_solve_matrix(Blocking::Max_kc/4,size); // cache block size along the K direction @@ -206,15 +206,15 @@ struct ei_triangular_solve_matrix pack_rhs_panel; ei_gemm_pack_lhs pack_lhs_panel; - for(int k2=IsLowerTriangular ? size : 0; - IsLowerTriangular ? k2>0 : k20 : k20) pack_rhs(geb, &rhs(actual_k2,startPanel), triStride, -1, actual_kc, rs); @@ -226,8 +226,8 @@ struct ei_triangular_solve_matrix(actual_kc-j2, SmallPanelWidth); int actual_j2 = actual_k2 + j2; - int panelOffset = IsLowerTriangular ? j2+actualPanelWidth : 0; - int panelLength = IsLowerTriangular ? actual_kc-j2-actualPanelWidth : j2; + int panelOffset = IsLower ? j2+actualPanelWidth : 0; + int panelLength = IsLower ? actual_kc-j2-actualPanelWidth : j2; if (panelLength>0) pack_rhs_panel(blockB+j2*actual_kc*Blocking::PacketSize, @@ -244,17 +244,17 @@ struct ei_triangular_solve_matrix vertical panels of rhs) - for (int j2 = IsLowerTriangular + for (int j2 = IsLower ? (actual_kc - ((actual_kc%SmallPanelWidth) ? (actual_kc%SmallPanelWidth) : SmallPanelWidth)) : 0; - IsLowerTriangular ? j2>=0 : j2=0 : j2(actual_kc-j2, SmallPanelWidth); int absolute_j2 = actual_k2 + j2; - int panelOffset = IsLowerTriangular ? j2+actualPanelWidth : 0; - int panelLength = IsLowerTriangular ? actual_kc - j2 - actualPanelWidth : j2; + int panelOffset = IsLower ? j2+actualPanelWidth : 0; + int panelLength = IsLower ? actual_kc - j2 - actualPanelWidth : j2; // GEBP if(panelLength>0) @@ -269,17 +269,17 @@ struct ei_triangular_solve_matrix class ColPivHouseholderQR; template class FullPivHouseholderQR; template class SVD; template class JacobiSVD; -template class LLT; +template class LLT; template class LDLT; template class HouseholderSequence; template class PlanarRotation; diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 4bff09252..9b17a2b0e 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -263,8 +263,7 @@ template::ty template struct ei_are_flags_consistent { - enum { ret = !( (Flags&UnitDiagBit && Flags&ZeroDiagBit) ) - }; + enum { ret = true }; }; /** \internal Helper base class to add a scalar multiple operator diff --git a/Eigen/src/Eigen2Support/Flagged.h b/Eigen/src/Eigen2Support/Flagged.h index 94e7f9119..bed110b64 100644 --- a/Eigen/src/Eigen2Support/Flagged.h +++ b/Eigen/src/Eigen2Support/Flagged.h @@ -109,6 +109,12 @@ template clas const ExpressionType& _expression() const { return m_matrix; } + template + typename ExpressionType::PlainMatrixType solveTriangular(const MatrixBase& other) const; + + template + void solveTriangularInPlace(const MatrixBase& other) const; + protected: ExpressionTypeNested m_matrix; }; diff --git a/Eigen/src/Eigen2Support/TriangularSolver.h b/Eigen/src/Eigen2Support/TriangularSolver.h index e69de29bb..94b92577e 100644 --- a/Eigen/src/Eigen2Support/TriangularSolver.h +++ b/Eigen/src/Eigen2Support/TriangularSolver.h @@ -0,0 +1,53 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2010 Gael Guennebaud +// +// Eigen is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// Alternatively, you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of +// the License, or (at your option) any later version. +// +// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License and a copy of the GNU General Public License along with +// Eigen. If not, see . + +#ifndef EIGEN_TRIANGULAR_SOLVER2_H +#define EIGEN_TRIANGULAR_SOLVER2_H + +const unsigned int UnitDiagBit = UnitDiag; +const unsigned int SelfAdjointBit = SelfAdjoint; +const unsigned int UpperTriangularBit = Upper; +const unsigned int LowerTriangularBit = Lower; + +const unsigned int UpperTriangular = Upper; +const unsigned int LowerTriangular = Lower; +const unsigned int UnitUpperTriangular = UnitUpper; +const unsigned int UnitLowerTriangular = UnitLower; + +template +template +typename ExpressionType::PlainMatrixType +Flagged::solveTriangular(const MatrixBase& other) const +{ + return m_matrix.template triangularView.solve(other.derived()); +} + +template +template +void Flagged::solveTriangularInPlace(const MatrixBase& other) const +{ + m_matrix.template triangularView.solveInPlace(other.derived()); +} + +#endif // EIGEN_TRIANGULAR_SOLVER2_H diff --git a/Eigen/src/Eigenvalues/HessenbergDecomposition.h b/Eigen/src/Eigenvalues/HessenbergDecomposition.h index 636b2f4f7..e3f64b807 100644 --- a/Eigen/src/Eigenvalues/HessenbergDecomposition.h +++ b/Eigen/src/Eigenvalues/HessenbergDecomposition.h @@ -199,7 +199,7 @@ HessenbergDecomposition::matrixH() const int n = m_matrix.rows(); MatrixType matH = m_matrix; if (n>2) - matH.corner(BottomLeft,n-2, n-2).template triangularView().setZero(); + matH.corner(BottomLeft,n-2, n-2).template triangularView().setZero(); return matH; } diff --git a/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h b/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h index 336976517..960e9b417 100644 --- a/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +++ b/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h @@ -247,11 +247,11 @@ compute(const MatrixType& matA, const MatrixType& matB, bool computeEigenvectors matC.adjointInPlace(); // this version works too: // matC = matC.transpose(); -// cholB.matrixL().conjugate().template marked().solveTriangularInPlace(matC); +// cholB.matrixL().conjugate().template marked().solveTriangularInPlace(matC); // matC = matC.transpose(); // FIXME: this should work: (currently it only does for small matrices) // Transpose trMatC(matC); -// cholB.matrixL().conjugate().eval().template marked().solveTriangularInPlace(trMatC); +// cholB.matrixL().conjugate().eval().template marked().solveTriangularInPlace(trMatC); compute(matC, computeEigenvectors); @@ -275,7 +275,7 @@ template inline Matrix::Scalar>::Real, ei_traits::ColsAtCompileTime, 1> MatrixBase::eigenvalues() const { - ei_assert(Flags&SelfAdjointBit); + ei_assert(Flags&SelfAdjoint); return SelfAdjointEigenSolver(eval(),false).eigenvalues(); } @@ -316,7 +316,7 @@ template inline typename NumTraits::Scalar>::Real MatrixBase::operatorNorm() const { - return ei_operatorNorm_selector + return ei_operatorNorm_selector ::operatorNorm(derived()); } diff --git a/Eigen/src/Eigenvalues/Tridiagonalization.h b/Eigen/src/Eigenvalues/Tridiagonalization.h index e43605b0f..ffd374eb2 100644 --- a/Eigen/src/Eigenvalues/Tridiagonalization.h +++ b/Eigen/src/Eigenvalues/Tridiagonalization.h @@ -172,8 +172,8 @@ Tridiagonalization::matrixT(void) const matT.corner(TopRight,n-1, n-1).diagonal() = subDiagonal().template cast().conjugate(); if (n>2) { - matT.corner(TopRight,n-2, n-2).template triangularView().setZero(); - matT.corner(BottomLeft,n-2, n-2).template triangularView().setZero(); + matT.corner(TopRight,n-2, n-2).template triangularView().setZero(); + matT.corner(BottomLeft,n-2, n-2).template triangularView().setZero(); } return matT; } @@ -208,12 +208,12 @@ void Tridiagonalization::_compute(MatrixType& matA, CoeffVectorType& // i.e., A = H A H' where H = I - h v v' and v = matA.col(i).tail(n-i-1) matA.col(i).coeffRef(i+1) = 1; - hCoeffs.tail(n-i-1) = (matA.corner(BottomRight,remainingSize,remainingSize).template selfadjointView() + hCoeffs.tail(n-i-1) = (matA.corner(BottomRight,remainingSize,remainingSize).template selfadjointView() * (ei_conj(h) * matA.col(i).tail(remainingSize))); hCoeffs.tail(n-i-1) += (ei_conj(h)*Scalar(-0.5)*(hCoeffs.tail(remainingSize).dot(matA.col(i).tail(remainingSize)))) * matA.col(i).tail(n-i-1); - matA.corner(BottomRight, remainingSize, remainingSize).template selfadjointView() + matA.corner(BottomRight, remainingSize, remainingSize).template selfadjointView() .rankUpdate(matA.col(i).tail(remainingSize), hCoeffs.tail(remainingSize), -1); matA.col(i).coeffRef(i+1) = beta; diff --git a/Eigen/src/LU/Determinant.h b/Eigen/src/LU/Determinant.h index 27ad6abe9..bae01256e 100644 --- a/Eigen/src/LU/Determinant.h +++ b/Eigen/src/LU/Determinant.h @@ -41,14 +41,8 @@ const typename Derived::Scalar ei_bruteforce_det4_helper * (matrix.coeff(m,2) * matrix.coeff(n,3) - matrix.coeff(n,2) * matrix.coeff(m,3)); } -// FIXME update computation of triangular det - -const int TriangularDeterminant = 0; - template struct ei_determinant_impl { static inline typename ei_traits::Scalar run(const Derived& m) @@ -57,19 +51,6 @@ template struct ei_determinant_impl -{ - static inline typename ei_traits::Scalar run(const Derived& m) - { - if (Derived::Flags & UnitDiagBit) - return 1; - else if (Derived::Flags & ZeroDiagBit) - return 0; - else - return m.diagonal().redux(ei_scalar_product_op::Scalar>()); - } -}; - template struct ei_determinant_impl { static inline typename ei_traits::Scalar run(const Derived& m) diff --git a/Eigen/src/LU/FullPivLU.h b/Eigen/src/LU/FullPivLU.h index f62dcc1db..148ddcd23 100644 --- a/Eigen/src/LU/FullPivLU.h +++ b/Eigen/src/LU/FullPivLU.h @@ -541,7 +541,7 @@ struct ei_kernel_retval > m.row(i).tail(cols-i) = dec().matrixLU().row(pivots.coeff(i)).tail(cols-i); } m.block(0, 0, rank(), rank()); - m.block(0, 0, rank(), rank()).template triangularView().setZero(); + m.block(0, 0, rank(), rank()).template triangularView().setZero(); for(int i = 0; i < rank(); ++i) m.col(i).swap(m.col(pivots.coeff(i))); @@ -549,7 +549,7 @@ struct ei_kernel_retval > // notice that the math behind this suggests that we should apply this to the // negative of the RHS, but for performance we just put the negative sign elsewhere, see below. m.corner(TopLeft, rank(), rank()) - .template triangularView().solveInPlace( + .template triangularView().solveInPlace( m.corner(TopRight, rank(), dimker) ); @@ -638,7 +638,7 @@ struct ei_solve_retval, Rhs> // Step 2 dec().matrixLU() .corner(Eigen::TopLeft,smalldim,smalldim) - .template triangularView() + .template triangularView() .solveInPlace(c.corner(Eigen::TopLeft, smalldim, c.cols())); if(rows>cols) { @@ -650,7 +650,7 @@ struct ei_solve_retval, Rhs> // Step 3 dec().matrixLU() .corner(TopLeft, nonzero_pivots, nonzero_pivots) - .template triangularView() + .template triangularView() .solveInPlace(c.corner(TopLeft, nonzero_pivots, c.cols())); // Step 4 diff --git a/Eigen/src/LU/PartialPivLU.h b/Eigen/src/LU/PartialPivLU.h index 6bb5c3ac7..f50aa4535 100644 --- a/Eigen/src/LU/PartialPivLU.h +++ b/Eigen/src/LU/PartialPivLU.h @@ -349,7 +349,7 @@ struct ei_partial_lu_impl A_2.row(i).swap(A_2.row(row_transpositions[i])); // A12 = A11^-1 A12 - A11.template triangularView().solveInPlace(A12); + A11.template triangularView().solveInPlace(A12); A22.noalias() -= A21 * A12; } @@ -426,10 +426,10 @@ struct ei_solve_retval, Rhs> dst = dec().permutationP() * rhs(); // Step 2 - dec().matrixLU().template triangularView().solveInPlace(dst); + dec().matrixLU().template triangularView().solveInPlace(dst); // Step 3 - dec().matrixLU().template triangularView().solveInPlace(dst); + dec().matrixLU().template triangularView().solveInPlace(dst); } }; diff --git a/Eigen/src/QR/ColPivHouseholderQR.h b/Eigen/src/QR/ColPivHouseholderQR.h index 8b705de3c..f4edc9324 100644 --- a/Eigen/src/QR/ColPivHouseholderQR.h +++ b/Eigen/src/QR/ColPivHouseholderQR.h @@ -381,7 +381,7 @@ ColPivHouseholderQR& ColPivHouseholderQR::compute(const m_nonzero_pivots = k; m_hCoeffs.tail(size-k).setZero(); m_qr.corner(BottomRight,rows-k,cols-k) - .template triangularView() + .template triangularView() .setZero(); break; } @@ -453,7 +453,7 @@ struct ei_solve_retval, Rhs> dec().matrixQR() .corner(TopLeft, nonzero_pivots, nonzero_pivots) - .template triangularView() + .template triangularView() .solveInPlace(c.corner(TopLeft, nonzero_pivots, c.cols())); @@ -461,7 +461,7 @@ struct ei_solve_retval, Rhs> d.corner(TopLeft, nonzero_pivots, c.cols()) = dec().matrixQR() .corner(TopLeft, nonzero_pivots, nonzero_pivots) - .template triangularView() + .template triangularView() * c.corner(TopLeft, nonzero_pivots, c.cols()); for(int i = 0; i < nonzero_pivots; ++i) dst.row(dec().colsPermutation().indices().coeff(i)) = c.row(i); diff --git a/Eigen/src/QR/FullPivHouseholderQR.h b/Eigen/src/QR/FullPivHouseholderQR.h index 598f44dc3..717ff19f8 100644 --- a/Eigen/src/QR/FullPivHouseholderQR.h +++ b/Eigen/src/QR/FullPivHouseholderQR.h @@ -376,7 +376,7 @@ struct ei_solve_retval, Rhs> } dec().matrixQR() .corner(TopLeft, dec().rank(), dec().rank()) - .template triangularView() + .template triangularView() .solveInPlace(c.corner(TopLeft, dec().rank(), c.cols())); for(int i = 0; i < dec().rank(); ++i) dst.row(dec().colsPermutation().indices().coeff(i)) = c.row(i); diff --git a/Eigen/src/QR/HouseholderQR.h b/Eigen/src/QR/HouseholderQR.h index 24aa96e04..3afaed9e0 100644 --- a/Eigen/src/QR/HouseholderQR.h +++ b/Eigen/src/QR/HouseholderQR.h @@ -231,7 +231,7 @@ struct ei_solve_retval, Rhs> dec().matrixQR() .corner(TopLeft, rank, rank) - .template triangularView() + .template triangularView() .solveInPlace(c.corner(TopLeft, rank, c.cols())); dst.corner(TopLeft, rank, c.cols()) = c.corner(TopLeft, rank, c.cols()); diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index d2cd8e478..55fac3d12 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -234,7 +234,7 @@ struct ei_svd_precondition_if_more_rows_than_cols if(rows > cols) { FullPivHouseholderQR qr(matrix); - work_matrix = qr.matrixQR().block(0,0,diagSize,diagSize).template triangularView(); + work_matrix = qr.matrixQR().block(0,0,diagSize,diagSize).template triangularView(); if(ComputeU) svd.m_matrixU = qr.matrixQ(); if(ComputeV) svd.m_matrixV = qr.colsPermutation(); @@ -278,7 +278,7 @@ struct ei_svd_precondition_if_more_cols_than_rows MatrixOptions,MaxColsAtCompileTime,MaxRowsAtCompileTime> TransposeTypeWithSameStorageOrder; FullPivHouseholderQR qr(matrix.adjoint()); - work_matrix = qr.matrixQR().block(0,0,diagSize,diagSize).template triangularView().adjoint(); + work_matrix = qr.matrixQR().block(0,0,diagSize,diagSize).template triangularView().adjoint(); if(ComputeV) svd.m_matrixV = qr.matrixQ(); if(ComputeU) svd.m_matrixU = qr.colsPermutation(); return true; diff --git a/Eigen/src/Sparse/CholmodSupport.h b/Eigen/src/Sparse/CholmodSupport.h index f02374d7c..fd33b1507 100644 --- a/Eigen/src/Sparse/CholmodSupport.h +++ b/Eigen/src/Sparse/CholmodSupport.h @@ -76,9 +76,9 @@ cholmod_sparse SparseMatrixBase::asCholmodMatrix() if (Derived::Flags & SelfAdjoint) { - if (Derived::Flags & UpperTriangular) + if (Derived::Flags & Upper) res.stype = 1; - else if (Derived::Flags & LowerTriangular) + else if (Derived::Flags & Lower) res.stype = -1; else res.stype = 0; diff --git a/Eigen/src/Sparse/RandomSetter.h b/Eigen/src/Sparse/RandomSetter.h index b34ca19a8..76f24cf0e 100644 --- a/Eigen/src/Sparse/RandomSetter.h +++ b/Eigen/src/Sparse/RandomSetter.h @@ -179,8 +179,8 @@ class RandomSetter SwapStorage = 1 - MapTraits::IsSorted, TargetRowMajor = (SparseMatrixType::Flags & RowMajorBit) ? 1 : 0, SetterRowMajor = SwapStorage ? 1-TargetRowMajor : TargetRowMajor, - IsUpperTriangular = SparseMatrixType::Flags & UpperTriangularBit, - IsLowerTriangular = SparseMatrixType::Flags & LowerTriangularBit + IsUpper = SparseMatrixType::Flags & Upper, + IsLower = SparseMatrixType::Flags & Lower }; public: @@ -303,8 +303,8 @@ class RandomSetter /** \returns a reference to the coefficient at given coordinates \a row, \a col */ Scalar& operator() (int row, int col) { - ei_assert(((!IsUpperTriangular) || (row<=col)) && "Invalid access to an upper triangular matrix"); - ei_assert(((!IsLowerTriangular) || (col<=row)) && "Invalid access to an upper triangular matrix"); + ei_assert(((!IsUpper) || (row<=col)) && "Invalid access to an upper triangular matrix"); + ei_assert(((!IsLower) || (col<=row)) && "Invalid access to an upper triangular matrix"); const int outer = SetterRowMajor ? row : col; const int inner = SetterRowMajor ? col : row; const int outerMajor = outer >> OuterPacketBits; // index of the packet/map diff --git a/Eigen/src/Sparse/SparseLDLT.h b/Eigen/src/Sparse/SparseLDLT.h index 625357e2b..7dfcf329c 100644 --- a/Eigen/src/Sparse/SparseLDLT.h +++ b/Eigen/src/Sparse/SparseLDLT.h @@ -333,12 +333,12 @@ bool SparseLDLT::solveInPlace(MatrixBase &b) const return false; if (m_matrix.nonZeros()>0) // otherwise L==I - m_matrix.template triangularView().solveInPlace(b); + m_matrix.template triangularView().solveInPlace(b); b = b.cwiseQuotient(m_diag); // FIXME should be .adjoint() but it fails to compile... if (m_matrix.nonZeros()>0) // otherwise L==I - m_matrix.transpose().template triangularView().solveInPlace(b); + m_matrix.transpose().template triangularView().solveInPlace(b); return true; } diff --git a/Eigen/src/Sparse/SparseLLT.h b/Eigen/src/Sparse/SparseLLT.h index 68ae43022..9018fe0df 100644 --- a/Eigen/src/Sparse/SparseLLT.h +++ b/Eigen/src/Sparse/SparseLLT.h @@ -41,7 +41,7 @@ class SparseLLT protected: typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; - typedef SparseMatrix CholMatrixType; + typedef SparseMatrix CholMatrixType; enum { SupernodalFactorIsDirty = 0x10000, @@ -193,15 +193,15 @@ bool SparseLLT::solveInPlace(MatrixBase &b) const const int size = m_matrix.rows(); ei_assert(size==b.rows()); - m_matrix.template triangularView().solveInPlace(b); + m_matrix.template triangularView().solveInPlace(b); // FIXME should be simply .adjoint() but it fails to compile... if (NumTraits::IsComplex) { CholMatrixType aux = m_matrix.conjugate(); - aux.transpose().template triangularView().solveInPlace(b); + aux.transpose().template triangularView().solveInPlace(b); } else - m_matrix.transpose().template triangularView().solveInPlace(b); + m_matrix.transpose().template triangularView().solveInPlace(b); return true; } diff --git a/Eigen/src/Sparse/SparseLU.h b/Eigen/src/Sparse/SparseLU.h index 2ec6d0e74..0802b0807 100644 --- a/Eigen/src/Sparse/SparseLU.h +++ b/Eigen/src/Sparse/SparseLU.h @@ -47,7 +47,7 @@ class SparseLU protected: typedef typename MatrixType::Scalar Scalar; typedef typename NumTraits::Real RealScalar; - typedef SparseMatrix LUMatrixType; + typedef SparseMatrix LUMatrixType; enum { MatrixLUIsDirty = 0x10000 diff --git a/Eigen/src/Sparse/SparseMatrixBase.h b/Eigen/src/Sparse/SparseMatrixBase.h index dc66113f2..9e426c2b9 100644 --- a/Eigen/src/Sparse/SparseMatrixBase.h +++ b/Eigen/src/Sparse/SparseMatrixBase.h @@ -532,8 +532,8 @@ template class SparseMatrixBase : public AnyMatrixBase()) const; // bool isDiagonal(RealScalar prec = dummy_precision()) const; -// bool isUpperTriangular(RealScalar prec = dummy_precision()) const; -// bool isLowerTriangular(RealScalar prec = dummy_precision()) const; +// bool isUpper(RealScalar prec = dummy_precision()) const; +// bool isLower(RealScalar prec = dummy_precision()) const; // template // bool isOrthogonal(const MatrixBase& other, diff --git a/Eigen/src/Sparse/SparseSelfAdjointView.h b/Eigen/src/Sparse/SparseSelfAdjointView.h index 9f9c5b5e8..039e5c725 100644 --- a/Eigen/src/Sparse/SparseSelfAdjointView.h +++ b/Eigen/src/Sparse/SparseSelfAdjointView.h @@ -31,7 +31,7 @@ * \brief Pseudo expression to manipulate a triangular sparse matrix as a selfadjoint matrix. * * \param MatrixType the type of the dense matrix storing the coefficients - * \param UpLo can be either \c LowerTriangular or \c UpperTriangular + * \param UpLo can be either \c Lower or \c Upper * * This class is an expression of a sefladjoint matrix from a triangular part of a matrix * with given dense storage of the coefficients. It is the return type of MatrixBase::selfadjointView() @@ -168,9 +168,9 @@ class SparseSelfAdjointTimeDenseProduct enum { LhsIsRowMajor = (_Lhs::Flags&RowMajorBit)==RowMajorBit, ProcessFirstHalf = - ((UpLo&(UpperTriangularBit|LowerTriangularBit))==(UpperTriangularBit|LowerTriangularBit)) - || ( (UpLo&UpperTriangularBit) && !LhsIsRowMajor) - || ( (UpLo&LowerTriangularBit) && LhsIsRowMajor), + ((UpLo&(Upper|Lower))==(Upper|Lower)) + || ( (UpLo&Upper) && !LhsIsRowMajor) + || ( (UpLo&Lower) && LhsIsRowMajor), ProcessSecondHalf = !ProcessFirstHalf }; for (int j=0; j > template class SparseTriangularView : public SparseMatrixBase > { - enum { SkipFirst = (Mode==LowerTriangular && !(MatrixType::Flags&RowMajorBit)) - || (Mode==UpperTriangular && (MatrixType::Flags&RowMajorBit)) }; + enum { SkipFirst = (Mode==Lower && !(MatrixType::Flags&RowMajorBit)) + || (Mode==Upper && (MatrixType::Flags&RowMajorBit)) }; public: class InnerIterator; diff --git a/Eigen/src/Sparse/SuperLUSupport.h b/Eigen/src/Sparse/SuperLUSupport.h index 708f177e8..1a765c75b 100644 --- a/Eigen/src/Sparse/SuperLUSupport.h +++ b/Eigen/src/Sparse/SuperLUSupport.h @@ -193,9 +193,9 @@ struct SluMatrix : SuperMatrix res.setScalarType(); // FIXME the following is not very accurate - if (MatrixType::Flags & UpperTriangular) + if (MatrixType::Flags & Upper) res.Mtype = SLU_TRU; - if (MatrixType::Flags & LowerTriangular) + if (MatrixType::Flags & Lower) res.Mtype = SLU_TRL; if (MatrixType::Flags & SelfAdjoint) ei_assert(false && "SelfAdjoint matrix shape not supported by SuperLU"); @@ -251,9 +251,9 @@ struct SluMatrixMapHelper > res.setScalarType(); // FIXME the following is not very accurate - if (MatrixType::Flags & UpperTriangular) + if (MatrixType::Flags & Upper) res.Mtype = SLU_TRU; - if (MatrixType::Flags & LowerTriangular) + if (MatrixType::Flags & Lower) res.Mtype = SLU_TRL; if (MatrixType::Flags & SelfAdjoint) ei_assert(false && "SelfAdjoint matrix shape not supported by SuperLU"); @@ -298,8 +298,8 @@ class SparseLU : public SparseLU typedef Matrix Vector; typedef Matrix IntRowVectorType; typedef Matrix IntColVectorType; - typedef SparseMatrix LMatrixType; - typedef SparseMatrix UMatrixType; + typedef SparseMatrix LMatrixType; + typedef SparseMatrix UMatrixType; using Base::m_flags; using Base::m_status; diff --git a/Eigen/src/Sparse/TaucsSupport.h b/Eigen/src/Sparse/TaucsSupport.h index cbe3d0036..f2a9d19dc 100644 --- a/Eigen/src/Sparse/TaucsSupport.h +++ b/Eigen/src/Sparse/TaucsSupport.h @@ -50,13 +50,13 @@ taucs_ccs_matrix SparseMatrixBase::asTaucsMatrix() ei_assert(false && "Scalar type not supported by TAUCS"); } - if (Flags & UpperTriangular) + if (Flags & Upper) res.flags |= TAUCS_UPPER; - if (Flags & LowerTriangular) + if (Flags & Lower) res.flags |= TAUCS_LOWER; if (Flags & SelfAdjoint) res.flags |= (NumTraits::IsComplex ? TAUCS_HERMITIAN : TAUCS_SYMMETRIC); - else if ((Flags & UpperTriangular) || (Flags & LowerTriangular)) + else if ((Flags & Upper) || (Flags & Lower)) res.flags |= TAUCS_TRIANGULAR; return res; diff --git a/Eigen/src/Sparse/TriangularSolver.h b/Eigen/src/Sparse/TriangularSolver.h index 5b761e6ad..039424bf0 100644 --- a/Eigen/src/Sparse/TriangularSolver.h +++ b/Eigen/src/Sparse/TriangularSolver.h @@ -26,17 +26,17 @@ #define EIGEN_SPARSETRIANGULARSOLVER_H template::Flags) & RowMajorBit> struct ei_sparse_solve_triangular_selector; // forward substitution, row-major template -struct ei_sparse_solve_triangular_selector +struct ei_sparse_solve_triangular_selector { typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, Rhs& other) @@ -56,7 +56,7 @@ struct ei_sparse_solve_triangular_selector -struct ei_sparse_solve_triangular_selector +struct ei_sparse_solve_triangular_selector { typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, Rhs& other) @@ -88,7 +88,7 @@ struct ei_sparse_solve_triangular_selector -struct ei_sparse_solve_triangular_selector +struct ei_sparse_solve_triangular_selector { typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, Rhs& other) @@ -116,7 +116,7 @@ struct ei_sparse_solve_triangular_selector -struct ei_sparse_solve_triangular_selector +struct ei_sparse_solve_triangular_selector { typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, Rhs& other) @@ -145,7 +145,7 @@ struct ei_sparse_solve_triangular_selector::solveInPlace(MatrixBase::Flags & RowMajorBit }; @@ -194,10 +194,10 @@ SparseTriangularView::solve(const MatrixBase& // pure sparse path template struct ei_sparse_solve_triangular_sparse_selector; @@ -209,7 +209,7 @@ struct ei_sparse_solve_triangular_sparse_selector typedef typename Rhs::Scalar Scalar; static void run(const Lhs& lhs, Rhs& other) { - const bool IsLowerTriangular = (UpLo==LowerTriangular); + const bool IsLower = (UpLo==Lower); AmbiVector tempVector(other.rows()*2); tempVector.setBounds(0,other.rows()); @@ -227,9 +227,9 @@ struct ei_sparse_solve_triangular_sparse_selector tempVector.coeffRef(rhsIt.index()) = rhsIt.value(); } - for(int i=IsLowerTriangular?0:lhs.cols()-1; - IsLowerTriangular?i=0; - i+=IsLowerTriangular?1:-1) + for(int i=IsLower?0:lhs.cols()-1; + IsLower?i=0; + i+=IsLower?1:-1) { tempVector.restart(); Scalar& ci = tempVector.coeffRef(i); @@ -237,9 +237,9 @@ struct ei_sparse_solve_triangular_sparse_selector { // find typename Lhs::InnerIterator it(lhs, i); - if(!(Mode & UnitDiagBit)) + if(!(Mode & UnitDiag)) { - if (IsLowerTriangular) + if (IsLower) { ei_assert(it.index()==i); ci /= it.value(); @@ -248,7 +248,7 @@ struct ei_sparse_solve_triangular_sparse_selector ci /= lhs.coeff(i,i); } tempVector.restart(); - if (IsLowerTriangular) + if (IsLower) { if (it.index()==i) ++it; @@ -287,8 +287,8 @@ void SparseTriangularView::solveInPlace(SparseMatrixBase::Flags & RowMajorBit }; @@ -311,7 +311,7 @@ template template void SparseMatrixBase::solveTriangularInPlace(MatrixBase& other) const { - this->template triangular().solveInPlace(other); + this->template triangular().solveInPlace(other); } /** \deprecated */ diff --git a/Eigen/src/Sparse/UmfPackSupport.h b/Eigen/src/Sparse/UmfPackSupport.h index 1c7a7aaa8..cde924964 100644 --- a/Eigen/src/Sparse/UmfPackSupport.h +++ b/Eigen/src/Sparse/UmfPackSupport.h @@ -127,8 +127,8 @@ class SparseLU : public SparseLU typedef Matrix Vector; typedef Matrix IntRowVectorType; typedef Matrix IntColVectorType; - typedef SparseMatrix LMatrixType; - typedef SparseMatrix UMatrixType; + typedef SparseMatrix LMatrixType; + typedef SparseMatrix UMatrixType; using Base::m_flags; using Base::m_status; diff --git a/doc/A05_PortingFrom2To3.dox b/doc/A05_PortingFrom2To3.dox index e2dac4525..3c1952ebc 100644 --- a/doc/A05_PortingFrom2To3.dox +++ b/doc/A05_PortingFrom2To3.dox @@ -29,13 +29,30 @@ vec.head(length) vec.head() vec.tail(length) vec.tail() -\endcodeThis is a simple search and replace change. +\endcodeTrivial "search and replace". \code mat.cwise().XXX()\endcode\code mat.array().XXX()\endcodeSee \ref CoefficientWiseOperations. \code c = (a * b).lazy();\endcode\code c.noalias() = a * b;\endcodeSee \ref LazyVsNoalias. \code A.triangularSolveInPlace(X);\endcode\code A.triangularView().solveInPlace(X);\endcode + +\code +UpperTriangular +LowerTriangular +UnitUpperTriangular +UnitLowerTriangular +StrictlyUpperTriangular +StrictlyLowerTriangular +\endcode\code +Upper +Lower +UnitUpper +UnitLower +StrictlyUpper +StrictlyLower +\endcode +Trivial "search and replace". \section CoefficientWiseOperations Coefficient wise operations diff --git a/test/bandmatrix.cpp b/test/bandmatrix.cpp index e243dffe5..dc54812b9 100644 --- a/test/bandmatrix.cpp +++ b/test/bandmatrix.cpp @@ -64,8 +64,8 @@ template void bandmatrix(const MatrixType& _m) int a = std::max(0,cols-d-supers); int b = std::max(0,rows-d-subs); if(a>0) dm1.block(0,d+supers,rows,a).setZero(); - dm1.block(0,supers+1,cols-supers-1-a,cols-supers-1-a).template triangularView().setZero(); - dm1.block(subs+1,0,rows-subs-1-b,rows-subs-1-b).template triangularView().setZero(); + dm1.block(0,supers+1,cols-supers-1-a,cols-supers-1-a).template triangularView().setZero(); + dm1.block(subs+1,0,rows-subs-1-b,rows-subs-1-b).template triangularView().setZero(); if(b>0) dm1.block(d+subs,0,b,cols).setZero(); //std::cerr << m.m_data << "\n\n" << m.toDense() << "\n\n" << dm1 << "\n\n"; VERIFY_IS_APPROX(dm1,m.toDenseMatrix()); diff --git a/test/cholesky.cpp b/test/cholesky.cpp index c658b902c..1bb808d20 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -58,12 +58,12 @@ template void cholesky(const MatrixType& m) symm += a1 * a1.adjoint(); } - SquareMatrixType symmUp = symm.template triangularView(); - SquareMatrixType symmLo = symm.template triangularView(); + SquareMatrixType symmUp = symm.template triangularView(); + SquareMatrixType symmLo = symm.template triangularView(); // to test if really Cholesky only uses the upper triangular part, uncomment the following // FIXME: currently that fails !! - //symm.template part().setZero(); + //symm.template part().setZero(); #ifdef HAS_GSL // if (ei_is_same_type::ret) @@ -94,7 +94,7 @@ template void cholesky(const MatrixType& m) #endif { - LLT chollo(symmLo); + LLT chollo(symmLo); VERIFY_IS_APPROX(symm, chollo.matrixL().toDenseMatrix() * chollo.matrixL().adjoint().toDenseMatrix()); vecX = chollo.solve(vecB); VERIFY_IS_APPROX(symm * vecX, vecB); @@ -102,7 +102,7 @@ template void cholesky(const MatrixType& m) VERIFY_IS_APPROX(symm * matX, matB); // test the upper mode - LLT cholup(symmUp); + LLT cholup(symmUp); VERIFY_IS_APPROX(symm, cholup.matrixL().toDenseMatrix() * cholup.matrixL().adjoint().toDenseMatrix()); vecX = cholup.solve(vecB); VERIFY_IS_APPROX(symm * vecX, vecB); diff --git a/test/product_notemporary.cpp b/test/product_notemporary.cpp index 534d23d84..1da91e5d7 100644 --- a/test/product_notemporary.cpp +++ b/test/product_notemporary.cpp @@ -85,31 +85,31 @@ template void product_notemporary(const MatrixType& m) // NOTE this is because the Block expression is not handled yet by our expression analyser VERIFY_EVALUATION_COUNT(( m3.block(r0,r0,r1,r1).noalias() = s1 * m1.block(r0,c0,r1,c1) * (s1*m2).block(c0,r0,c1,r1) ), 1); - VERIFY_EVALUATION_COUNT( m3.noalias() -= (s1 * m1).template triangularView() * m2, 0); - VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView() * (m2+m2), 1); - VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView() * m2.adjoint(), 0); + VERIFY_EVALUATION_COUNT( m3.noalias() -= (s1 * m1).template triangularView() * m2, 0); + VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView() * (m2+m2), 1); + VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template triangularView() * m2.adjoint(), 0); - VERIFY_EVALUATION_COUNT( rm3.col(c0).noalias() = (s1 * m1.adjoint()).template triangularView() * (s2*m2.row(c0)).adjoint(), 0); + VERIFY_EVALUATION_COUNT( rm3.col(c0).noalias() = (s1 * m1.adjoint()).template triangularView() * (s2*m2.row(c0)).adjoint(), 0); - VERIFY_EVALUATION_COUNT( m1.template triangularView().solveInPlace(m3), 0); - VERIFY_EVALUATION_COUNT( m1.adjoint().template triangularView().solveInPlace(m3.transpose()), 0); + VERIFY_EVALUATION_COUNT( m1.template triangularView().solveInPlace(m3), 0); + VERIFY_EVALUATION_COUNT( m1.adjoint().template triangularView().solveInPlace(m3.transpose()), 0); - VERIFY_EVALUATION_COUNT( m3.noalias() -= (s1 * m1).adjoint().template selfadjointView() * (-m2*s3).adjoint(), 0); - VERIFY_EVALUATION_COUNT( m3.noalias() = s2 * m2.adjoint() * (s1 * m1.adjoint()).template selfadjointView(), 0); - VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template selfadjointView() * m2.adjoint(), 0); + VERIFY_EVALUATION_COUNT( m3.noalias() -= (s1 * m1).adjoint().template selfadjointView() * (-m2*s3).adjoint(), 0); + VERIFY_EVALUATION_COUNT( m3.noalias() = s2 * m2.adjoint() * (s1 * m1.adjoint()).template selfadjointView(), 0); + VERIFY_EVALUATION_COUNT( rm3.noalias() = (s1 * m1.adjoint()).template selfadjointView() * m2.adjoint(), 0); - VERIFY_EVALUATION_COUNT( m3.col(c0).noalias() = (s1 * m1).adjoint().template selfadjointView() * (-m2.row(c0)*s3).adjoint(), 0); - VERIFY_EVALUATION_COUNT( m3.col(c0).noalias() -= (s1 * m1).adjoint().template selfadjointView() * (-m2.row(c0)*s3).adjoint(), 0); + VERIFY_EVALUATION_COUNT( m3.col(c0).noalias() = (s1 * m1).adjoint().template selfadjointView() * (-m2.row(c0)*s3).adjoint(), 0); + VERIFY_EVALUATION_COUNT( m3.col(c0).noalias() -= (s1 * m1).adjoint().template selfadjointView() * (-m2.row(c0)*s3).adjoint(), 0); - VERIFY_EVALUATION_COUNT( m3.block(r0,c0,r1,c1).noalias() += m1.block(r0,r0,r1,r1).template selfadjointView() * (s1*m2.block(r0,c0,r1,c1)), 0); - VERIFY_EVALUATION_COUNT( m3.block(r0,c0,r1,c1).noalias() = m1.block(r0,r0,r1,r1).template selfadjointView() * m2.block(r0,c0,r1,c1), 0); + VERIFY_EVALUATION_COUNT( m3.block(r0,c0,r1,c1).noalias() += m1.block(r0,r0,r1,r1).template selfadjointView() * (s1*m2.block(r0,c0,r1,c1)), 0); + VERIFY_EVALUATION_COUNT( m3.block(r0,c0,r1,c1).noalias() = m1.block(r0,r0,r1,r1).template selfadjointView() * m2.block(r0,c0,r1,c1), 0); - VERIFY_EVALUATION_COUNT( m3.template selfadjointView().rankUpdate(m2.adjoint()), 0); + VERIFY_EVALUATION_COUNT( m3.template selfadjointView().rankUpdate(m2.adjoint()), 0); m3.resize(1,1); - VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template selfadjointView() * m2.block(r0,c0,r1,c1), 0); + VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template selfadjointView() * m2.block(r0,c0,r1,c1), 0); m3.resize(1,1); - VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template triangularView() * m2.block(r0,c0,r1,c1), 0); + VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template triangularView() * m2.block(r0,c0,r1,c1), 0); } void test_product_notemporary() diff --git a/test/product_selfadjoint.cpp b/test/product_selfadjoint.cpp index 2f3833a02..2027fc8e5 100644 --- a/test/product_selfadjoint.cpp +++ b/test/product_selfadjoint.cpp @@ -53,25 +53,25 @@ template void product_selfadjoint(const MatrixType& m) m1 = (m1.adjoint() + m1).eval(); // rank2 update - m2 = m1.template triangularView(); - m2.template selfadjointView().rankUpdate(v1,v2); - VERIFY_IS_APPROX(m2, (m1 + v1 * v2.adjoint()+ v2 * v1.adjoint()).template triangularView().toDenseMatrix()); + m2 = m1.template triangularView(); + m2.template selfadjointView().rankUpdate(v1,v2); + VERIFY_IS_APPROX(m2, (m1 + v1 * v2.adjoint()+ v2 * v1.adjoint()).template triangularView().toDenseMatrix()); - m2 = m1.template triangularView(); - m2.template selfadjointView().rankUpdate(-v1,s2*v2,s3); - VERIFY_IS_APPROX(m2, (m1 + (-s2*s3) * (v1 * v2.adjoint()+ v2 * v1.adjoint())).template triangularView().toDenseMatrix()); + m2 = m1.template triangularView(); + m2.template selfadjointView().rankUpdate(-v1,s2*v2,s3); + VERIFY_IS_APPROX(m2, (m1 + (-s2*s3) * (v1 * v2.adjoint()+ v2 * v1.adjoint())).template triangularView().toDenseMatrix()); - m2 = m1.template triangularView(); - m2.template selfadjointView().rankUpdate(-r1.adjoint(),r2.adjoint()*s3,s1); - VERIFY_IS_APPROX(m2, (m1 + (-s3*s1) * (r1.adjoint() * r2 + r2.adjoint() * r1)).template triangularView().toDenseMatrix()); + m2 = m1.template triangularView(); + m2.template selfadjointView().rankUpdate(-r1.adjoint(),r2.adjoint()*s3,s1); + VERIFY_IS_APPROX(m2, (m1 + (-s3*s1) * (r1.adjoint() * r2 + r2.adjoint() * r1)).template triangularView().toDenseMatrix()); if (rows>1) { - m2 = m1.template triangularView(); - m2.block(1,1,rows-1,cols-1).template selfadjointView().rankUpdate(v1.tail(rows-1),v2.head(cols-1)); + m2 = m1.template triangularView(); + m2.block(1,1,rows-1,cols-1).template selfadjointView().rankUpdate(v1.tail(rows-1),v2.head(cols-1)); m3 = m1; m3.block(1,1,rows-1,cols-1) += v1.tail(rows-1) * v2.head(cols-1).adjoint()+ v2.head(cols-1) * v1.tail(rows-1).adjoint(); - VERIFY_IS_APPROX(m2, m3.template triangularView().toDenseMatrix()); + VERIFY_IS_APPROX(m2, m3.template triangularView().toDenseMatrix()); } } diff --git a/test/product_symm.cpp b/test/product_symm.cpp index a9e055bd3..a0d80080f 100644 --- a/test/product_symm.cpp +++ b/test/product_symm.cpp @@ -28,10 +28,10 @@ template struct symm_extra { template static void run(M1& m1, M1& m2, M2& rhs2, M2& rhs22, M2& rhs23, Scalar s1, Scalar s2) { - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs22 = (rhs2) * (m2).template selfadjointView(), + m2 = m1.template triangularView(); + VERIFY_IS_APPROX(rhs22 = (rhs2) * (m2).template selfadjointView(), rhs23 = (rhs2) * (m1)); - VERIFY_IS_APPROX(rhs22 = (s2*rhs2) * (s1*m2).template selfadjointView(), + VERIFY_IS_APPROX(rhs22 = (s2*rhs2) * (s1*m2).template selfadjointView(), rhs23 = (s2*rhs2) * (s1*m1)); } }; @@ -65,38 +65,38 @@ template void symm(int size = Size, in Scalar s1 = ei_random(), s2 = ei_random(); - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs1), + m2 = m1.template triangularView(); + VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs1), rhs13 = (s1*m1) * (s2*rhs1)); - m2 = m1.template triangularView(); rhs12.setRandom(); rhs13 = rhs12; - VERIFY_IS_APPROX(rhs12 += (s1*m2).template selfadjointView() * (s2*rhs1), + m2 = m1.template triangularView(); rhs12.setRandom(); rhs13 = rhs12; + VERIFY_IS_APPROX(rhs12 += (s1*m2).template selfadjointView() * (s2*rhs1), rhs13 += (s1*m1) * (s2*rhs1)); - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs2.adjoint()), + m2 = m1.template triangularView(); + VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs2.adjoint()), rhs13 = (s1*m1) * (s2*rhs2.adjoint())); - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs2.adjoint()), + m2 = m1.template triangularView(); + VERIFY_IS_APPROX(rhs12 = (s1*m2).template selfadjointView() * (s2*rhs2.adjoint()), rhs13 = (s1*m1) * (s2*rhs2.adjoint())); - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs12 = (s1*m2.adjoint()).template selfadjointView() * (s2*rhs2.adjoint()), + m2 = m1.template triangularView(); + VERIFY_IS_APPROX(rhs12 = (s1*m2.adjoint()).template selfadjointView() * (s2*rhs2.adjoint()), rhs13 = (s1*m1.adjoint()) * (s2*rhs2.adjoint())); // test row major = <...> - m2 = m1.template triangularView(); rhs12.setRandom(); rhs13 = rhs12; - VERIFY_IS_APPROX(rhs12 -= (s1*m2).template selfadjointView() * (s2*rhs3), + m2 = m1.template triangularView(); rhs12.setRandom(); rhs13 = rhs12; + VERIFY_IS_APPROX(rhs12 -= (s1*m2).template selfadjointView() * (s2*rhs3), rhs13 -= (s1*m1) * (s2 * rhs3)); - m2 = m1.template triangularView(); - VERIFY_IS_APPROX(rhs12 = (s1*m2.adjoint()).template selfadjointView() * (s2*rhs3).conjugate(), + m2 = m1.template triangularView(); + VERIFY_IS_APPROX(rhs12 = (s1*m2.adjoint()).template selfadjointView() * (s2*rhs3).conjugate(), rhs13 = (s1*m1.adjoint()) * (s2*rhs3).conjugate()); - m2 = m1.template triangularView(); rhs13 = rhs12; - VERIFY_IS_APPROX(rhs12.noalias() += s1 * ((m2.adjoint()).template selfadjointView() * (s2*rhs3).conjugate()), + m2 = m1.template triangularView(); rhs13 = rhs12; + VERIFY_IS_APPROX(rhs12.noalias() += s1 * ((m2.adjoint()).template selfadjointView() * (s2*rhs3).conjugate()), rhs13 += (s1*m1.adjoint()) * (s2*rhs3).conjugate()); // test matrix * selfadjoint diff --git a/test/product_syrk.cpp b/test/product_syrk.cpp index 9f6aec0e2..e597ac88a 100644 --- a/test/product_syrk.cpp +++ b/test/product_syrk.cpp @@ -45,28 +45,28 @@ template void syrk(const MatrixType& m) Scalar s1 = ei_random(); m2.setZero(); - VERIFY_IS_APPROX((m2.template selfadjointView().rankUpdate(rhs2,s1)._expression()), - ((s1 * rhs2 * rhs2.adjoint()).eval().template triangularView().toDenseMatrix())); + VERIFY_IS_APPROX((m2.template selfadjointView().rankUpdate(rhs2,s1)._expression()), + ((s1 * rhs2 * rhs2.adjoint()).eval().template triangularView().toDenseMatrix())); m2.setZero(); - VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs2,s1)._expression(), - (s1 * rhs2 * rhs2.adjoint()).eval().template triangularView().toDenseMatrix()); + VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs2,s1)._expression(), + (s1 * rhs2 * rhs2.adjoint()).eval().template triangularView().toDenseMatrix()); m2.setZero(); - VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs1.adjoint(),s1)._expression(), - (s1 * rhs1.adjoint() * rhs1).eval().template triangularView().toDenseMatrix()); + VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs1.adjoint(),s1)._expression(), + (s1 * rhs1.adjoint() * rhs1).eval().template triangularView().toDenseMatrix()); m2.setZero(); - VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs1.adjoint(),s1)._expression(), - (s1 * rhs1.adjoint() * rhs1).eval().template triangularView().toDenseMatrix()); + VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs1.adjoint(),s1)._expression(), + (s1 * rhs1.adjoint() * rhs1).eval().template triangularView().toDenseMatrix()); m2.setZero(); - VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs3.adjoint(),s1)._expression(), - (s1 * rhs3.adjoint() * rhs3).eval().template triangularView().toDenseMatrix()); + VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs3.adjoint(),s1)._expression(), + (s1 * rhs3.adjoint() * rhs3).eval().template triangularView().toDenseMatrix()); m2.setZero(); - VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs3.adjoint(),s1)._expression(), - (s1 * rhs3.adjoint() * rhs3).eval().template triangularView().toDenseMatrix()); + VERIFY_IS_APPROX(m2.template selfadjointView().rankUpdate(rhs3.adjoint(),s1)._expression(), + (s1 * rhs3.adjoint() * rhs3).eval().template triangularView().toDenseMatrix()); } void test_product_syrk() diff --git a/test/product_trmm.cpp b/test/product_trmm.cpp index 5f92391e6..69e97f7aa 100644 --- a/test/product_trmm.cpp +++ b/test/product_trmm.cpp @@ -36,27 +36,27 @@ template void trmm(int size,int othersize) s2 = ei_random(); tri.setRandom(); - loTri = tri.template triangularView(); - upTri = tri.template triangularView(); + loTri = tri.template triangularView(); + upTri = tri.template triangularView(); ge1.setRandom(); ge2.setRandom(); - VERIFY_IS_APPROX( ge3 = tri.template triangularView() * ge1, loTri * ge1); - VERIFY_IS_APPROX(rge3 = tri.template triangularView() * ge1, loTri * ge1); - VERIFY_IS_APPROX( ge3 = tri.template triangularView() * ge1, upTri * ge1); - VERIFY_IS_APPROX(rge3 = tri.template triangularView() * ge1, upTri * ge1); - VERIFY_IS_APPROX( ge3 = (s1*tri.adjoint()).template triangularView() * (s2*ge1), s1*loTri.adjoint() * (s2*ge1)); - VERIFY_IS_APPROX(rge3 = tri.adjoint().template triangularView() * ge1, loTri.adjoint() * ge1); - VERIFY_IS_APPROX( ge3 = tri.adjoint().template triangularView() * ge1, upTri.adjoint() * ge1); - VERIFY_IS_APPROX(rge3 = tri.adjoint().template triangularView() * ge1, upTri.adjoint() * ge1); - VERIFY_IS_APPROX( ge3 = tri.template triangularView() * ge2.adjoint(), loTri * ge2.adjoint()); - VERIFY_IS_APPROX(rge3 = tri.template triangularView() * ge2.adjoint(), loTri * ge2.adjoint()); - VERIFY_IS_APPROX( ge3 = tri.template triangularView() * ge2.adjoint(), upTri * ge2.adjoint()); - VERIFY_IS_APPROX(rge3 = tri.template triangularView() * ge2.adjoint(), upTri * ge2.adjoint()); - VERIFY_IS_APPROX( ge3 = (s1*tri).adjoint().template triangularView() * ge2.adjoint(), ei_conj(s1) * loTri.adjoint() * ge2.adjoint()); - VERIFY_IS_APPROX(rge3 = tri.adjoint().template triangularView() * ge2.adjoint(), loTri.adjoint() * ge2.adjoint()); - VERIFY_IS_APPROX( ge3 = tri.adjoint().template triangularView() * ge2.adjoint(), upTri.adjoint() * ge2.adjoint()); - VERIFY_IS_APPROX(rge3 = tri.adjoint().template triangularView() * ge2.adjoint(), upTri.adjoint() * ge2.adjoint()); + VERIFY_IS_APPROX( ge3 = tri.template triangularView() * ge1, loTri * ge1); + VERIFY_IS_APPROX(rge3 = tri.template triangularView() * ge1, loTri * ge1); + VERIFY_IS_APPROX( ge3 = tri.template triangularView() * ge1, upTri * ge1); + VERIFY_IS_APPROX(rge3 = tri.template triangularView() * ge1, upTri * ge1); + VERIFY_IS_APPROX( ge3 = (s1*tri.adjoint()).template triangularView() * (s2*ge1), s1*loTri.adjoint() * (s2*ge1)); + VERIFY_IS_APPROX(rge3 = tri.adjoint().template triangularView() * ge1, loTri.adjoint() * ge1); + VERIFY_IS_APPROX( ge3 = tri.adjoint().template triangularView() * ge1, upTri.adjoint() * ge1); + VERIFY_IS_APPROX(rge3 = tri.adjoint().template triangularView() * ge1, upTri.adjoint() * ge1); + VERIFY_IS_APPROX( ge3 = tri.template triangularView() * ge2.adjoint(), loTri * ge2.adjoint()); + VERIFY_IS_APPROX(rge3 = tri.template triangularView() * ge2.adjoint(), loTri * ge2.adjoint()); + VERIFY_IS_APPROX( ge3 = tri.template triangularView() * ge2.adjoint(), upTri * ge2.adjoint()); + VERIFY_IS_APPROX(rge3 = tri.template triangularView() * ge2.adjoint(), upTri * ge2.adjoint()); + VERIFY_IS_APPROX( ge3 = (s1*tri).adjoint().template triangularView() * ge2.adjoint(), ei_conj(s1) * loTri.adjoint() * ge2.adjoint()); + VERIFY_IS_APPROX(rge3 = tri.adjoint().template triangularView() * ge2.adjoint(), loTri.adjoint() * ge2.adjoint()); + VERIFY_IS_APPROX( ge3 = tri.adjoint().template triangularView() * ge2.adjoint(), upTri.adjoint() * ge2.adjoint()); + VERIFY_IS_APPROX(rge3 = tri.adjoint().template triangularView() * ge2.adjoint(), upTri.adjoint() * ge2.adjoint()); } void test_product_trmm() diff --git a/test/product_trmv.cpp b/test/product_trmv.cpp index 5016a5b1f..f0962557a 100644 --- a/test/product_trmv.cpp +++ b/test/product_trmv.cpp @@ -44,37 +44,37 @@ template void trmv(const MatrixType& m) m1 = MatrixType::Random(rows, cols); // check with a column-major matrix - m3 = m1.template triangularView(); - VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); - m3 = m1.template triangularView(); - VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); - m3 = m1.template triangularView(); - VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); - m3 = m1.template triangularView(); - VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3 * v1).isApprox(m1.template triangularView() * v1, largerEps)); // check conjugated and scalar multiple expressions (col-major) - m3 = m1.template triangularView(); - VERIFY(((s1*m3).conjugate() * v1).isApprox((s1*m1).conjugate().template triangularView() * v1, largerEps)); - m3 = m1.template triangularView(); - VERIFY((m3.conjugate() * v1.conjugate()).isApprox(m1.conjugate().template triangularView() * v1.conjugate(), largerEps)); + m3 = m1.template triangularView(); + VERIFY(((s1*m3).conjugate() * v1).isApprox((s1*m1).conjugate().template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3.conjugate() * v1.conjugate()).isApprox(m1.conjugate().template triangularView() * v1.conjugate(), largerEps)); // check with a row-major matrix - m3 = m1.template triangularView(); - VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); - m3 = m1.template triangularView(); - VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); - m3 = m1.template triangularView(); - VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); - m3 = m1.template triangularView(); - VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3.transpose() * v1).isApprox(m1.transpose().template triangularView() * v1, largerEps)); // check conjugated and scalar multiple expressions (row-major) - m3 = m1.template triangularView(); - VERIFY((m3.adjoint() * v1).isApprox(m1.adjoint().template triangularView() * v1, largerEps)); - m3 = m1.template triangularView(); - VERIFY((m3.adjoint() * (s1*v1.conjugate())).isApprox(m1.adjoint().template triangularView() * (s1*v1.conjugate()), largerEps)); - m3 = m1.template triangularView(); + m3 = m1.template triangularView(); + VERIFY((m3.adjoint() * v1).isApprox(m1.adjoint().template triangularView() * v1, largerEps)); + m3 = m1.template triangularView(); + VERIFY((m3.adjoint() * (s1*v1.conjugate())).isApprox(m1.adjoint().template triangularView() * (s1*v1.conjugate()), largerEps)); + m3 = m1.template triangularView(); // TODO check with sub-matrices } diff --git a/test/product_trsolve.cpp b/test/product_trsolve.cpp index 4477a29d1..6e916230e 100644 --- a/test/product_trsolve.cpp +++ b/test/product_trsolve.cpp @@ -49,28 +49,28 @@ template void trsolve(int size=Size,int cols cmLhs.setRandom(); cmLhs *= static_cast(0.1); cmLhs.diagonal().array() += static_cast(1); rmLhs.setRandom(); rmLhs *= static_cast(0.1); rmLhs.diagonal().array() += static_cast(1); - VERIFY_TRSM(cmLhs.conjugate().template triangularView(), cmRhs); - VERIFY_TRSM(cmLhs .template triangularView(), cmRhs); - VERIFY_TRSM(cmLhs .template triangularView(), rmRhs); - VERIFY_TRSM(cmLhs.conjugate().template triangularView(), rmRhs); + VERIFY_TRSM(cmLhs.conjugate().template triangularView(), cmRhs); + VERIFY_TRSM(cmLhs .template triangularView(), cmRhs); + VERIFY_TRSM(cmLhs .template triangularView(), rmRhs); + VERIFY_TRSM(cmLhs.conjugate().template triangularView(), rmRhs); - VERIFY_TRSM(cmLhs.conjugate().template triangularView(), cmRhs); - VERIFY_TRSM(cmLhs .template triangularView(), rmRhs); + VERIFY_TRSM(cmLhs.conjugate().template triangularView(), cmRhs); + VERIFY_TRSM(cmLhs .template triangularView(), rmRhs); - VERIFY_TRSM(rmLhs .template triangularView(), cmRhs); - VERIFY_TRSM(rmLhs.conjugate().template triangularView(), rmRhs); + VERIFY_TRSM(rmLhs .template triangularView(), cmRhs); + VERIFY_TRSM(rmLhs.conjugate().template triangularView(), rmRhs); - VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView(), cmRhs); - VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView(), cmRhs); - VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView(), rmRhs); - VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView(), rmRhs); + VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView(), cmRhs); + VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView(), cmRhs); + VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView(), rmRhs); + VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView(), rmRhs); - VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView(), cmRhs); - VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView(), rmRhs); + VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView(), cmRhs); + VERIFY_TRSM_ONTHERIGHT(cmLhs .template triangularView(), rmRhs); - VERIFY_TRSM_ONTHERIGHT(rmLhs .template triangularView(), cmRhs); - VERIFY_TRSM_ONTHERIGHT(rmLhs.conjugate().template triangularView(), rmRhs); + VERIFY_TRSM_ONTHERIGHT(rmLhs .template triangularView(), cmRhs); + VERIFY_TRSM_ONTHERIGHT(rmLhs.conjugate().template triangularView(), rmRhs); } void test_product_trsolve() diff --git a/test/qr_colpivoting.cpp b/test/qr_colpivoting.cpp index 8b56cd296..16eb27c52 100644 --- a/test/qr_colpivoting.cpp +++ b/test/qr_colpivoting.cpp @@ -47,7 +47,7 @@ template void qr() MatrixQType q = qr.householderQ(); VERIFY_IS_UNITARY(q); - MatrixType r = qr.matrixQR().template triangularView(); + MatrixType r = qr.matrixQR().template triangularView(); MatrixType c = q * r * qr.colsPermutation().inverse(); VERIFY_IS_APPROX(m1, c); @@ -72,7 +72,7 @@ template void qr_fixedsize() VERIFY(!qr.isInvertible()); VERIFY(!qr.isSurjective()); - Matrix r = qr.matrixQR().template triangularView(); + Matrix r = qr.matrixQR().template triangularView(); Matrix c = qr.householderQ() * r * qr.colsPermutation().inverse(); VERIFY_IS_APPROX(m1, c); diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp index 00c2cdf74..04e089784 100644 --- a/test/sparse_product.cpp +++ b/test/sparse_product.cpp @@ -115,9 +115,9 @@ template void sparse_product(const SparseMatrixType& VERIFY_IS_APPROX(mS, refS); VERIFY_IS_APPROX(x=mS*b, refX=refS*b); - VERIFY_IS_APPROX(x=mUp.template selfadjointView()*b, refX=refS*b); - VERIFY_IS_APPROX(x=mLo.template selfadjointView()*b, refX=refS*b); - VERIFY_IS_APPROX(x=mS.template selfadjointView()*b, refX=refS*b); + VERIFY_IS_APPROX(x=mUp.template selfadjointView()*b, refX=refS*b); + VERIFY_IS_APPROX(x=mLo.template selfadjointView()*b, refX=refS*b); + VERIFY_IS_APPROX(x=mS.template selfadjointView()*b, refX=refS*b); } } diff --git a/test/sparse_solvers.cpp b/test/sparse_solvers.cpp index 059747c3d..fab2ab56e 100644 --- a/test/sparse_solvers.cpp +++ b/test/sparse_solvers.cpp @@ -65,23 +65,23 @@ template void sparse_solvers(int rows, int cols) // lower - dense initSparse(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular, &zeroCoords, &nonzeroCoords); - VERIFY_IS_APPROX(refMat2.template triangularView().solve(vec2), - m2.template triangularView().solve(vec3)); + VERIFY_IS_APPROX(refMat2.template triangularView().solve(vec2), + m2.template triangularView().solve(vec3)); // upper - dense initSparse(density, refMat2, m2, ForceNonZeroDiag|MakeUpperTriangular, &zeroCoords, &nonzeroCoords); - VERIFY_IS_APPROX(refMat2.template triangularView().solve(vec2), - m2.template triangularView().solve(vec3)); + VERIFY_IS_APPROX(refMat2.template triangularView().solve(vec2), + m2.template triangularView().solve(vec3)); // lower - transpose initSparse(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular, &zeroCoords, &nonzeroCoords); - VERIFY_IS_APPROX(refMat2.transpose().template triangularView().solve(vec2), - m2.transpose().template triangularView().solve(vec3)); + VERIFY_IS_APPROX(refMat2.transpose().template triangularView().solve(vec2), + m2.transpose().template triangularView().solve(vec3)); // upper - transpose initSparse(density, refMat2, m2, ForceNonZeroDiag|MakeUpperTriangular, &zeroCoords, &nonzeroCoords); - VERIFY_IS_APPROX(refMat2.transpose().template triangularView().solve(vec2), - m2.transpose().template triangularView().solve(vec3)); + VERIFY_IS_APPROX(refMat2.transpose().template triangularView().solve(vec2), + m2.transpose().template triangularView().solve(vec3)); SparseMatrix matB(rows, rows); DenseMatrix refMatB = DenseMatrix::Zero(rows, rows); @@ -89,21 +89,21 @@ template void sparse_solvers(int rows, int cols) // lower - sparse initSparse(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular); initSparse(density, refMatB, matB); - refMat2.template triangularView().solveInPlace(refMatB); - m2.template triangularView().solveInPlace(matB); + refMat2.template triangularView().solveInPlace(refMatB); + m2.template triangularView().solveInPlace(matB); VERIFY_IS_APPROX(matB.toDense(), refMatB); // upper - sparse initSparse(density, refMat2, m2, ForceNonZeroDiag|MakeUpperTriangular); initSparse(density, refMatB, matB); - refMat2.template triangularView().solveInPlace(refMatB); - m2.template triangularView().solveInPlace(matB); + refMat2.template triangularView().solveInPlace(refMatB); + m2.template triangularView().solveInPlace(matB); VERIFY_IS_APPROX(matB, refMatB); // test deprecated API initSparse(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular, &zeroCoords, &nonzeroCoords); - VERIFY_IS_APPROX(refMat2.template triangularView().solve(vec2), - m2.template triangularView().solve(vec3)); + VERIFY_IS_APPROX(refMat2.template triangularView().solve(vec2), + m2.template triangularView().solve(vec3)); } // test LLT @@ -118,29 +118,28 @@ template void sparse_solvers(int rows, int cols) initSPD(density, refMat2, m2); refX = refMat2.llt().solve(b); - typedef SparseMatrix SparseSelfAdjointMatrix; if (!NumTraits::IsComplex) { x = b; - SparseLLT (m2).solveInPlace(x); + SparseLLT > (m2).solveInPlace(x); VERIFY(refX.isApprox(x,test_precision()) && "LLT: default"); } #ifdef EIGEN_CHOLMOD_SUPPORT x = b; - SparseLLT(m2).solveInPlace(x); + SparseLLT ,Cholmod>(m2).solveInPlace(x); VERIFY(refX.isApprox(x,test_precision()) && "LLT: cholmod"); #endif #ifdef EIGEN_TAUCS_SUPPORT x = b; - SparseLLT(m2,IncompleteFactorization).solveInPlace(x); + SparseLLT ,Taucs>(m2,IncompleteFactorization).solveInPlace(x); VERIFY(refX.isApprox(x,test_precision()) && "LLT: taucs (IncompleteFactorization)"); // TODO fix TAUCS with complexes x = b; - SparseLLT(m2,SupernodalMultifrontal).solveInPlace(x); + SparseLLT ,Taucs>(m2,SupernodalMultifrontal).solveInPlace(x); VERIFY(refX.isApprox(x,test_precision()) && "LLT: taucs (SupernodalMultifrontal)"); x = b; - SparseLLT(m2,SupernodalLeftLooking).solveInPlace(x); + SparseLLT ,Taucs>(m2,SupernodalLeftLooking).solveInPlace(x); VERIFY(refX.isApprox(x,test_precision()) && "LLT: taucs (SupernodalLeftLooking)"); #endif } @@ -161,7 +160,7 @@ template void sparse_solvers(int rows, int cols) refMat2.diagonal() *= 0.5; refX = refMat2.llt().solve(b); // FIXME use LLT to compute the reference because LDLT seems to fail with large matrices - typedef SparseMatrix SparseSelfAdjointMatrix; + typedef SparseMatrix SparseSelfAdjointMatrix; x = b; SparseLDLT ldlt(m2); if (ldlt.succeeded()) diff --git a/test/triangular.cpp b/test/triangular.cpp index 0de9f5841..2903e247c 100644 --- a/test/triangular.cpp +++ b/test/triangular.cpp @@ -53,14 +53,14 @@ template void triangular_square(const MatrixType& m) v2 = VectorType::Random(rows), vzero = VectorType::Zero(rows); - MatrixType m1up = m1.template triangularView(); - MatrixType m2up = m2.template triangularView(); + MatrixType m1up = m1.template triangularView(); + MatrixType m2up = m2.template triangularView(); if (rows*cols>1) { - VERIFY(m1up.isUpperTriangular()); - VERIFY(m2up.transpose().isLowerTriangular()); - VERIFY(!m2.isLowerTriangular()); + VERIFY(m1up.isUpper()); + VERIFY(m2up.transpose().isLower()); + VERIFY(!m2.isLower()); } // VERIFY_IS_APPROX(m1up.transpose() * m2, m1.upper().transpose().lower() * m2); @@ -68,20 +68,20 @@ template void triangular_square(const MatrixType& m) // test overloaded operator+= r1.setZero(); r2.setZero(); - r1.template triangularView() += m1; + r1.template triangularView() += m1; r2 += m1up; VERIFY_IS_APPROX(r1,r2); // test overloaded operator= m1.setZero(); - m1.template triangularView() = m2.transpose() + m2; + m1.template triangularView() = m2.transpose() + m2; m3 = m2.transpose() + m2; - VERIFY_IS_APPROX(m3.template triangularView().transpose().toDenseMatrix(), m1); + VERIFY_IS_APPROX(m3.template triangularView().transpose().toDenseMatrix(), m1); // test overloaded operator= m1.setZero(); - m1.template triangularView() = m2.transpose() + m2; - VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); + m1.template triangularView() = m2.transpose() + m2; + VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); m1 = MatrixType::Random(rows, cols); for (int i=0; i void triangular_square(const MatrixType& m) Transpose trm4(m4); // test back and forward subsitution with a vector as the rhs - m3 = m1.template triangularView(); - VERIFY(v2.isApprox(m3.adjoint() * (m1.adjoint().template triangularView().solve(v2)), largerEps)); - m3 = m1.template triangularView(); - VERIFY(v2.isApprox(m3.transpose() * (m1.transpose().template triangularView().solve(v2)), largerEps)); - m3 = m1.template triangularView(); - VERIFY(v2.isApprox(m3 * (m1.template triangularView().solve(v2)), largerEps)); - m3 = m1.template triangularView(); - VERIFY(v2.isApprox(m3.conjugate() * (m1.conjugate().template triangularView().solve(v2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(v2.isApprox(m3.adjoint() * (m1.adjoint().template triangularView().solve(v2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(v2.isApprox(m3.transpose() * (m1.transpose().template triangularView().solve(v2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(v2.isApprox(m3 * (m1.template triangularView().solve(v2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(v2.isApprox(m3.conjugate() * (m1.conjugate().template triangularView().solve(v2)), largerEps)); // test back and forward subsitution with a matrix as the rhs - m3 = m1.template triangularView(); - VERIFY(m2.isApprox(m3.adjoint() * (m1.adjoint().template triangularView().solve(m2)), largerEps)); - m3 = m1.template triangularView(); - VERIFY(m2.isApprox(m3.transpose() * (m1.transpose().template triangularView().solve(m2)), largerEps)); - m3 = m1.template triangularView(); - VERIFY(m2.isApprox(m3 * (m1.template triangularView().solve(m2)), largerEps)); - m3 = m1.template triangularView(); - VERIFY(m2.isApprox(m3.conjugate() * (m1.conjugate().template triangularView().solve(m2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(m2.isApprox(m3.adjoint() * (m1.adjoint().template triangularView().solve(m2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(m2.isApprox(m3.transpose() * (m1.transpose().template triangularView().solve(m2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(m2.isApprox(m3 * (m1.template triangularView().solve(m2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(m2.isApprox(m3.conjugate() * (m1.conjugate().template triangularView().solve(m2)), largerEps)); // check M * inv(L) using in place API m4 = m3; - m3.transpose().template triangularView().solveInPlace(trm4); + m3.transpose().template triangularView().solveInPlace(trm4); VERIFY(m4.cwiseAbs().isIdentity(test_precision())); // check M * inv(U) using in place API - m3 = m1.template triangularView(); + m3 = m1.template triangularView(); m4 = m3; - m3.transpose().template triangularView().solveInPlace(trm4); + m3.transpose().template triangularView().solveInPlace(trm4); VERIFY(m4.cwiseAbs().isIdentity(test_precision())); // check solve with unit diagonal - m3 = m1.template triangularView(); - VERIFY(m2.isApprox(m3 * (m1.template triangularView().solve(m2)), largerEps)); + m3 = m1.template triangularView(); + VERIFY(m2.isApprox(m3 * (m1.template triangularView().solve(m2)), largerEps)); -// VERIFY(( m1.template triangularView() -// * m2.template triangularView()).isUpperTriangular()); +// VERIFY(( m1.template triangularView() +// * m2.template triangularView()).isUpper()); // test swap m1.setOnes(); m2.setZero(); - m2.template triangularView().swap(m1); + m2.template triangularView().swap(m1); m3.setZero(); - m3.template triangularView().setOnes(); + m3.template triangularView().setOnes(); VERIFY_IS_APPROX(m2,m3); } @@ -165,69 +165,69 @@ template void triangular_rect(const MatrixType& m) v2 = VectorType::Random(rows), vzero = VectorType::Zero(rows); - MatrixType m1up = m1.template triangularView(); - MatrixType m2up = m2.template triangularView(); + MatrixType m1up = m1.template triangularView(); + MatrixType m2up = m2.template triangularView(); if (rows*cols>1) { - VERIFY(m1up.isUpperTriangular()); - VERIFY(m2up.transpose().isLowerTriangular()); - VERIFY(!m2.isLowerTriangular()); + VERIFY(m1up.isUpper()); + VERIFY(m2up.transpose().isLower()); + VERIFY(!m2.isLower()); } // test overloaded operator+= r1.setZero(); r2.setZero(); - r1.template triangularView() += m1; + r1.template triangularView() += m1; r2 += m1up; VERIFY_IS_APPROX(r1,r2); // test overloaded operator= m1.setZero(); - m1.template triangularView() = 3 * m2; + m1.template triangularView() = 3 * m2; m3 = 3 * m2; - VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); + VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); m1.setZero(); - m1.template triangularView() = 3 * m2; - VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); + m1.template triangularView() = 3 * m2; + VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); m1.setZero(); - m1.template triangularView() = 3 * m2; - VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); + m1.template triangularView() = 3 * m2; + VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); m1.setZero(); - m1.template triangularView() = 3 * m2; - VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); + m1.template triangularView() = 3 * m2; + VERIFY_IS_APPROX(m3.template triangularView().toDenseMatrix(), m1); m1.setRandom(); - m2 = m1.template triangularView(); - VERIFY(m2.isUpperTriangular()); - VERIFY(!m2.isLowerTriangular()); - m2 = m1.template triangularView(); - VERIFY(m2.isUpperTriangular()); + m2 = m1.template triangularView(); + VERIFY(m2.isUpper()); + VERIFY(!m2.isLower()); + m2 = m1.template triangularView(); + VERIFY(m2.isUpper()); VERIFY(m2.diagonal().isMuchSmallerThan(RealScalar(1))); - m2 = m1.template triangularView(); - VERIFY(m2.isUpperTriangular()); + m2 = m1.template triangularView(); + VERIFY(m2.isUpper()); m2.diagonal().array() -= Scalar(1); VERIFY(m2.diagonal().isMuchSmallerThan(RealScalar(1))); - m2 = m1.template triangularView(); - VERIFY(m2.isLowerTriangular()); - VERIFY(!m2.isUpperTriangular()); - m2 = m1.template triangularView(); - VERIFY(m2.isLowerTriangular()); + m2 = m1.template triangularView(); + VERIFY(m2.isLower()); + VERIFY(!m2.isUpper()); + m2 = m1.template triangularView(); + VERIFY(m2.isLower()); VERIFY(m2.diagonal().isMuchSmallerThan(RealScalar(1))); - m2 = m1.template triangularView(); - VERIFY(m2.isLowerTriangular()); + m2 = m1.template triangularView(); + VERIFY(m2.isLower()); m2.diagonal().array() -= Scalar(1); VERIFY(m2.diagonal().isMuchSmallerThan(RealScalar(1))); // test swap m1.setOnes(); m2.setZero(); - m2.template triangularView().swap(m1); + m2.template triangularView().swap(m1); m3.setZero(); - m3.template triangularView().setOnes(); + m3.template triangularView().setOnes(); VERIFY_IS_APPROX(m2,m3); }