From aa8b8976075823636b7a266cb6307dbba2ee2705 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 19 Apr 2013 14:03:16 +0200 Subject: document the evaluation order of the comma initializer --- Eigen/src/Core/CommaInitializer.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Eigen') diff --git a/Eigen/src/Core/CommaInitializer.h b/Eigen/src/Core/CommaInitializer.h index f20c1774c..a96867af4 100644 --- a/Eigen/src/Core/CommaInitializer.h +++ b/Eigen/src/Core/CommaInitializer.h @@ -118,6 +118,8 @@ struct CommaInitializer * * Example: \include MatrixBase_set.cpp * Output: \verbinclude MatrixBase_set.out + * + * \note According the c++ standard, the argument expressions of this comma initializer are evaluated in arbitrary order. * * \sa CommaInitializer::finished(), class CommaInitializer */ -- cgit v1.2.3 From fcdbfabf7a712299edaed206dafaada0d8f72b92 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 3 May 2013 14:28:37 +0200 Subject: Fix setFromTripplet with empty inputs --- Eigen/src/SparseCore/SparseMatrix.h | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index dc57f77fc..e9e285f35 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -911,19 +911,22 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa typedef typename SparseMatrixType::Scalar Scalar; SparseMatrix trMat(mat.rows(),mat.cols()); - // pass 1: count the nnz per inner-vector - VectorXi wi(trMat.outerSize()); - wi.setZero(); - for(InputIterator it(begin); it!=end; ++it) - wi(IsRowMajor ? it->col() : it->row())++; - - // pass 2: insert all the elements into trMat - trMat.reserve(wi); - for(InputIterator it(begin); it!=end; ++it) - trMat.insertBackUncompressed(it->row(),it->col()) = it->value(); - - // pass 3: - trMat.sumupDuplicates(); + if(begincol() : it->row())++; + + // pass 2: insert all the elements into trMat + trMat.reserve(wi); + for(InputIterator it(begin); it!=end; ++it) + trMat.insertBackUncompressed(it->row(),it->col()) = it->value(); + + // pass 3: + trMat.sumupDuplicates(); + } // pass 4: transposed copy -> implicit sorting mat = trMat; -- cgit v1.2.3 From 43bb94236589168914f9e3cf742f7eaa188c5dba Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 13 May 2013 10:39:50 +0200 Subject: Add missing support for x.noalias() = ReturnByValue<...> --- Eigen/src/Core/NoAlias.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Eigen') diff --git a/Eigen/src/Core/NoAlias.h b/Eigen/src/Core/NoAlias.h index 0112c865b..768bfb18c 100644 --- a/Eigen/src/Core/NoAlias.h +++ b/Eigen/src/Core/NoAlias.h @@ -80,6 +80,10 @@ class NoAlias template EIGEN_STRONG_INLINE ExpressionType& operator-=(const CoeffBasedProduct& other) { return m_expression.derived() -= CoeffBasedProduct(other.lhs(), other.rhs()); } + + template + ExpressionType& operator=(const ReturnByValue& func) + { return m_expression = func; } #endif ExpressionType& expression() const -- cgit v1.2.3 From 122b16d841eac3b0c5f6cf1a1d6ee6616723dc08 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Mon, 13 May 2013 13:04:12 +0200 Subject: fix memory leak from Cholmod data in SPQR support --- Eigen/src/SPQRSupport/SuiteSparseQRSupport.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h b/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h index 0ffb894f6..ff304a546 100644 --- a/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h +++ b/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h @@ -64,7 +64,7 @@ class SPQR typedef PermutationMatrix PermutationType; public: SPQR() - : m_ordering(SPQR_ORDERING_DEFAULT), + : m_ordering(SPQR_ORDERING_AMD), m_allow_tol(SPQR_DEFAULT_TOL), m_tolerance (NumTraits::epsilon()) { @@ -72,7 +72,7 @@ class SPQR } SPQR(const _MatrixType& matrix) - : m_ordering(SPQR_ORDERING_DEFAULT), + : m_ordering(SPQR_ORDERING_AMD), m_allow_tol(SPQR_DEFAULT_TOL), m_tolerance (NumTraits::epsilon()) { @@ -83,10 +83,12 @@ class SPQR ~SPQR() { // Calls SuiteSparseQR_free() - cholmod_free_sparse(&m_H, &m_cc); - cholmod_free_dense(&m_HTau, &m_cc); - delete[] m_E; - delete[] m_HPinv; + cholmod_l_free_sparse(&m_H, &m_cc); + cholmod_l_free_sparse(&m_cR, &m_cc); + cholmod_l_free_dense(&m_HTau, &m_cc); + std::free(m_E); + std::free(m_HPinv); + cholmod_l_finish(&m_cc); } void compute(const _MatrixType& matrix) { @@ -244,7 +246,7 @@ struct SPQR_QProduct : ReturnByValue > y_cd = viewAsCholmod(m_other.const_cast_derived()); x_cd = SuiteSparseQR_qmult(method, m_spqr.m_H, m_spqr.m_HTau, m_spqr.m_HPinv, &y_cd, cc); res = Matrix::Map(reinterpret_cast(x_cd->x), x_cd->nrow, x_cd->ncol); - cholmod_free_dense(&x_cd, cc); + cholmod_l_free_dense(&x_cd, cc); } const SPQRType& m_spqr; const Derived& m_other; @@ -301,4 +303,4 @@ struct solve_retval, Rhs> } // end namespace internal }// End namespace Eigen -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From 83736e9c61d708634d26a56bac09e0d86c34d2b6 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Mon, 13 May 2013 13:08:13 +0200 Subject: Set back the default ordering method in SPQR support --- Eigen/src/SPQRSupport/SuiteSparseQRSupport.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h b/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h index ff304a546..aa41f434c 100644 --- a/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h +++ b/Eigen/src/SPQRSupport/SuiteSparseQRSupport.h @@ -64,7 +64,7 @@ class SPQR typedef PermutationMatrix PermutationType; public: SPQR() - : m_ordering(SPQR_ORDERING_AMD), + : m_ordering(SPQR_ORDERING_DEFAULT), m_allow_tol(SPQR_DEFAULT_TOL), m_tolerance (NumTraits::epsilon()) { @@ -72,7 +72,7 @@ class SPQR } SPQR(const _MatrixType& matrix) - : m_ordering(SPQR_ORDERING_AMD), + : m_ordering(SPQR_ORDERING_DEFAULT), m_allow_tol(SPQR_DEFAULT_TOL), m_tolerance (NumTraits::epsilon()) { -- cgit v1.2.3 From f7bdbf69e1974cde4bbd57bdfc4691d42cb373c3 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Tue, 14 May 2013 17:15:23 +0200 Subject: Add support in SparseLU to solve with L and U factors independently --- Eigen/src/SparseLU/SparseLU.h | 144 ++++++++++++++++--------- Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h | 15 +-- 2 files changed, 102 insertions(+), 57 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index e78250084..5475e17f4 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -15,7 +15,8 @@ namespace Eigen { template class SparseLU; -template struct SparseLUMatrixLReturnType; +template struct SparseLUMatrixLReturnType; +template struct SparseLUMatrixUReturnType; /** \ingroup SparseLU_Module * \class SparseLU * @@ -123,8 +124,8 @@ class SparseLU : public internal::SparseLUImpl(m_Lstore); } + /** \returns an expression of the matrix U, + * The only operation available with this expression is the triangular solve + * \code + * y = b; matrixU().solveInPlace(y); + * \endcode + */ + SparseLUMatrixUReturnType > matrixU() const + { + return SparseLUMatrixUReturnType >(m_Lstore, m_Ustore); + } + + /** + * \returns a reference to the row matrix permutation \f$ P_r \f$ such that \f$P_r A P_c^T = L U\f$ + * \sa colsPermutation() + */ + inline const PermutationType& rowsPermutation() const + { + return m_perm_r; + } + /** + * \returns a reference to the column matrix permutation\f$ P_c^T \f$ such that \f$P_r A P_c^T = L U\f$ + * \sa rowsPermutation() + */ + inline const PermutationType& colsPermutation() const + { + return m_perm_c; + } /** Set the threshold used for a diagonal entry to be an acceptable pivot. */ void setPivotThreshold(const RealScalar& thresh) { @@ -195,59 +223,19 @@ class SparseLU : public internal::SparseLUImplmatrixL().solveInPlace(X); + X.resize(B.rows(),B.cols()); + for(Index j = 0; j < B.cols(); ++j) + X.col(j) = rowsPermutation() * B.col(j); - // Backward solve with U - for (Index k = m_Lstore.nsuper(); k >= 0; k--) - { - Index fsupc = m_Lstore.supToCol()[k]; - Index lda = m_Lstore.colIndexPtr()[fsupc+1] - m_Lstore.colIndexPtr()[fsupc]; // leading dimension - Index nsupc = m_Lstore.supToCol()[k+1] - fsupc; - Index luptr = m_Lstore.colIndexPtr()[fsupc]; - - if (nsupc == 1) - { - for (Index j = 0; j < nrhs; j++) - { - X(fsupc, j) /= m_Lstore.valuePtr()[luptr]; - } - } - else - { - Map, 0, OuterStride<> > A( &(m_Lstore.valuePtr()[luptr]), nsupc, nsupc, OuterStride<>(lda) ); - Map< Matrix, 0, OuterStride<> > U (&(X(fsupc,0)), nsupc, nrhs, OuterStride<>(n) ); - U = A.template triangularView().solve(U); - } - - for (Index j = 0; j < nrhs; ++j) - { - for (Index jcol = fsupc; jcol < fsupc + nsupc; jcol++) - { - typename MappedSparseMatrix::InnerIterator it(m_Ustore, jcol); - for ( ; it; ++it) - { - Index irow = it.index(); - X(irow, j) -= X(jcol, j) * it.value(); - } - } - } - } // End For U-solve + //Forward substitution with L + this->matrixL().solveInPlace(X); + this->matrixU().solveInPlace(X); // Permute back the solution - for (Index j = 0; j < nrhs; ++j) - X.col(j) = m_perm_c.inverse() * X.col(j); + for (Index j = 0; j < B.cols(); ++j) + X.col(j) = colsPermutation().inverse() * X.col(j); return true; } @@ -584,6 +572,60 @@ struct SparseLUMatrixLReturnType const MappedSupernodalType& m_mapL; }; +template +struct SparseLUMatrixUReturnType +{ + typedef typename MatrixLType::Index Index; + typedef typename MatrixLType::Scalar Scalar; + SparseLUMatrixUReturnType(const MatrixLType& mapL, const MatrixUType& mapU) + : m_mapL(mapL),m_mapU(mapU) + { } + Index rows() { return m_mapL.rows(); } + Index cols() { return m_mapL.cols(); } + + template void solveInPlace(MatrixBase &X) const + { + Index nrhs = X.cols(); + Index n = X.rows(); + // Backward solve with U + for (Index k = m_mapL.nsuper(); k >= 0; k--) + { + Index fsupc = m_mapL.supToCol()[k]; + Index lda = m_mapL.colIndexPtr()[fsupc+1] - m_mapL.colIndexPtr()[fsupc]; // leading dimension + Index nsupc = m_mapL.supToCol()[k+1] - fsupc; + Index luptr = m_mapL.colIndexPtr()[fsupc]; + + if (nsupc == 1) + { + for (Index j = 0; j < nrhs; j++) + { + X(fsupc, j) /= m_mapL.valuePtr()[luptr]; + } + } + else + { + Map, 0, OuterStride<> > A( &(m_mapL.valuePtr()[luptr]), nsupc, nsupc, OuterStride<>(lda) ); + Map< Matrix, 0, OuterStride<> > U (&(X(fsupc,0)), nsupc, nrhs, OuterStride<>(n) ); + U = A.template triangularView().solve(U); + } + + for (Index j = 0; j < nrhs; ++j) + { + for (Index jcol = fsupc; jcol < fsupc + nsupc; jcol++) + { + typename MatrixUType::InnerIterator it(m_mapU, jcol); + for ( ; it; ++it) + { + Index irow = it.index(); + X(irow, j) -= X(jcol, j) * it.value(); + } + } + } + } // End For U-solve + } + const MatrixLType& m_mapL; + const MatrixUType& m_mapU; +}; namespace internal { template diff --git a/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h b/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h index 3eae95479..3836d1096 100644 --- a/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +++ b/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h @@ -189,13 +189,14 @@ class MappedSuperNodalMatrix::InnerIterator m_idval(mat.colIndexPtr()[outer]), m_startidval(m_idval), m_endidval(mat.colIndexPtr()[outer+1]), - m_idrow(mat.rowIndexPtr()[outer]) + m_idrow(mat.rowIndexPtr()[outer]), + m_endidrow(mat.rowIndexPtr()[outer+1]) {} inline InnerIterator& operator++() { m_idval++; m_idrow++; - return *this; + return *this; } inline Scalar value() const { return m_matrix.valuePtr()[m_idval]; } @@ -209,7 +210,8 @@ class MappedSuperNodalMatrix::InnerIterator inline operator bool() const { - return ( (m_idval < m_endidval) && (m_idval >= m_startidval) ); + return ( (m_idval < m_endidval) && (m_idval >= m_startidval) + && (m_idrow < m_endidrow) ); } protected: @@ -220,6 +222,7 @@ class MappedSuperNodalMatrix::InnerIterator const Index m_startidval; // Start of the column value const Index m_endidval; // End of the column value Index m_idrow; //Index to browse the row indices + Index m_endidrow; // End index of row indices of the current column }; /** @@ -248,16 +251,16 @@ void MappedSuperNodalMatrix::solveInPlace( MatrixBase&X) con { for (Index j = 0; j < nrhs; j++) { - InnerIterator it(*this, fsupc); + InnerIterator it(*this, fsupc); ++it; // Skip the diagonal element for (; it; ++it) { irow = it.row(); - X(irow, j) -= X(fsupc, j) * it.value(); + X(irow, j) -= X(fsupc, j) * it.value(); } } } - else + else { // The supernode has more than one column Index luptr = colIndexPtr()[fsupc]; -- cgit v1.2.3 From b5e5b6aa575cc6eb14576a7ad76cb47cee20b2f3 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Thu, 16 May 2013 10:18:19 +0200 Subject: Fix non const data() member in Array and Matrix wrappers. --- Eigen/src/Core/ArrayWrapper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/ArrayWrapper.h b/Eigen/src/Core/ArrayWrapper.h index 1e021b0b9..a791bc358 100644 --- a/Eigen/src/Core/ArrayWrapper.h +++ b/Eigen/src/Core/ArrayWrapper.h @@ -55,7 +55,7 @@ class ArrayWrapper : public ArrayBase > inline Index outerStride() const { return m_expression.outerStride(); } inline Index innerStride() const { return m_expression.innerStride(); } - inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } + inline ScalarWithConstIfNotLvalue* data() { return m_expression.const_cast_derived().data(); } inline const Scalar* data() const { return m_expression.data(); } inline CoeffReturnType coeff(Index rowId, Index colId) const @@ -175,7 +175,7 @@ class MatrixWrapper : public MatrixBase > inline Index outerStride() const { return m_expression.outerStride(); } inline Index innerStride() const { return m_expression.innerStride(); } - inline ScalarWithConstIfNotLvalue* data() { return m_expression.data(); } + inline ScalarWithConstIfNotLvalue* data() { return m_expression.const_cast_derived().data(); } inline const Scalar* data() const { return m_expression.data(); } inline CoeffReturnType coeff(Index rowId, Index colId) const -- cgit v1.2.3 From 9ab3811cc57b651129a03506573436f923efd6a1 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 17 May 2013 14:02:20 +0200 Subject: Disallow implicit scalar conversion of SparseMatrix --- Eigen/src/SparseCore/SparseMatrix.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index e9e285f35..de4d36840 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -637,6 +637,8 @@ class SparseMatrix inline SparseMatrix(const SparseMatrixBase& other) : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) { + EIGEN_STATIC_ASSERT((internal::is_same::value), + YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) check_template_parameters(); *this = other.derived(); } @@ -1023,6 +1025,9 @@ template template EIGEN_DONT_INLINE SparseMatrix& SparseMatrix::operator=(const SparseMatrixBase& other) { + EIGEN_STATIC_ASSERT((internal::is_same::value), + YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) + const bool needToTranspose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); if (needToTranspose) { -- cgit v1.2.3 From bd0474adbbbd8a94293f9f28fec47f08fb597ac7 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 17 May 2013 14:39:31 +0200 Subject: Fix A=A with A a SparseMatrix --- Eigen/src/SparseCore/SparseMatrix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index de4d36840..b4ed27e9b 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -679,7 +679,7 @@ class SparseMatrix { swap(other.const_cast_derived()); } - else + else if(this!=&other) { initAssignment(other); if(other.isCompressed()) -- cgit v1.2.3 From bd7511fc3651c70d20473dc0c6beab3013fd229a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 17 May 2013 14:40:32 +0200 Subject: Fix return type of TriangularView::ReverseInnerIterator::operator++ --- Eigen/src/SparseCore/SparseTriangularView.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseTriangularView.h b/Eigen/src/SparseCore/SparseTriangularView.h index 477e4bd94..68c4c3397 100644 --- a/Eigen/src/SparseCore/SparseTriangularView.h +++ b/Eigen/src/SparseCore/SparseTriangularView.h @@ -139,7 +139,7 @@ class SparseTriangularView::ReverseInnerIterator : public Matri --(*this); } - EIGEN_STRONG_INLINE InnerIterator& operator--() + EIGEN_STRONG_INLINE ReverseInnerIterator& operator--() { Base::operator--(); return *this; } inline Index row() const { return Base::row(); } -- cgit v1.2.3 From cf939f154fe1ec9904276f5f3f2dbdbc8e98156a Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Tue, 21 May 2013 17:35:10 +0200 Subject: Fix bug #596 : Recover plain SparseMatrix from SparseQR matrixQ() --- Eigen/src/SparseCore/SparseCwiseBinaryOp.h | 4 +- Eigen/src/SparseCore/SparseMatrix.h | 8 ++ Eigen/src/SparseQR/SparseQR.h | 118 ++++++++++++++++----- test/sparseqr.cpp | 8 ++ .../src/LevenbergMarquardt/LevenbergMarquardt.h | 2 +- 5 files changed, 112 insertions(+), 28 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h b/Eigen/src/SparseCore/SparseCwiseBinaryOp.h index d5f97f78f..64b8c8547 100644 --- a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +++ b/Eigen/src/SparseCore/SparseCwiseBinaryOp.h @@ -300,7 +300,7 @@ template EIGEN_STRONG_INLINE Derived & SparseMatrixBase::operator-=(const SparseMatrixBase &other) { - return *this = derived() - other.derived(); + return derived() = derived() - other.derived(); } template @@ -308,7 +308,7 @@ template EIGEN_STRONG_INLINE Derived & SparseMatrixBase::operator+=(const SparseMatrixBase& other) { - return *this = derived() + other.derived(); + return derived() = derived() + other.derived(); } template diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index b4ed27e9b..d93dffb48 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -673,6 +673,14 @@ class SparseMatrix m_data.swap(other.m_data); } + /** Sets *this to the identity matrix */ + inline void setIdentity() + { + eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES"); + this->setZero(); + for (int j = 0; j < rows(); j++) + this->insert(j,j) = Scalar(1.0); + } inline SparseMatrix& operator=(const SparseMatrix& other) { if (other.isRValue()) diff --git a/Eigen/src/SparseQR/SparseQR.h b/Eigen/src/SparseQR/SparseQR.h index b3d5cd208..0c70609b4 100644 --- a/Eigen/src/SparseQR/SparseQR.h +++ b/Eigen/src/SparseQR/SparseQR.h @@ -21,6 +21,8 @@ namespace internal { template struct traits > { typedef typename SparseQRType::MatrixType ReturnType; + typedef typename ReturnType::Index Index; + typedef typename ReturnType::StorageKind StorageKind; }; template struct traits > { @@ -72,10 +74,10 @@ class SparseQR typedef Matrix ScalarVector; typedef PermutationMatrix PermutationType; public: - SparseQR () : m_isInitialized(false), m_analysisIsok(false), m_lastError(""), m_useDefaultThreshold(true) + SparseQR () : m_isInitialized(false), m_analysisIsok(false), m_lastError(""), m_useDefaultThreshold(true),m_isQSorted(false) { } - SparseQR(const MatrixType& mat) : m_isInitialized(false), m_analysisIsok(false), m_lastError(""), m_useDefaultThreshold(true) + SparseQR(const MatrixType& mat) : m_isInitialized(false), m_analysisIsok(false), m_lastError(""), m_useDefaultThreshold(true),m_isQSorted(false) { compute(mat); } @@ -110,11 +112,23 @@ class SparseQR } /** \returns an expression of the matrix Q as products of sparse Householder reflectors. - * You can do the following to get an actual SparseMatrix representation of Q: - * \code - * SparseMatrix Q = SparseQR >(A).matrixQ(); - * \endcode - */ + * The common usage of this function is to apply it to a dense matrix or vector + * \code + * VectorXd B1, B2; + * // Initialize B1 + * B2 = matrixQ() * B1; + * \endcode + * + * To get a plain SparseMatrix representation of Q: + * \code + * SparseMatrix Q; + * Q = SparseQR >(A).matrixQ(); + * \endcode + * Internally, this call simply performs a sparse product between the matrix Q + * and a sparse identity matrix. However, due to the fact that the sparse + * reflectors are stored unsorted, two transpositions are needed to sort + * them before performing the product. + */ SparseQRMatrixQReturnType matrixQ() const { return SparseQRMatrixQReturnType(*this); } @@ -158,6 +172,7 @@ class SparseQR return true; } + /** Sets the threshold that is used to determine linearly dependent columns during the factorization. * * In practice, if during the factorization the norm of the column that has to be eliminated is below @@ -180,6 +195,13 @@ class SparseQR eigen_assert(this->rows() == B.rows() && "SparseQR::solve() : invalid number of rows in the right hand side matrix"); return internal::solve_retval(*this, B.derived()); } + template + inline const internal::sparse_solve_retval solve(const SparseMatrixBase& B) const + { + eigen_assert(m_isInitialized && "The factorization should be called first, use compute()"); + eigen_assert(this->rows() == B.rows() && "SparseQR::solve() : invalid number of rows in the right hand side matrix"); + return internal::sparse_solve_retval(*this, B.derived()); + } /** \brief Reports whether previous computation was successful. * @@ -194,6 +216,16 @@ class SparseQR eigen_assert(m_isInitialized && "Decomposition is not initialized."); return m_info; } + + protected: + inline void sort_matrix_Q() + { + // The matrix Q is sorted during the transposition + SparseMatrix mQrm(this->m_Q); + this->m_Q = mQrm; + this->m_isQSorted = true; + } + protected: bool m_isInitialized; @@ -213,8 +245,10 @@ class SparseQR Index m_nonzeropivots; // Number of non zero pivots found IndexVector m_etree; // Column elimination tree IndexVector m_firstRowElt; // First element in each row + bool m_isQSorted; // whether Q is sorted or not template friend struct SparseQR_QProduct; + template friend struct SparseQRMatrixQReturnType; }; @@ -462,6 +496,7 @@ void SparseQR::factorize(const MatrixType& mat) m_Q.makeCompressed(); m_R.finalize(); m_R.makeCompressed(); + m_isQSorted = false; m_nonzeropivots = nonzeroCol; @@ -494,7 +529,18 @@ struct solve_retval, Rhs> dec()._solve(rhs(),dst); } }; +template +struct sparse_solve_retval, Rhs> + : sparse_solve_retval_base, Rhs> +{ + typedef SparseQR<_MatrixType, OrderingType> Dec; + EIGEN_MAKE_SPARSE_SOLVE_HELPERS(Dec, Rhs) + template void evalTo(Dest& dst) const + { + this->defaultEvalTo(dst); + } +}; } // end namespace internal template @@ -513,34 +559,35 @@ struct SparseQR_QProduct : ReturnByValue void evalTo(DesType& res) const { - Index n = m_qr.cols(); + Index n = m_qr.cols(); + res = m_other; if (m_transpose) { eigen_assert(m_qr.m_Q.rows() == m_other.rows() && "Non conforming object sizes"); - // Compute res = Q' * other : - res = m_other; - for (Index k = 0; k < n; k++) - { - Scalar tau = Scalar(0); - tau = m_qr.m_Q.col(k).dot(res); - tau = tau * m_qr.m_hcoeffs(k); - for (typename MatrixType::InnerIterator itq(m_qr.m_Q, k); itq; ++itq) + //Compute res = Q' * other column by column + for(Index j = 0; j < res.cols(); j++){ + for (Index k = 0; k < n; k++) { - res(itq.row()) -= itq.value() * tau; + Scalar tau = Scalar(0); + tau = m_qr.m_Q.col(k).dot(res.col(j)); + tau = tau * m_qr.m_hcoeffs(k); + res.col(j) -= tau * m_qr.m_Q.col(k); } } } else { eigen_assert(m_qr.m_Q.cols() == m_other.rows() && "Non conforming object sizes"); - // Compute res = Q * other : - res = m_other; - for (Index k = n-1; k >=0; k--) + // Compute res = Q' * other column by column + for(Index j = 0; j < res.cols(); j++) { - Scalar tau = Scalar(0); - tau = m_qr.m_Q.col(k).dot(res); - tau = tau * m_qr.m_hcoeffs(k); - res -= tau * m_qr.m_Q.col(k); + for (Index k = n-1; k >=0; k--) + { + Scalar tau = Scalar(0); + tau = m_qr.m_Q.col(k).dot(res.col(j)); + tau = tau * m_qr.m_hcoeffs(k); + res.col(j) -= tau * m_qr.m_Q.col(k); + } } } } @@ -551,8 +598,11 @@ struct SparseQR_QProduct : ReturnByValue -struct SparseQRMatrixQReturnType +struct SparseQRMatrixQReturnType : public EigenBase > { + typedef typename SparseQRType::Index Index; + typedef typename SparseQRType::Scalar Scalar; + typedef Matrix DenseMatrix; SparseQRMatrixQReturnType(const SparseQRType& qr) : m_qr(qr) {} template SparseQR_QProduct operator*(const MatrixBase& other) @@ -563,11 +613,29 @@ struct SparseQRMatrixQReturnType { return SparseQRMatrixQTransposeReturnType(m_qr); } + inline Index rows() const { return m_qr.rows(); } + inline Index cols() const { return m_qr.cols(); } // To use for operations with the transpose of Q SparseQRMatrixQTransposeReturnType transpose() const { return SparseQRMatrixQTransposeReturnType(m_qr); } + template void evalTo(MatrixBase& dest) const + { + dest.resize(m_qr.rows(), m_qr.cols()); + dest.derived() = m_qr.matrixQ() * Dest::Identity(m_qr.rows(), m_qr.rows()); + } + template void evalTo(SparseMatrixBase& dest) const + { + Dest idMat(m_qr.rows(), m_qr.rows()); + idMat.setIdentity(); + dest.derived().resize(m_qr.rows(), m_qr.cols()); + // Sort the sparse householder reflectors if needed + if(!m_qr.m_isQSorted) + const_cast(&m_qr)->sort_matrix_Q(); + dest.derived() = SparseQR_QProduct(m_qr, idMat, false); + } + const SparseQRType& m_qr; }; diff --git a/test/sparseqr.cpp b/test/sparseqr.cpp index 66c7c005e..6edba30b2 100644 --- a/test/sparseqr.cpp +++ b/test/sparseqr.cpp @@ -71,6 +71,14 @@ template void test_sparseqr_scalar() VERIFY((dA * refX - b).norm() * 2 > (A * x - b).norm() ); else VERIFY_IS_APPROX(x, refX); + + // Compute explicitly the matrix Q + MatrixType Q, QtQ, idM; + Q = solver.matrixQ(); + //Check ||Q' * Q - I || + QtQ = Q * Q.adjoint(); + idM.resize(Q.rows(), Q.rows()); idM.setIdentity(); + VERIFY(idM.isApprox(QtQ)); } void test_sparseqr() { diff --git a/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h b/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h index 8d5538d69..ad47d3d84 100644 --- a/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h +++ b/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h @@ -302,8 +302,8 @@ LevenbergMarquardt::minimizeInit(FVectorType &x) for (Index j = 0; j < n; ++j) if (m_diag[j] <= 0.) { - return LevenbergMarquardtSpace::ImproperInputParameters; m_info = InvalidInput; + return LevenbergMarquardtSpace::ImproperInputParameters; } /* evaluate the function at the starting point */ -- cgit v1.2.3 From 8e050bd68163a64e0252eed66e215baafb6c11ca Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Wed, 22 May 2013 10:43:12 +0200 Subject: Optimize Sparse setIdentity and add a unit test --- Eigen/src/SparseCore/SparseMatrix.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index d93dffb48..072578132 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -677,9 +677,10 @@ class SparseMatrix inline void setIdentity() { eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES"); - this->setZero(); - for (int j = 0; j < rows(); j++) - this->insert(j,j) = Scalar(1.0); + this->m_data.resize(rows()); + Eigen::Map >(&this->m_data.index(0), rows()).setLinSpaced(0, rows()-1); + Eigen::Map >(&this->m_data.value(0), rows()).setOnes(); + Eigen::Map >(this->m_outerIndex, rows()+1).setLinSpaced(0, rows()); } inline SparseMatrix& operator=(const SparseMatrix& other) { -- cgit v1.2.3 From e0566a817f4092ae58b6cd3a3fb8d2abd10357c9 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Wed, 22 May 2013 10:44:12 +0200 Subject: Delete unneeded resize in SparseQR --- Eigen/src/SparseQR/SparseQR.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseQR/SparseQR.h b/Eigen/src/SparseQR/SparseQR.h index 0c70609b4..1bf631507 100644 --- a/Eigen/src/SparseQR/SparseQR.h +++ b/Eigen/src/SparseQR/SparseQR.h @@ -220,6 +220,7 @@ class SparseQR protected: inline void sort_matrix_Q() { + if(this->m_isQSorted) return; // The matrix Q is sorted during the transposition SparseMatrix mQrm(this->m_Q); this->m_Q = mQrm; @@ -622,17 +623,14 @@ struct SparseQRMatrixQReturnType : public EigenBase void evalTo(MatrixBase& dest) const { - dest.resize(m_qr.rows(), m_qr.cols()); dest.derived() = m_qr.matrixQ() * Dest::Identity(m_qr.rows(), m_qr.rows()); } template void evalTo(SparseMatrixBase& dest) const { Dest idMat(m_qr.rows(), m_qr.rows()); idMat.setIdentity(); - dest.derived().resize(m_qr.rows(), m_qr.cols()); // Sort the sparse householder reflectors if needed - if(!m_qr.m_isQSorted) - const_cast(&m_qr)->sort_matrix_Q(); + const_cast(&m_qr)->sort_matrix_Q(); dest.derived() = SparseQR_QProduct(m_qr, idMat, false); } -- cgit v1.2.3 From d7cd957f105b731412124755face7c3a098ff5a3 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Wed, 29 May 2013 10:15:40 +0200 Subject: Include misc struct declarations --- Eigen/SparseLU | 3 +++ Eigen/SparseQR | 4 ++++ 2 files changed, 7 insertions(+) (limited to 'Eigen') diff --git a/Eigen/SparseLU b/Eigen/SparseLU index 38b38b531..8527a49bd 100644 --- a/Eigen/SparseLU +++ b/Eigen/SparseLU @@ -20,6 +20,9 @@ * Please, see the documentation of the SparseLU class for more details. */ +#include "src/misc/Solve.h" +#include "src/misc/SparseSolve.h" + // Ordering interface #include "OrderingMethods" diff --git a/Eigen/SparseQR b/Eigen/SparseQR index f51913f7b..4ee42065e 100644 --- a/Eigen/SparseQR +++ b/Eigen/SparseQR @@ -20,6 +20,10 @@ * * */ + +#include "src/misc/Solve.h" +#include "src/misc/SparseSolve.h" + #include "OrderingMethods" #include "src/SparseCore/SparseColEtree.h" #include "src/SparseQR/SparseQR.h" -- cgit v1.2.3 From b3adc4face5c7855fd63d8f6f96f6a8f63dc40c4 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 17 May 2013 17:25:29 +0200 Subject: Add missing pconj specializations --- Eigen/src/Core/arch/AltiVec/PacketMath.h | 3 +++ Eigen/src/Core/arch/NEON/PacketMath.h | 3 +++ Eigen/src/Core/arch/SSE/PacketMath.h | 4 ++++ 3 files changed, 10 insertions(+) (limited to 'Eigen') diff --git a/Eigen/src/Core/arch/AltiVec/PacketMath.h b/Eigen/src/Core/arch/AltiVec/PacketMath.h index 75de19311..e4089962d 100644 --- a/Eigen/src/Core/arch/AltiVec/PacketMath.h +++ b/Eigen/src/Core/arch/AltiVec/PacketMath.h @@ -173,6 +173,9 @@ template<> EIGEN_STRONG_INLINE Packet4i psub(const Packet4i& a, const template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return psub(p4f_ZERO, a); } template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return psub(p4i_ZERO, a); } +template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; } +template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } + template<> EIGEN_STRONG_INLINE Packet4f pmul(const Packet4f& a, const Packet4f& b) { return vec_madd(a,b,p4f_ZERO); } /* Commented out: it's actually slower than processing it scalar * diff --git a/Eigen/src/Core/arch/NEON/PacketMath.h b/Eigen/src/Core/arch/NEON/PacketMath.h index 2662e2ebf..4c0702715 100644 --- a/Eigen/src/Core/arch/NEON/PacketMath.h +++ b/Eigen/src/Core/arch/NEON/PacketMath.h @@ -115,6 +115,9 @@ template<> EIGEN_STRONG_INLINE Packet4i psub(const Packet4i& a, const template<> EIGEN_STRONG_INLINE Packet4f pnegate(const Packet4f& a) { return vnegq_f32(a); } template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) { return vnegq_s32(a); } +template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; } +template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } + template<> EIGEN_STRONG_INLINE Packet4f pmul(const Packet4f& a, const Packet4f& b) { return vmulq_f32(a,b); } template<> EIGEN_STRONG_INLINE Packet4i pmul(const Packet4i& a, const Packet4i& b) { return vmulq_s32(a,b); } diff --git a/Eigen/src/Core/arch/SSE/PacketMath.h b/Eigen/src/Core/arch/SSE/PacketMath.h index addb2fc0e..e256f4bac 100644 --- a/Eigen/src/Core/arch/SSE/PacketMath.h +++ b/Eigen/src/Core/arch/SSE/PacketMath.h @@ -141,6 +141,10 @@ template<> EIGEN_STRONG_INLINE Packet4i pnegate(const Packet4i& a) return psub(_mm_setr_epi32(0,0,0,0), a); } +template<> EIGEN_STRONG_INLINE Packet4f pconj(const Packet4f& a) { return a; } +template<> EIGEN_STRONG_INLINE Packet2d pconj(const Packet2d& a) { return a; } +template<> EIGEN_STRONG_INLINE Packet4i pconj(const Packet4i& a) { return a; } + template<> EIGEN_STRONG_INLINE Packet4f pmul(const Packet4f& a, const Packet4f& b) { return _mm_mul_ps(a,b); } template<> EIGEN_STRONG_INLINE Packet2d pmul(const Packet2d& a, const Packet2d& b) { return _mm_mul_pd(a,b); } template<> EIGEN_STRONG_INLINE Packet4i pmul(const Packet4i& a, const Packet4i& b) -- cgit v1.2.3 From e04b59929e45564dbbc80f4e1482892458983ac0 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 9 Jun 2013 21:03:32 +0200 Subject: fix unused variable warning --- Eigen/src/CholmodSupport/CholmodSupport.h | 1 + 1 file changed, 1 insertion(+) (limited to 'Eigen') diff --git a/Eigen/src/CholmodSupport/CholmodSupport.h b/Eigen/src/CholmodSupport/CholmodSupport.h index 42d289ad8..d4008e63d 100644 --- a/Eigen/src/CholmodSupport/CholmodSupport.h +++ b/Eigen/src/CholmodSupport/CholmodSupport.h @@ -312,6 +312,7 @@ class CholmodBase : internal::noncopyable { eigen_assert(m_factorizationIsOk && "The decomposition is not in a valid state for solving, you must first call either compute() or symbolic()/numeric()"); const Index size = m_cholmodFactor->n; + EIGEN_UNUSED_VARIABLE(size); eigen_assert(size==b.rows()); // note: cs stands for Cholmod Sparse -- cgit v1.2.3 From c98fd7a6cae853f1ca8570994ae9ba3c13e9c4bd Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 9 Jun 2013 23:14:45 +0200 Subject: Fix bug #609: avoid if statement and improve consistency of eulerAngles method --- Eigen/src/Geometry/EulerAngles.h | 58 +++++++++++++++++++++++++++------------- test/geo_eulerangles.cpp | 58 +++++++++++++++++++++++++++++++--------- 2 files changed, 85 insertions(+), 31 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Geometry/EulerAngles.h b/Eigen/src/Geometry/EulerAngles.h index 216307706..3f6ecc6d9 100644 --- a/Eigen/src/Geometry/EulerAngles.h +++ b/Eigen/src/Geometry/EulerAngles.h @@ -27,12 +27,18 @@ namespace Eigen { * * AngleAxisf(ea[1], Vector3f::UnitX()) * * AngleAxisf(ea[2], Vector3f::UnitZ()); \endcode * This corresponds to the right-multiply conventions (with right hand side frames). + * + * The returned angles are in the ranges [0:pi]x[0:pi]x[-pi:pi]. + * + * \sa class AngleAxis */ template inline Matrix::Scalar,3,1> MatrixBase::eulerAngles(Index a0, Index a1, Index a2) const { using std::atan2; + using std::sin; + using std::cos; /* Implemented from Graphics Gems IV */ EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3) @@ -44,39 +50,53 @@ MatrixBase::eulerAngles(Index a0, Index a1, Index a2) const const Index i = a0; const Index j = (a0 + 1 + odd)%3; const Index k = (a0 + 2 - odd)%3; - + if (a0==a2) { - Scalar s = Vector2(coeff(j,i) , coeff(k,i)).norm(); - res[1] = atan2(s, coeff(i,i)); - if (s > epsilon) + res[0] = atan2(coeff(j,i), coeff(k,i)); + if((odd && res[0]<0) || ((!odd) && res[0]>0)) { - res[0] = atan2(coeff(j,i), coeff(k,i)); - res[2] = atan2(coeff(i,j),-coeff(i,k)); + res[0] = (res[0] > 0) ? res[0] - M_PI : res[0] + M_PI; + Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm(); + res[1] = -atan2(s2, coeff(i,i)); } else { - res[0] = Scalar(0); - res[2] = (coeff(i,i)>0?1:-1)*atan2(-coeff(k,j), coeff(j,j)); + Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm(); + res[1] = atan2(s2, coeff(i,i)); } - } + + // With a=(0,1,0), we have i=0; j=1; k=2, and after computing the first two angles, + // we can compute their respective rotation, and apply its inverse to M. Since the result must + // be a rotation around x, we have: + // + // c2 s1.s2 c1.s2 1 0 0 + // 0 c1 -s1 * M = 0 c3 s3 + // -s2 s1.c2 c1.c2 0 -s3 c3 + // + // Thus: m11.c1 - m21.s1 = c3 & m12.c1 - m22.s1 = s3 + + Scalar s1 = sin(res[0]); + Scalar c1 = cos(res[0]); + res[2] = atan2(c1*coeff(j,k)-s1*coeff(k,k), c1*coeff(j,j) - s1 * coeff(k,j)); + } else { - Scalar c = Vector2(coeff(i,i) , coeff(i,j)).norm(); - res[1] = atan2(-coeff(i,k), c); - if (c > epsilon) - { - res[0] = atan2(coeff(j,k), coeff(k,k)); - res[2] = atan2(coeff(i,j), coeff(i,i)); + res[0] = atan2(coeff(j,k), coeff(k,k)); + Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm(); + if((odd && res[0]<0) || ((!odd) && res[0]>0)) { + res[0] = (res[0] > 0) ? res[0] - M_PI : res[0] + M_PI; + res[1] = atan2(-coeff(i,k), -c2); } else - { - res[0] = Scalar(0); - res[2] = (coeff(i,k)>0?1:-1)*atan2(-coeff(k,j), coeff(j,j)); - } + res[1] = atan2(-coeff(i,k), c2); + Scalar s1 = sin(res[0]); + Scalar c1 = cos(res[0]); + res[2] = atan2(s1*coeff(k,i)-c1*coeff(j,i), c1*coeff(j,j) - s1 * coeff(k,j)); } if (!odd) res = -res; + return res; } diff --git a/test/geo_eulerangles.cpp b/test/geo_eulerangles.cpp index 9bf149d2a..26456beee 100644 --- a/test/geo_eulerangles.cpp +++ b/test/geo_eulerangles.cpp @@ -1,7 +1,7 @@ // This file is part of Eigen, a lightweight C++ template library // for linear algebra. // -// Copyright (C) 2008-2009 Gael Guennebaud +// Copyright (C) 2008-2012 Gael Guennebaud // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed @@ -12,22 +12,18 @@ #include #include -template void eulerangles(void) +template void check_all_var(const Matrix& ea) { typedef Matrix Matrix3; typedef Matrix Vector3; - typedef Quaternion Quaternionx; typedef AngleAxis AngleAxisx; - - Scalar a = internal::random(-Scalar(M_PI), Scalar(M_PI)); - Quaternionx q1; - q1 = AngleAxisx(a, Vector3::Random().normalized()); - Matrix3 m; - m = q1; - + #define VERIFY_EULER(I,J,K, X,Y,Z) { \ - Vector3 ea = m.eulerAngles(I,J,K); \ - VERIFY_IS_APPROX(m, Matrix3(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z()))); \ + Matrix3 m(AngleAxisx(ea[0], Vector3::Unit##X()) * AngleAxisx(ea[1], Vector3::Unit##Y()) * AngleAxisx(ea[2], Vector3::Unit##Z())); \ + Vector3 eabis = m.eulerAngles(I,J,K); \ + Matrix3 mbis(AngleAxisx(eabis[0], Vector3::Unit##X()) * AngleAxisx(eabis[1], Vector3::Unit##Y()) * AngleAxisx(eabis[2], Vector3::Unit##Z())); \ + VERIFY_IS_APPROX(m, mbis); \ + if(I!=K || ea[1]!=0) VERIFY_IS_APPROX(ea, eabis); \ } VERIFY_EULER(0,1,2, X,Y,Z); VERIFY_EULER(0,1,0, X,Y,X); @@ -45,6 +41,44 @@ template void eulerangles(void) VERIFY_EULER(2,1,2, Z,Y,Z); } +template void eulerangles(void) +{ + typedef Matrix Matrix3; + typedef Matrix Vector3; + typedef Array Array3; + typedef Quaternion Quaternionx; + typedef AngleAxis AngleAxisx; + + Scalar a = internal::random(-Scalar(M_PI), Scalar(M_PI)); + Quaternionx q1; + q1 = AngleAxisx(a, Vector3::Random().normalized()); + Matrix3 m; + m = q1; + + Vector3 ea = m.eulerAngles(0,1,2); + check_all_var(ea); + ea = m.eulerAngles(0,1,0); + check_all_var(ea); + + ea = (Array3::Random() + Array3(1,1,0))*M_PI*Array3(0.5,0.5,1); + check_all_var(ea); + + ea[2] = ea[0] = internal::random(0,M_PI); + check_all_var(ea); + + ea[0] = ea[1] = internal::random(0,M_PI); + check_all_var(ea); + + ea[1] = 0; + check_all_var(ea); + + ea.head(2).setZero(); + check_all_var(ea); + + ea.setZero(); + check_all_var(ea); +} + void test_geo_eulerangles() { for(int i = 0; i < g_repeat; i++) { -- cgit v1.2.3 From a69b4b092beec7caf87f1fe13cbba0781c651852 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 9 Jun 2013 23:19:32 +0200 Subject: Fix bug #608: the sign computation in LDLT was broken --- Eigen/src/Cholesky/LDLT.h | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index 4c0be9dd9..d933b10d4 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -278,22 +278,13 @@ template<> struct ldlt_inplace // are compared; if any diagonal is negligible compared // to the largest overall, the algorithm bails. cutoff = abs(NumTraits::epsilon() * biggest_in_corner); - - if(sign) - *sign = real(mat.diagonal().coeff(index_of_biggest_in_corner)) > 0 ? 1 : -1; - } - else if(sign) - { - // LDLT is not guaranteed to work for indefinite matrices, but let's try to get the sign right - int newSign = real(mat.diagonal().coeff(index_of_biggest_in_corner)) > 0; - if(newSign != *sign) - *sign = 0; } // Finish early if the matrix is not full rank. if(biggest_in_corner < cutoff) { for(Index i = k; i < size; i++) transpositions.coeffRef(i) = i; + if(sign) *sign = 0; break; } @@ -334,6 +325,16 @@ template<> struct ldlt_inplace } if((rs>0) && (abs(mat.coeffRef(k,k)) > cutoff)) A21 /= mat.coeffRef(k,k); + + if(sign) + { + // LDLT is not guaranteed to work for indefinite matrices, but let's try to get the sign right + int newSign = real(mat.diagonal().coeff(index_of_biggest_in_corner)) > 0; + if(k == 0) + *sign = newSign; + else if(*sign != newSign) + *sign = 0; + } } return true; -- cgit v1.2.3 From e3929485486ad4450dd93d24fa2af9dd72aa368e Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 10 Jun 2013 00:06:40 +0200 Subject: Fix bug #607: handle implicit transposition from sparse vector to dense vector --- Eigen/src/Core/Assign.h | 10 ++++++---- Eigen/src/SparseCore/SparseMatrixBase.h | 26 +++++++++++++------------- test/sparse_vector.cpp | 5 +++++ 3 files changed, 24 insertions(+), 17 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index 288f8ec53..6400f5ae7 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -520,18 +520,22 @@ struct assign_selector; template struct assign_selector { static EIGEN_STRONG_INLINE Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.derived()); } + static EIGEN_STRONG_INLINE Derived& evalTo(Derived& dst, const OtherDerived& other) { other.evalTo(dst); return dst; } }; template struct assign_selector { static EIGEN_STRONG_INLINE Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.eval()); } + static EIGEN_STRONG_INLINE Derived& evalTo(Derived& dst, const OtherDerived& other) { other.evalTo(dst); return dst; } }; template struct assign_selector { static EIGEN_STRONG_INLINE Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose()); } + static EIGEN_STRONG_INLINE Derived& evalTo(Derived& dst, const OtherDerived& other) { Transpose dstTrans(dst); other.evalTo(dstTrans); return dst; } }; template struct assign_selector { static EIGEN_STRONG_INLINE Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose().eval()); } + static EIGEN_STRONG_INLINE Derived& evalTo(Derived& dst, const OtherDerived& other) { Transpose dstTrans(dst); other.evalTo(dstTrans); return dst; } }; } // end namespace internal @@ -566,16 +570,14 @@ template template EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const EigenBase& other) { - other.derived().evalTo(derived()); - return derived(); + return internal::assign_selector::evalTo(derived(), other.derived()); } template template EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const ReturnByValue& other) { - other.evalTo(derived()); - return derived(); + return internal::assign_selector::evalTo(derived(), other.derived()); } } // end namespace Eigen diff --git a/Eigen/src/SparseCore/SparseMatrixBase.h b/Eigen/src/SparseCore/SparseMatrixBase.h index 590339663..6c73b7172 100644 --- a/Eigen/src/SparseCore/SparseMatrixBase.h +++ b/Eigen/src/SparseCore/SparseMatrixBase.h @@ -403,20 +403,20 @@ template class SparseMatrixBase : public EigenBase Block innerVectors(Index outerStart, Index outerSize); const Block innerVectors(Index outerStart, Index outerSize) const; - /** \internal use operator= */ - template - void evalTo(MatrixBase& dst) const - { - dst.setZero(); - for (Index j=0; j + void evalTo(MatrixBase& dst) const + { + dst.setZero(); + for (Index j=0; j toDense() const - { - return derived(); - } + Matrix toDense() const + { + return derived(); + } template bool isApprox(const SparseMatrixBase& other, diff --git a/test/sparse_vector.cpp b/test/sparse_vector.cpp index d16d42f59..ec5877b6a 100644 --- a/test/sparse_vector.cpp +++ b/test/sparse_vector.cpp @@ -90,6 +90,11 @@ template void sparse_vector(int rows, int cols) VERIFY_IS_APPROX((mv1=v1),v1); VERIFY_IS_APPROX(mv1,(v1=mv1)); VERIFY_IS_APPROX(mv1,(v1=mv1.transpose())); + + // check copy to dense vector with transpose + refV3.resize(0); + VERIFY_IS_APPROX(refV3 = v1.transpose(),v1.toDense()); + VERIFY_IS_APPROX(DenseVector(v1),v1.toDense()); } -- cgit v1.2.3 From b6d3fcf6f28c189bf270e8f9cffc13913a814925 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 10 Jun 2013 10:11:29 +0200 Subject: Fix bug #605: ambiguous call to std::min when calling .diagonal() on a sparse matrix with non default index type --- Eigen/src/Core/Diagonal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index 0927e9969..c106f93c4 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -75,7 +75,7 @@ template class Diagonal EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Diagonal) inline Index rows() const - { return m_index.value()<0 ? (std::min)(m_matrix.cols(),m_matrix.rows()+m_index.value()) : (std::min)(m_matrix.rows(),m_matrix.cols()-m_index.value()); } + { return m_index.value()<0 ? (std::min)(m_matrix.cols(),m_matrix.rows()+m_index.value()) : (std::min)(m_matrix.rows(),m_matrix.cols()-m_index.value()); } inline Index cols() const { return 1; } -- cgit v1.2.3 From e8c963568cd70c525234b283d15b0653114a93f4 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 10 Jun 2013 10:32:29 +0200 Subject: Simplify and generalize assign_selector logic --- Eigen/src/Core/Assign.h | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h index 6400f5ae7..1dccc2f42 100644 --- a/Eigen/src/Core/Assign.h +++ b/Eigen/src/Core/Assign.h @@ -507,35 +507,33 @@ EIGEN_STRONG_INLINE Derived& DenseBase namespace internal { template + bool EvalBeforeAssigning = (int(internal::traits::Flags) & EvalBeforeAssigningBit) != 0, + bool NeedToTranspose = ((int(Derived::RowsAtCompileTime) == 1 && int(OtherDerived::ColsAtCompileTime) == 1) + | // FIXME | instead of || to please GCC 4.4.0 stupid warning "suggest parentheses around &&". + // revert to || as soon as not needed anymore. + (int(Derived::ColsAtCompileTime) == 1 && int(OtherDerived::RowsAtCompileTime) == 1)) + && int(Derived::SizeAtCompileTime) != 1> struct assign_selector; template struct assign_selector { static EIGEN_STRONG_INLINE Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.derived()); } - static EIGEN_STRONG_INLINE Derived& evalTo(Derived& dst, const OtherDerived& other) { other.evalTo(dst); return dst; } + template + static EIGEN_STRONG_INLINE Derived& evalTo(ActualDerived& dst, const ActualOtherDerived& other) { other.evalTo(dst); return dst; } }; template struct assign_selector { static EIGEN_STRONG_INLINE Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.eval()); } - static EIGEN_STRONG_INLINE Derived& evalTo(Derived& dst, const OtherDerived& other) { other.evalTo(dst); return dst; } }; template struct assign_selector { static EIGEN_STRONG_INLINE Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose()); } - static EIGEN_STRONG_INLINE Derived& evalTo(Derived& dst, const OtherDerived& other) { Transpose dstTrans(dst); other.evalTo(dstTrans); return dst; } + template + static EIGEN_STRONG_INLINE Derived& evalTo(ActualDerived& dst, const ActualOtherDerived& other) { Transpose dstTrans(dst); other.evalTo(dstTrans); return dst; } }; template struct assign_selector { static EIGEN_STRONG_INLINE Derived& run(Derived& dst, const OtherDerived& other) { return dst.lazyAssign(other.transpose().eval()); } - static EIGEN_STRONG_INLINE Derived& evalTo(Derived& dst, const OtherDerived& other) { Transpose dstTrans(dst); other.evalTo(dstTrans); return dst; } }; } // end namespace internal @@ -570,14 +568,14 @@ template template EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const EigenBase& other) { - return internal::assign_selector::evalTo(derived(), other.derived()); + return internal::assign_selector::evalTo(derived(), other.derived()); } template template EIGEN_STRONG_INLINE Derived& MatrixBase::operator=(const ReturnByValue& other) { - return internal::assign_selector::evalTo(derived(), other.derived()); + return internal::assign_selector::evalTo(derived(), other.derived()); } } // end namespace Eigen -- cgit v1.2.3 From 2b6528effc0465baa2dc937f1e143625c6a8520b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 10 Jun 2013 11:42:14 +0200 Subject: HouseholderSequence should expose standard enums (Rows/Cols, etc.)) --- Eigen/src/Householder/HouseholderSequence.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Householder/HouseholderSequence.h b/Eigen/src/Householder/HouseholderSequence.h index 1e71e16a7..0de2a0084 100644 --- a/Eigen/src/Householder/HouseholderSequence.h +++ b/Eigen/src/Householder/HouseholderSequence.h @@ -112,6 +112,9 @@ template struct matrix_type_times template class HouseholderSequence : public EigenBase > { + typedef typename internal::hseq_side_dependent_impl::EssentialVectorType EssentialVectorType; + + public: enum { RowsAtCompileTime = internal::traits::RowsAtCompileTime, ColsAtCompileTime = internal::traits::ColsAtCompileTime, @@ -121,11 +124,6 @@ template class HouseholderS typedef typename internal::traits::Scalar Scalar; typedef typename VectorsType::Index Index; - typedef typename internal::hseq_side_dependent_impl::EssentialVectorType - EssentialVectorType; - - public: - typedef HouseholderSequence< VectorsType, typename internal::conditional::IsComplex, -- cgit v1.2.3 From 0525874a0378a62faf4db5316636d3a62ef62a31 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 10 Jun 2013 11:58:28 +0200 Subject: Fix bug #599: add missing documentation of some members in QR module. --- Eigen/src/QR/ColPivHouseholderQR.h | 24 ++++++++++++++++++++++++ Eigen/src/QR/FullPivHouseholderQR.h | 25 +++++++++++++++++++++++++ Eigen/src/QR/HouseholderQR.h | 33 ++++++++++++++++++++++++++++----- 3 files changed, 77 insertions(+), 5 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/QR/ColPivHouseholderQR.h b/Eigen/src/QR/ColPivHouseholderQR.h index 9ec8a65e4..07e75d6f0 100644 --- a/Eigen/src/QR/ColPivHouseholderQR.h +++ b/Eigen/src/QR/ColPivHouseholderQR.h @@ -94,6 +94,18 @@ template class ColPivHouseholderQR m_isInitialized(false), m_usePrescribedThreshold(false) {} + /** \brief Constructs a QR factorization from a given matrix + * + * This constructor computes the QR factorization of the matrix \a matrix by calling + * the method compute(). It is a short cut for: + * + * \code + * ColPivHouseholderQR qr(matrix.rows(), matrix.cols()); + * qr.compute(matrix); + * \endcode + * + * \sa compute() + */ ColPivHouseholderQR(const MatrixType& matrix) : m_qr(matrix.rows(), matrix.cols()), m_hCoeffs((std::min)(matrix.rows(),matrix.cols())), @@ -163,6 +175,7 @@ template class ColPivHouseholderQR ColPivHouseholderQR& compute(const MatrixType& matrix); + /** \returns a const reference to the column permutation matrix */ const PermutationType& colsPermutation() const { eigen_assert(m_isInitialized && "ColPivHouseholderQR is not initialized."); @@ -281,6 +294,11 @@ template class ColPivHouseholderQR inline Index rows() const { return m_qr.rows(); } inline Index cols() const { return m_qr.cols(); } + + /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q. + * + * For advanced uses only. + */ const HCoeffsType& hCoeffs() const { return m_hCoeffs; } /** Allows to prescribe a threshold to be used by certain methods, such as rank(), @@ -394,6 +412,12 @@ typename MatrixType::RealScalar ColPivHouseholderQR::logAbsDetermina return m_qr.diagonal().cwiseAbs().array().log().sum(); } +/** Performs the QR factorization of the given matrix \a matrix. The result of + * the factorization is stored into \c *this, and a reference to \c *this + * is returned. + * + * \sa class ColPivHouseholderQR, ColPivHouseholderQR(const MatrixType&) + */ template ColPivHouseholderQR& ColPivHouseholderQR::compute(const MatrixType& matrix) { diff --git a/Eigen/src/QR/FullPivHouseholderQR.h b/Eigen/src/QR/FullPivHouseholderQR.h index 613c29e57..f82126494 100644 --- a/Eigen/src/QR/FullPivHouseholderQR.h +++ b/Eigen/src/QR/FullPivHouseholderQR.h @@ -100,6 +100,18 @@ template class FullPivHouseholderQR m_isInitialized(false), m_usePrescribedThreshold(false) {} + /** \brief Constructs a QR factorization from a given matrix + * + * This constructor computes the QR factorization of the matrix \a matrix by calling + * the method compute(). It is a short cut for: + * + * \code + * FullPivHouseholderQR qr(matrix.rows(), matrix.cols()); + * qr.compute(matrix); + * \endcode + * + * \sa compute() + */ FullPivHouseholderQR(const MatrixType& matrix) : m_qr(matrix.rows(), matrix.cols()), m_hCoeffs((std::min)(matrix.rows(), matrix.cols())), @@ -152,12 +164,14 @@ template class FullPivHouseholderQR FullPivHouseholderQR& compute(const MatrixType& matrix); + /** \returns a const reference to the column permutation matrix */ const PermutationType& colsPermutation() const { eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); return m_cols_permutation; } + /** \returns a const reference to the vector of indices representing the rows transpositions */ const IntColVectorType& rowsTranspositions() const { eigen_assert(m_isInitialized && "FullPivHouseholderQR is not initialized."); @@ -275,6 +289,11 @@ template class FullPivHouseholderQR inline Index rows() const { return m_qr.rows(); } inline Index cols() const { return m_qr.cols(); } + + /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q. + * + * For advanced uses only. + */ const HCoeffsType& hCoeffs() const { return m_hCoeffs; } /** Allows to prescribe a threshold to be used by certain methods, such as rank(), @@ -377,6 +396,12 @@ typename MatrixType::RealScalar FullPivHouseholderQR::logAbsDetermin return m_qr.diagonal().cwiseAbs().array().log().sum(); } +/** Performs the QR factorization of the given matrix \a matrix. The result of + * the factorization is stored into \c *this, and a reference to \c *this + * is returned. + * + * \sa class FullPivHouseholderQR, FullPivHouseholderQR(const MatrixType&) + */ template FullPivHouseholderQR& FullPivHouseholderQR::compute(const MatrixType& matrix) { diff --git a/Eigen/src/QR/HouseholderQR.h b/Eigen/src/QR/HouseholderQR.h index 0314d5259..5a620f495 100644 --- a/Eigen/src/QR/HouseholderQR.h +++ b/Eigen/src/QR/HouseholderQR.h @@ -60,11 +60,11 @@ template class HouseholderQR typedef typename HouseholderSequence::ConjugateReturnType HouseholderSequenceType; /** - * \brief Default Constructor. - * - * The default constructor is useful in cases in which the user intends to - * perform decompositions via HouseholderQR::compute(const MatrixType&). - */ + * \brief Default Constructor. + * + * The default constructor is useful in cases in which the user intends to + * perform decompositions via HouseholderQR::compute(const MatrixType&). + */ HouseholderQR() : m_qr(), m_hCoeffs(), m_temp(), m_isInitialized(false) {} /** \brief Default Constructor with memory preallocation @@ -79,6 +79,18 @@ template class HouseholderQR m_temp(cols), m_isInitialized(false) {} + /** \brief Constructs a QR factorization from a given matrix + * + * This constructor computes the QR factorization of the matrix \a matrix by calling + * the method compute(). It is a short cut for: + * + * \code + * HouseholderQR qr(matrix.rows(), matrix.cols()); + * qr.compute(matrix); + * \endcode + * + * \sa compute() + */ HouseholderQR(const MatrixType& matrix) : m_qr(matrix.rows(), matrix.cols()), m_hCoeffs((std::min)(matrix.rows(),matrix.cols())), @@ -169,6 +181,11 @@ template class HouseholderQR inline Index rows() const { return m_qr.rows(); } inline Index cols() const { return m_qr.cols(); } + + /** \returns a const reference to the vector of Householder coefficients used to represent the factor \c Q. + * + * For advanced uses only. + */ const HCoeffsType& hCoeffs() const { return m_hCoeffs; } protected: @@ -317,6 +334,12 @@ struct solve_retval, Rhs> } // end namespace internal +/** Performs the QR factorization of the given matrix \a matrix. The result of + * the factorization is stored into \c *this, and a reference to \c *this + * is returned. + * + * \sa class HouseholderQR, HouseholderQR(const MatrixType&) + */ template HouseholderQR& HouseholderQR::compute(const MatrixType& matrix) { -- cgit v1.2.3 From 26c35b95c782fa1359812acc8e4de507c223e36f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 10 Jun 2013 12:03:55 +0200 Subject: Fix bug #598: add explicit cast to Scalar type --- Eigen/src/Geometry/EulerAngles.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Geometry/EulerAngles.h b/Eigen/src/Geometry/EulerAngles.h index 3f6ecc6d9..28135a954 100644 --- a/Eigen/src/Geometry/EulerAngles.h +++ b/Eigen/src/Geometry/EulerAngles.h @@ -54,9 +54,9 @@ MatrixBase::eulerAngles(Index a0, Index a1, Index a2) const if (a0==a2) { res[0] = atan2(coeff(j,i), coeff(k,i)); - if((odd && res[0]<0) || ((!odd) && res[0]>0)) + if((odd && res[0]Scalar(0))) { - res[0] = (res[0] > 0) ? res[0] - M_PI : res[0] + M_PI; + res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI); Scalar s2 = Vector2(coeff(j,i), coeff(k,i)).norm(); res[1] = -atan2(s2, coeff(i,i)); } @@ -84,8 +84,8 @@ MatrixBase::eulerAngles(Index a0, Index a1, Index a2) const { res[0] = atan2(coeff(j,k), coeff(k,k)); Scalar c2 = Vector2(coeff(i,i), coeff(i,j)).norm(); - if((odd && res[0]<0) || ((!odd) && res[0]>0)) { - res[0] = (res[0] > 0) ? res[0] - M_PI : res[0] + M_PI; + if((odd && res[0]Scalar(0))) { + res[0] = (res[0] > Scalar(0)) ? res[0] - Scalar(M_PI) : res[0] + Scalar(M_PI); res[1] = atan2(-coeff(i,k), -c2); } else -- cgit v1.2.3 From ca67c6015031d9740034e98774ff8de5f5bbf865 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Mon, 10 Jun 2013 15:59:03 +0200 Subject: Fix bug #591: minor optimization in NEON vectorization support --- Eigen/src/Core/arch/NEON/Complex.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/arch/NEON/Complex.h b/Eigen/src/Core/arch/NEON/Complex.h index 795b4be73..f183d31de 100644 --- a/Eigen/src/Core/arch/NEON/Complex.h +++ b/Eigen/src/Core/arch/NEON/Complex.h @@ -68,7 +68,6 @@ template<> EIGEN_STRONG_INLINE Packet2cf pconj(const Packet2cf& a) template<> EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, const Packet2cf& b) { Packet4f v1, v2; - float32x2_t a_lo, a_hi; // Get the real values of a | a1_re | a1_re | a2_re | a2_re | v1 = vcombine_f32(vdup_lane_f32(vget_low_f32(a.v), 0), vdup_lane_f32(vget_high_f32(a.v), 0)); @@ -81,9 +80,7 @@ template<> EIGEN_STRONG_INLINE Packet2cf pmul(const Packet2cf& a, con // Conjugate v2 v2 = vreinterpretq_f32_u32(veorq_u32(vreinterpretq_u32_f32(v2), p4ui_CONJ_XOR)); // Swap real/imag elements in v2. - a_lo = vrev64_f32(vget_low_f32(v2)); - a_hi = vrev64_f32(vget_high_f32(v2)); - v2 = vcombine_f32(a_lo, a_hi); + v2 = vrev64q_f32(v2); // Add and return the result return Packet2cf(vaddq_f32(v1, v2)); } @@ -241,13 +238,10 @@ template<> EIGEN_STRONG_INLINE Packet2cf pdiv(const Packet2cf& a, con // TODO optimize it for AltiVec Packet2cf res = conj_helper().pmul(a,b); Packet4f s, rev_s; - float32x2_t a_lo, a_hi; // this computes the norm s = vmulq_f32(b.v, b.v); - a_lo = vrev64_f32(vget_low_f32(s)); - a_hi = vrev64_f32(vget_high_f32(s)); - rev_s = vcombine_f32(a_lo, a_hi); + rev_s = vrev64q_f32(s); return Packet2cf(pdiv(res.v, vaddq_f32(s,rev_s))); } -- cgit v1.2.3 From 18e476107e5b1b38d3e13888f2afda6b1a8b6a87 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 10 Jun 2013 17:16:16 +0200 Subject: Fix bug #583: add compile-time check that DenseIndex is signed --- Eigen/src/Core/DenseBase.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'Eigen') diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index dfdf6c4a8..4e8b820bb 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -13,6 +13,16 @@ namespace Eigen { +namespace internal { + +// The index type defined by EIGEN_DEFAULT_DENSE_INDEX_TYPE must be a signed type. +// This dummy function simply aims at checking that at compile time. +static inline void check_DenseIndex_is_signed() { + EIGEN_STATIC_ASSERT(NumTraits::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE); +} + +} // end namespace internal + /** \class DenseBase * \ingroup Core_Module * -- cgit v1.2.3 From 4cd8245c968577bc94d4cf149e386a597ac7079f Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Tue, 11 Jun 2013 14:42:29 +0200 Subject: Add support with unit test for off-diagonal sparse matrix views --- Eigen/src/SparseCore/SparseTriangularView.h | 27 ++++++++++++++++++++------- test/sparse_basic.cpp | 17 +++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseTriangularView.h b/Eigen/src/SparseCore/SparseTriangularView.h index 68c4c3397..88a345b22 100644 --- a/Eigen/src/SparseCore/SparseTriangularView.h +++ b/Eigen/src/SparseCore/SparseTriangularView.h @@ -2,6 +2,7 @@ // for linear algebra. // // Copyright (C) 2009 Gael Guennebaud +// Copyright (C) 2012 Désiré Nuentsa-Wakam // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed @@ -27,6 +28,7 @@ template class SparseTriangularView enum { SkipFirst = ((Mode&Lower) && !(MatrixType::Flags&RowMajorBit)) || ((Mode&Upper) && (MatrixType::Flags&RowMajorBit)), SkipLast = !SkipFirst, + SkipDiag = (Mode&ZeroDiag) ? 1 : 0, HasUnitDiag = (Mode&UnitDiag) ? 1 : 0 }; @@ -71,7 +73,7 @@ class SparseTriangularView::InnerIterator : public MatrixTypeNe { if(SkipFirst) { - while((*this) && (HasUnitDiag ? this->index()<=outer : this->index()index()<=outer : this->index()::InnerIterator : public MatrixTypeNe return *this; } - inline Index row() const { return Base::row(); } - inline Index col() const { return Base::col(); } + inline Index row() const { return (MatrixType::Flags&RowMajorBit ? Base::outer() : this->index()); } + inline Index col() const { return (MatrixType::Flags&RowMajorBit ? this->index() : Base::outer()); } inline Index index() const { if(HasUnitDiag && m_returnOne) return Base::outer(); @@ -118,7 +120,12 @@ class SparseTriangularView::InnerIterator : public MatrixTypeNe { if(HasUnitDiag && m_returnOne) return true; - return (SkipFirst ? Base::operator bool() : (Base::operator bool() && this->index() <= this->outer())); + if(SkipFirst) return Base::operator bool(); + else + { + if (SkipDiag) return (Base::operator bool() && this->index() < this->outer()); + else return (Base::operator bool() && this->index() <= this->outer()); + } } protected: bool m_returnOne; @@ -134,9 +141,10 @@ class SparseTriangularView::ReverseInnerIterator : public Matri : Base(view.nestedExpression(), outer) { eigen_assert((!HasUnitDiag) && "ReverseInnerIterator does not support yet triangular views with a unit diagonal"); - if(SkipLast) - while((*this) && this->index()>outer) + if(SkipLast) { + while((*this) && (SkipDiag ? this->index()>=outer : this->index()>outer)) --(*this); + } } EIGEN_STRONG_INLINE ReverseInnerIterator& operator--() @@ -147,7 +155,12 @@ class SparseTriangularView::ReverseInnerIterator : public Matri EIGEN_STRONG_INLINE operator bool() const { - return SkipLast ? Base::operator bool() : (Base::operator bool() && this->index() >= this->outer()); + if (SkipLast) return Base::operator bool() ; + else + { + if(SkipDiag) return (Base::operator bool() && this->index() > this->outer()); + else return (Base::operator bool() && this->index() >= this->outer()); + } } }; diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 121cc05b1..2f92f1627 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -3,6 +3,7 @@ // // Copyright (C) 2008-2011 Gael Guennebaud // Copyright (C) 2008 Daniel Gomez Ferro +// Copyright (C) 2013 Désiré Nuentsa-Wakam // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed @@ -391,6 +392,14 @@ template void sparse_basic(const SparseMatrixType& re refMat3 = refMat2.template triangularView(); m3 = m2.template triangularView(); VERIFY_IS_APPROX(m3, refMat3); + + refMat3 = refMat2.template triangularView(); + m3 = m2.template triangularView(); + VERIFY_IS_APPROX(m3, refMat3); + + refMat3 = refMat2.template triangularView(); + m3 = m2.template triangularView(); + VERIFY_IS_APPROX(m3, refMat3); } // test selfadjointView @@ -454,6 +463,14 @@ template void sparse_basic(const SparseMatrixType& re } } + + // test Identity matrix + { + DenseMatrix refMat1 = DenseMatrix::Identity(rows, rows); + SparseMatrixType m1(rows, rows); + m1.setIdentity(); + VERIFY_IS_APPROX(m1, refMat1); + } } void test_sparse_basic() -- cgit v1.2.3 From 9266f65318381bd34ddc719f21f8fa9b4e1521e4 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Tue, 11 Jun 2013 14:46:13 +0200 Subject: Fix bug #588 : Compute a determinant using SparseLU --- Eigen/src/SparseLU/SparseLU.h | 82 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index 5475e17f4..c8dcbfa21 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -85,11 +85,11 @@ class SparseLU : public internal::SparseLUImpl Base; public: - SparseLU():m_isInitialized(true),m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0) + SparseLU():m_isInitialized(true),m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0),m_detPermR(1) { initperfvalues(); } - SparseLU(const MatrixType& matrix):m_isInitialized(true),m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0) + SparseLU(const MatrixType& matrix):m_isInitialized(true),m_lastError(""),m_Ustore(0,0,0,0,0,0),m_symmetricmode(false),m_diagpivotthresh(1.0),m_detPermR(1) { initperfvalues(); compute(matrix); @@ -215,6 +215,7 @@ class SparseLU : public internal::SparseLUImpl bool _solve(const MatrixBase &B, MatrixBase &_X) const { @@ -239,12 +240,80 @@ class SparseLU : public internal::SparseLUImplcols(); ++j) + { + for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) + { + if(it.row() < j) continue; + if(it.row() == j) + { + det *= (std::abs)(it.value()); + break; + } + } + } + return det; + } + + /** \returns the natural log of the absolute value of the determinant of the matrix + * of which **this is the QR decomposition + * + * \note This method is useful to work around the risk of overflow/underflow that's + * inherent to the determinant computation + *a + * \sa absDeterminant(), signDeterminant() + */ + Scalar logAbsDeterminant() const + { + eigen_assert(m_factorizationIsOk && "The matrix should be factorized first."); + Scalar det = Scalar(0.); + for (Index j = 0; j < this->cols(); ++j) + { + for (typename SCMatrix::InnerIterator it(m_Lstore, j); it; ++it) + { + if(it.row() < j) continue; + if(it.row() == j) + { + det += (std::log)((std::abs)(it.value())); + break; + } + } + } + return det; + } + + /** \returns A number representing the sign of the determinant + * + * \sa absDeterminant(), logAbsDeterminant() + */ + Scalar signDeterminant() + { + eigen_assert(m_factorizationIsOk && "The matrix should be factorized first."); + return Scalar(m_detPermR); + } protected: // Functions void initperfvalues() { - m_perfv.panel_size = 12; + m_perfv.panel_size = 1; m_perfv.relax = 1; m_perfv.maxsuper = 128; m_perfv.rowblk = 16; @@ -273,7 +342,7 @@ class SparseLU : public internal::SparseLUImpl m_perfv; RealScalar m_diagpivotthresh; // Specifies the threshold used for a diagonal entry to be an acceptable pivot Index m_nnzL, m_nnzU; // Nonzeros in L and U factors - + Index m_detPermR; // Determinant of the coefficient matrix private: // Copy constructor SparseLU (SparseLU& ) {} @@ -281,6 +350,7 @@ class SparseLU : public internal::SparseLUImpl::factorize(const MatrixType& matrix) m_perm_r.resize(m); m_perm_r.indices().setConstant(-1); marker.setConstant(-1); + m_detPermR = 1.0; // Record the determinant of the row permutation m_glu.supno(0) = emptyIdxLU; m_glu.xsup.setConstant(0); m_glu.xsup(0) = m_glu.xlsub(0) = m_glu.xusub(0) = m_glu.xlusup(0) = Index(0); @@ -528,6 +599,9 @@ void SparseLU::factorize(const MatrixType& matrix) return; } + // Update the determinant of the row permutation matrix + if (pivrow != jj) m_detPermR *= -1; + // Prune columns (0:jj-1) using column jj Base::pruneL(jj, m_perm_r.indices(), pivrow, nseg, segrep, repfnz_k, xprune, m_glu); -- cgit v1.2.3 From 1bf18bd57feed5d23c752c97457c2a9884e291bb Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Tue, 11 Jun 2013 14:48:04 +0200 Subject: Fix bug in SparseLU dfs for dense matrices --- Eigen/src/SparseLU/SparseLU_column_dfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseLU/SparseLU_column_dfs.h b/Eigen/src/SparseLU/SparseLU_column_dfs.h index bd450ddc7..bc4cfbf37 100644 --- a/Eigen/src/SparseLU/SparseLU_column_dfs.h +++ b/Eigen/src/SparseLU/SparseLU_column_dfs.h @@ -101,7 +101,7 @@ Index SparseLUImpl::column_dfs(const Index m, const Index jcol, In column_dfs_traits traits(jcol, jsuper, glu, *this); // For each nonzero in A(*,jcol) do dfs - for (Index k = 0; lsub_col[k] != emptyIdxLU; k++) + for (Index k = 0; ((k < m) ? lsub_col[k] != emptyIdxLU : false) ; k++) { Index krow = lsub_col(k); lsub_col(k) = emptyIdxLU; -- cgit v1.2.3 From f3af423c70af094aa6c6a550525bcd6addb421a5 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 11 Jun 2013 21:13:30 +0200 Subject: Add missing dependency in SparseSholesky header --- Eigen/SparseCholesky | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/SparseCholesky b/Eigen/SparseCholesky index 800f17bc4..9f5056aa1 100644 --- a/Eigen/SparseCholesky +++ b/Eigen/SparseCholesky @@ -1,7 +1,17 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2008-2013 Gael Guennebaud +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. + #ifndef EIGEN_SPARSECHOLESKY_MODULE_H #define EIGEN_SPARSECHOLESKY_MODULE_H #include "SparseCore" +#include "OrderingMethods" #include "src/Core/util/DisableStupidWarnings.h" @@ -26,7 +36,6 @@ #include "src/misc/Solve.h" #include "src/misc/SparseSolve.h" - #include "src/SparseCholesky/SimplicialCholesky.h" #ifndef EIGEN_MPL2_ONLY -- cgit v1.2.3 From 7742eacfebaad92649ea033fd0ce55a69dd74336 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 12 Jun 2013 09:22:59 +0200 Subject: Add default value for IsRepeatable in functor_traits --- Eigen/src/Core/util/XprHelper.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 3d1290cd2..3c4773054 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -91,7 +91,8 @@ template struct functor_traits enum { Cost = 10, - PacketAccess = false + PacketAccess = false, + IsRepeatable = false }; }; -- cgit v1.2.3 From 92eb807c30962bacfc194e7f845892dd2dc4f7f4 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 12 Jun 2013 09:24:07 +0200 Subject: Fix warning: explicitely initialize all member of IOFormat --- Eigen/src/Core/IO.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/IO.h b/Eigen/src/Core/IO.h index 50bf93d9f..c8d5f6379 100644 --- a/Eigen/src/Core/IO.h +++ b/Eigen/src/Core/IO.h @@ -55,7 +55,7 @@ struct IOFormat const std::string& _rowSeparator = "\n", const std::string& _rowPrefix="", const std::string& _rowSuffix="", const std::string& _matPrefix="", const std::string& _matSuffix="") : matPrefix(_matPrefix), matSuffix(_matSuffix), rowPrefix(_rowPrefix), rowSuffix(_rowSuffix), rowSeparator(_rowSeparator), - coeffSeparator(_coeffSeparator), precision(_precision), flags(_flags) + rowSpacer(""), coeffSeparator(_coeffSeparator), precision(_precision), flags(_flags) { int i = int(matSuffix.length())-1; while (i>=0 && matSuffix[i]!='\n') -- cgit v1.2.3 From 62670c83a0ba7cb4f45a734a4817a818a7c92bba Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 10 Jun 2013 23:40:56 +0200 Subject: Fix bug #314: move remaining math functions from internal to numext namespace --- Eigen/Core | 2 +- Eigen/src/Cholesky/LDLT.h | 18 +- Eigen/src/Cholesky/LLT.h | 10 +- Eigen/src/Core/Dot.h | 4 +- Eigen/src/Core/Functors.h | 16 +- Eigen/src/Core/Fuzzy.h | 4 +- Eigen/src/Core/GeneralProduct.h | 2 +- Eigen/src/Core/GlobalFunctions.h | 3 +- Eigen/src/Core/MathFunctions.h | 218 +++++++++++---------- Eigen/src/Core/SelfAdjointView.h | 12 +- Eigen/src/Core/StableNorm.h | 10 +- Eigen/src/Core/arch/SSE/Complex.h | 8 +- Eigen/src/Core/products/GeneralMatrixVector.h | 2 +- Eigen/src/Core/products/SelfadjointMatrixMatrix.h | 34 ++-- Eigen/src/Core/products/SelfadjointMatrixVector.h | 12 +- Eigen/src/Core/products/SelfadjointRank2Update.h | 12 +- Eigen/src/Core/products/TriangularMatrixVector.h | 2 +- Eigen/src/Core/util/BlasUtil.h | 10 +- Eigen/src/Eigen2Support/MathFunctions.h | 10 +- Eigen/src/Eigen2Support/SVD.h | 8 +- Eigen/src/Eigenvalues/ComplexEigenSolver.h | 2 +- Eigen/src/Eigenvalues/ComplexSchur.h | 10 +- Eigen/src/Eigenvalues/EigenSolver.h | 26 +-- Eigen/src/Eigenvalues/HessenbergDecomposition.h | 2 +- Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h | 16 +- Eigen/src/Eigenvalues/SelfAdjointEigenSolver_MKL.h | 2 +- Eigen/src/Eigenvalues/Tridiagonalization.h | 8 +- Eigen/src/Geometry/OrthoMethods.h | 26 +-- Eigen/src/Householder/Householder.h | 10 +- .../src/IterativeLinearSolvers/ConjugateGradient.h | 4 +- Eigen/src/IterativeLinearSolvers/IncompleteLUT.h | 2 +- Eigen/src/Jacobi/Jacobi.h | 50 ++--- Eigen/src/MetisSupport/MetisSupport.h | 2 +- Eigen/src/QR/ColPivHouseholderQR.h | 2 +- Eigen/src/QR/FullPivHouseholderQR.h | 2 +- Eigen/src/SVD/JacobiSVD.h | 8 +- Eigen/src/SparseCholesky/SimplicialCholesky.h | 4 +- Eigen/src/SparseCholesky/SimplicialCholesky_impl.h | 8 +- Eigen/src/SparseCore/SparseDot.h | 6 +- Eigen/src/SparseCore/SparseSelfAdjointView.h | 11 +- Eigen/src/SparseCore/SparseView.h | 2 +- Eigen/src/SparseQR/SparseQR.h | 12 +- Eigen/src/UmfPackSupport/UmfPackSupport.h | 14 +- test/adjoint.cpp | 14 +- test/array.cpp | 8 +- test/array_for_matrix.cpp | 6 +- test/basicstuff.cpp | 8 +- test/block.cpp | 8 +- test/determinant.cpp | 2 +- test/eigen2support.cpp | 4 +- test/householder.cpp | 8 +- test/jacobi.cpp | 6 +- test/main.h | 2 +- test/packetmath.cpp | 2 +- test/product_extra.cpp | 2 +- test/product_selfadjoint.cpp | 4 +- test/product_trmm.cpp | 2 +- test/redux.cpp | 28 +-- test/sparse.h | 4 +- test/spqr_support.cpp | 2 +- test/triangular.cpp | 2 +- test/umeyama.cpp | 2 +- unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h | 12 +- unsupported/Eigen/src/AutoDiff/AutoDiffVector.h | 4 +- unsupported/Eigen/src/IterativeSolvers/DGMRES.h | 2 +- .../Eigen/src/LevenbergMarquardt/LMonestep.h | 6 +- .../Eigen/src/MatrixFunctions/MatrixPowerBase.h | 2 +- .../NonLinearOptimization/HybridNonLinearSolver.h | 8 +- .../src/NonLinearOptimization/LevenbergMarquardt.h | 12 +- .../Eigen/src/Polynomials/PolynomialSolver.h | 8 +- .../Eigen/src/Polynomials/PolynomialUtils.h | 2 +- 71 files changed, 408 insertions(+), 388 deletions(-) (limited to 'Eigen') diff --git a/Eigen/Core b/Eigen/Core index 8197c944f..7e068cbbd 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -245,8 +245,8 @@ using std::ptrdiff_t; #include "src/Core/util/Constants.h" #include "src/Core/util/ForwardDeclarations.h" #include "src/Core/util/Meta.h" -#include "src/Core/util/XprHelper.h" #include "src/Core/util/StaticAssert.h" +#include "src/Core/util/XprHelper.h" #include "src/Core/util/Memory.h" #include "src/Core/NumTraits.h" diff --git a/Eigen/src/Cholesky/LDLT.h b/Eigen/src/Cholesky/LDLT.h index d933b10d4..d19cb3968 100644 --- a/Eigen/src/Cholesky/LDLT.h +++ b/Eigen/src/Cholesky/LDLT.h @@ -259,7 +259,7 @@ template<> struct ldlt_inplace { transpositions.setIdentity(); if(sign) - *sign = real(mat.coeff(0,0))>0 ? 1:-1; + *sign = numext::real(mat.coeff(0,0))>0 ? 1:-1; return true; } @@ -300,11 +300,11 @@ template<> struct ldlt_inplace for(int i=k+1;i::IsComplex) - mat.coeffRef(index_of_biggest_in_corner,k) = conj(mat.coeff(index_of_biggest_in_corner,k)); + mat.coeffRef(index_of_biggest_in_corner,k) = numext::conj(mat.coeff(index_of_biggest_in_corner,k)); } // partition the matrix: @@ -329,7 +329,7 @@ template<> struct ldlt_inplace if(sign) { // LDLT is not guaranteed to work for indefinite matrices, but let's try to get the sign right - int newSign = real(mat.diagonal().coeff(index_of_biggest_in_corner)) > 0; + int newSign = numext::real(mat.diagonal().coeff(index_of_biggest_in_corner)) > 0; if(k == 0) *sign = newSign; else if(*sign != newSign) @@ -350,7 +350,7 @@ template<> struct ldlt_inplace template static bool updateInPlace(MatrixType& mat, MatrixBase& w, const typename MatrixType::RealScalar& sigma=1) { - using internal::isfinite; + using numext::isfinite; typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; typedef typename MatrixType::Index Index; @@ -368,9 +368,9 @@ template<> struct ldlt_inplace break; // Update the diagonal terms - RealScalar dj = real(mat.coeff(j,j)); + RealScalar dj = numext::real(mat.coeff(j,j)); Scalar wj = w.coeff(j); - RealScalar swj2 = sigma*abs2(wj); + RealScalar swj2 = sigma*numext::abs2(wj); RealScalar gamma = dj*alpha + swj2; mat.coeffRef(j,j) += swj2/alpha; @@ -381,7 +381,7 @@ template<> struct ldlt_inplace Index rs = size-j-1; w.tail(rs) -= wj * mat.col(j).tail(rs); if(gamma != 0) - mat.col(j).tail(rs) += (sigma*conj(wj)/gamma)*w.tail(rs); + mat.col(j).tail(rs) += (sigma*numext::conj(wj)/gamma)*w.tail(rs); } return true; } diff --git a/Eigen/src/Cholesky/LLT.h b/Eigen/src/Cholesky/LLT.h index db22a2f85..2e6189f7d 100644 --- a/Eigen/src/Cholesky/LLT.h +++ b/Eigen/src/Cholesky/LLT.h @@ -232,10 +232,10 @@ static typename MatrixType::Index llt_rank_update_lower(MatrixType& mat, const V RealScalar beta = 1; for(Index j=0; j struct llt_inplace Block A10(mat,k,0,1,k); Block A20(mat,k+1,0,rs,k); - RealScalar x = real(mat.coeff(k,k)); + RealScalar x = numext::real(mat.coeff(k,k)); if (k>0) x -= A10.squaredNorm(); if (x<=RealScalar(0)) return k; diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index 9d513d699..e4107a1ac 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -112,7 +112,7 @@ MatrixBase::eigen2_dot(const MatrixBase& other) const template EIGEN_STRONG_INLINE typename NumTraits::Scalar>::Real MatrixBase::squaredNorm() const { - return internal::real((*this).cwiseAbs2().sum()); + return numext::real((*this).cwiseAbs2().sum()); } /** \returns, for vectors, the \em l2 norm of \c *this, and for matrices the Frobenius norm. @@ -228,7 +228,7 @@ bool MatrixBase::isOrthogonal { typename internal::nested::type nested(derived()); typename internal::nested::type otherNested(other.derived()); - return internal::abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm(); + return numext::abs2(nested.dot(otherNested)) <= prec * prec * nested.squaredNorm() * otherNested.squaredNorm(); } /** \returns true if *this is approximately an unitary matrix, diff --git a/Eigen/src/Core/Functors.h b/Eigen/src/Core/Functors.h index 9a84e8f26..04fb21732 100644 --- a/Eigen/src/Core/Functors.h +++ b/Eigen/src/Core/Functors.h @@ -171,7 +171,7 @@ struct functor_traits > { */ template struct scalar_binary_pow_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_binary_pow_op) - inline Scalar operator() (const Scalar& a, const OtherScalar& b) const { return internal::pow(a, b); } + inline Scalar operator() (const Scalar& a, const OtherScalar& b) const { return numext::pow(a, b); } }; template struct functor_traits > { @@ -310,7 +310,7 @@ struct functor_traits > template struct scalar_abs2_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_abs2_op) typedef typename NumTraits::Real result_type; - EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return internal::abs2(a); } + EIGEN_STRONG_INLINE const result_type operator() (const Scalar& a) const { return numext::abs2(a); } template EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const { return internal::pmul(a,a); } @@ -326,7 +326,7 @@ struct functor_traits > */ template struct scalar_conjugate_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_conjugate_op) - EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { using internal::conj; return conj(a); } + EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { using numext::conj; return conj(a); } template EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a) const { return internal::pconj(a); } }; @@ -363,7 +363,7 @@ template struct scalar_real_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_real_op) typedef typename NumTraits::Real result_type; - EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return internal::real(a); } + EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::real(a); } }; template struct functor_traits > @@ -378,7 +378,7 @@ template struct scalar_imag_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_op) typedef typename NumTraits::Real result_type; - EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return internal::imag(a); } + EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::imag(a); } }; template struct functor_traits > @@ -393,7 +393,7 @@ template struct scalar_real_ref_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_real_ref_op) typedef typename NumTraits::Real result_type; - EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return internal::real_ref(*const_cast(&a)); } + EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::real_ref(*const_cast(&a)); } }; template struct functor_traits > @@ -408,7 +408,7 @@ template struct scalar_imag_ref_op { EIGEN_EMPTY_STRUCT_CTOR(scalar_imag_ref_op) typedef typename NumTraits::Real result_type; - EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return internal::imag_ref(*const_cast(&a)); } + EIGEN_STRONG_INLINE result_type& operator() (const Scalar& a) const { return numext::imag_ref(*const_cast(&a)); } }; template struct functor_traits > @@ -801,7 +801,7 @@ struct scalar_pow_op { // FIXME default copy constructors seems bugged with std::complex<> inline scalar_pow_op(const scalar_pow_op& other) : m_exponent(other.m_exponent) { } inline scalar_pow_op(const Scalar& exponent) : m_exponent(exponent) {} - inline Scalar operator() (const Scalar& a) const { return internal::pow(a, m_exponent); } + inline Scalar operator() (const Scalar& a) const { return numext::pow(a, m_exponent); } const Scalar m_exponent; }; template diff --git a/Eigen/src/Core/Fuzzy.h b/Eigen/src/Core/Fuzzy.h index 8fb9a01dd..fe63bd298 100644 --- a/Eigen/src/Core/Fuzzy.h +++ b/Eigen/src/Core/Fuzzy.h @@ -42,7 +42,7 @@ struct isMuchSmallerThan_object_selector { static bool run(const Derived& x, const OtherDerived& y, const typename Derived::RealScalar& prec) { - return x.cwiseAbs2().sum() <= abs2(prec) * y.cwiseAbs2().sum(); + return x.cwiseAbs2().sum() <= numext::abs2(prec) * y.cwiseAbs2().sum(); } }; @@ -60,7 +60,7 @@ struct isMuchSmallerThan_scalar_selector { static bool run(const Derived& x, const typename Derived::RealScalar& y, const typename Derived::RealScalar& prec) { - return x.cwiseAbs2().sum() <= abs2(prec * y); + return x.cwiseAbs2().sum() <= numext::abs2(prec * y); } }; diff --git a/Eigen/src/Core/GeneralProduct.h b/Eigen/src/Core/GeneralProduct.h index 4e6448353..2a59d9464 100644 --- a/Eigen/src/Core/GeneralProduct.h +++ b/Eigen/src/Core/GeneralProduct.h @@ -435,7 +435,7 @@ template<> struct gemv_selector gemv_static_vector_if static_dest; - bool alphaIsCompatible = (!ComplexByReal) || (imag(actualAlpha)==RealScalar(0)); + bool alphaIsCompatible = (!ComplexByReal) || (numext::imag(actualAlpha)==RealScalar(0)); bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible; RhsScalar compatibleAlpha = get_factor::run(actualAlpha); diff --git a/Eigen/src/Core/GlobalFunctions.h b/Eigen/src/Core/GlobalFunctions.h index 02cae552e..2acf97723 100644 --- a/Eigen/src/Core/GlobalFunctions.h +++ b/Eigen/src/Core/GlobalFunctions.h @@ -39,6 +39,7 @@ namespace Eigen { EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(real,scalar_real_op) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(imag,scalar_imag_op) + EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(conj,scalar_conjugate_op) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sin,scalar_sin_op) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cos,scalar_cos_op) EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asin,scalar_asin_op) @@ -86,6 +87,6 @@ namespace Eigen } } -// TODO: cleanly disable those functions that are not supported on Array (internal::real_ref, internal::random, internal::isApprox...) +// TODO: cleanly disable those functions that are not supported on Array (numext::real_ref, internal::random, internal::isApprox...) #endif // EIGEN_GLOBAL_FUNCTIONS_H diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index a2c55f255..5df2d8bca 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -51,16 +51,15 @@ struct global_math_functions_filtering_base typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type; }; -#define EIGEN_MATHFUNC_IMPL(func, scalar) func##_impl::type> -#define EIGEN_MATHFUNC_RETVAL(func, scalar) typename func##_retval::type>::type - +#define EIGEN_MATHFUNC_IMPL(func, scalar) Eigen::internal::func##_impl::type> +#define EIGEN_MATHFUNC_RETVAL(func, scalar) typename Eigen::internal::func##_retval::type>::type /**************************************************************************** * Implementation of real * ****************************************************************************/ -template -struct real_impl +template::IsComplex> +struct real_default_impl { typedef typename NumTraits::Real RealScalar; static inline RealScalar run(const Scalar& x) @@ -69,34 +68,32 @@ struct real_impl } }; -template -struct real_impl > +template +struct real_default_impl { - static inline RealScalar run(const std::complex& x) + typedef typename NumTraits::Real RealScalar; + static inline RealScalar run(const Scalar& x) { using std::real; return real(x); } }; +template struct real_impl : real_default_impl {}; + template struct real_retval { typedef typename NumTraits::Real type; }; -template -inline EIGEN_MATHFUNC_RETVAL(real, Scalar) real(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x); -} /**************************************************************************** * Implementation of imag * ****************************************************************************/ -template -struct imag_impl +template::IsComplex> +struct imag_default_impl { typedef typename NumTraits::Real RealScalar; static inline RealScalar run(const Scalar&) @@ -105,28 +102,25 @@ struct imag_impl } }; -template -struct imag_impl > +template +struct imag_default_impl { - static inline RealScalar run(const std::complex& x) + typedef typename NumTraits::Real RealScalar; + static inline RealScalar run(const Scalar& x) { using std::imag; return imag(x); } }; +template struct imag_impl : imag_default_impl {}; + template struct imag_retval { typedef typename NumTraits::Real type; }; -template -inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) imag(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x); -} - /**************************************************************************** * Implementation of real_ref * ****************************************************************************/ @@ -151,18 +145,6 @@ struct real_ref_retval typedef typename NumTraits::Real & type; }; -template -inline typename add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(const Scalar& x) -{ - return real_ref_impl::run(x); -} - -template -inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x); -} - /**************************************************************************** * Implementation of imag_ref * ****************************************************************************/ @@ -203,23 +185,11 @@ struct imag_ref_retval typedef typename NumTraits::Real & type; }; -template -inline typename add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(const Scalar& x) -{ - return imag_ref_impl::run(x); -} - -template -inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x); -} - /**************************************************************************** * Implementation of conj * ****************************************************************************/ -template +template::IsComplex> struct conj_impl { static inline Scalar run(const Scalar& x) @@ -228,10 +198,10 @@ struct conj_impl } }; -template -struct conj_impl > +template +struct conj_impl { - static inline std::complex run(const std::complex& x) + static inline Scalar run(const Scalar& x) { using std::conj; return conj(x); @@ -244,12 +214,6 @@ struct conj_retval typedef Scalar type; }; -template -inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) conj(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x); -} - /**************************************************************************** * Implementation of abs2 * ****************************************************************************/ @@ -279,12 +243,6 @@ struct abs2_retval typedef typename NumTraits::Real type; }; -template -inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x); -} - /**************************************************************************** * Implementation of norm1 * ****************************************************************************/ @@ -319,12 +277,6 @@ struct norm1_retval typedef typename NumTraits::Real type; }; -template -inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(const Scalar& x) -{ - return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x); -} - /**************************************************************************** * Implementation of hypot * ****************************************************************************/ @@ -342,6 +294,7 @@ struct hypot_impl RealScalar _x = abs(x); RealScalar _y = abs(y); RealScalar p = (max)(_x, _y); + if(p==RealScalar(0)) return 0; RealScalar q = (min)(_x, _y); RealScalar qp = q/p; return p * sqrt(RealScalar(1) + qp*qp); @@ -354,12 +307,6 @@ struct hypot_retval typedef typename NumTraits::Real type; }; -template -inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(const Scalar& x, const Scalar& y) -{ - return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y); -} - /**************************************************************************** * Implementation of cast * ****************************************************************************/ @@ -422,12 +369,6 @@ struct atanh2_retval typedef Scalar type; }; -template -inline EIGEN_MATHFUNC_RETVAL(atanh2, Scalar) atanh2(const Scalar& x, const Scalar& y) -{ - return EIGEN_MATHFUNC_IMPL(atanh2, Scalar)::run(x, y); -} - /**************************************************************************** * Implementation of pow * ****************************************************************************/ @@ -471,12 +412,6 @@ struct pow_retval typedef Scalar type; }; -template -inline EIGEN_MATHFUNC_RETVAL(pow, Scalar) pow(const Scalar& x, const Scalar& y) -{ - return EIGEN_MATHFUNC_IMPL(pow, Scalar)::run(x, y); -} - /**************************************************************************** * Implementation of random * ****************************************************************************/ @@ -611,6 +546,97 @@ inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random() return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(); } +} // end namespace internal + +/**************************************************************************** +* Generic math function * +****************************************************************************/ + +namespace numext { + +template +inline EIGEN_MATHFUNC_RETVAL(real, Scalar) real(const Scalar& x) +{ + return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x); +} + +template +inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(const Scalar& x) +{ + return internal::real_ref_impl::run(x); +} + +template +inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x) +{ + return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x); +} + +template +inline EIGEN_MATHFUNC_RETVAL(imag, Scalar) imag(const Scalar& x) +{ + return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x); +} + +template +inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(const Scalar& x) +{ + return internal::imag_ref_impl::run(x); +} + +template +inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x) +{ + return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x); +} + +template +inline EIGEN_MATHFUNC_RETVAL(conj, Scalar) conj(const Scalar& x) +{ + return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x); +} + +template +inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar) abs2(const Scalar& x) +{ + return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x); +} + +template +inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(const Scalar& x) +{ + return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x); +} + +template +inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(const Scalar& x, const Scalar& y) +{ + return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y); +} + +template +inline EIGEN_MATHFUNC_RETVAL(atanh2, Scalar) atanh2(const Scalar& x, const Scalar& y) +{ + return EIGEN_MATHFUNC_IMPL(atanh2, Scalar)::run(x, y); +} + +template +inline EIGEN_MATHFUNC_RETVAL(pow, Scalar) pow(const Scalar& x, const Scalar& y) +{ + return EIGEN_MATHFUNC_IMPL(pow, Scalar)::run(x, y); +} + +// std::isfinite is non standard, so let's define our own version, +// even though it is not very efficient. +template bool (isfinite)(const T& x) +{ + return x::highest() && x>NumTraits::lowest(); +} + +} // end namespace numext + +namespace internal { + /**************************************************************************** * Implementation of fuzzy comparisons * ****************************************************************************/ @@ -668,12 +694,12 @@ struct scalar_fuzzy_default_impl template static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec) { - return abs2(x) <= abs2(y) * prec * prec; + return numext::abs2(x) <= numext::abs2(y) * prec * prec; } static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec) { using std::min; - return abs2(x - y) <= (min)(abs2(x), abs2(y)) * prec * prec; + return numext::abs2(x - y) <= (min)(numext::abs2(x), numext::abs2(y)) * prec * prec; } }; @@ -735,17 +761,7 @@ template<> struct scalar_fuzzy_impl }; -/**************************************************************************** -* Special functions * -****************************************************************************/ - -// std::isfinite is non standard, so let's define our own version, -// even though it is not very efficient. -template bool (isfinite)(const T& x) -{ - return x::highest() && x>NumTraits::lowest(); -} - + } // end namespace internal } // end namespace Eigen diff --git a/Eigen/src/Core/SelfAdjointView.h b/Eigen/src/Core/SelfAdjointView.h index d43789123..6fa7cd15e 100644 --- a/Eigen/src/Core/SelfAdjointView.h +++ b/Eigen/src/Core/SelfAdjointView.h @@ -214,9 +214,9 @@ struct triangular_assignment_selector::run(dst, src); if(row == col) - dst.coeffRef(row, col) = real(src.coeff(row, col)); + dst.coeffRef(row, col) = numext::real(src.coeff(row, col)); else if(row < col) - dst.coeffRef(col, row) = conj(dst.coeffRef(row, col) = src.coeff(row, col)); + dst.coeffRef(col, row) = numext::conj(dst.coeffRef(row, col) = src.coeff(row, col)); } }; @@ -239,9 +239,9 @@ struct triangular_assignment_selector::run(dst, src); if(row == col) - dst.coeffRef(row, col) = real(src.coeff(row, col)); + dst.coeffRef(row, col) = numext::real(src.coeff(row, col)); else if(row > col) - dst.coeffRef(col, row) = conj(dst.coeffRef(row, col) = src.coeff(row, col)); + dst.coeffRef(col, row) = numext::conj(dst.coeffRef(row, col) = src.coeff(row, col)); } }; @@ -262,7 +262,7 @@ struct triangular_assignment_selectorscale) { - ssq = ssq * abs2(scale/max); + ssq = ssq * numext::abs2(scale/max); scale = max; invScale = Scalar(1)/scale; } @@ -84,9 +84,9 @@ blueNorm_impl(const EigenBase& _vec) for(typename Derived::InnerIterator it(vec, 0); it; ++it) { RealScalar ax = abs(it.value()); - if(ax > ab2) abig += internal::abs2(ax*s2m); - else if(ax < b1) asml += internal::abs2(ax*s1m); - else amed += internal::abs2(ax); + if(ax > ab2) abig += numext::abs2(ax*s2m); + else if(ax < b1) asml += numext::abs2(ax*s1m); + else amed += numext::abs2(ax); } if(abig > RealScalar(0)) { @@ -120,7 +120,7 @@ blueNorm_impl(const EigenBase& _vec) if(asml <= abig*relerr) return abig; else - return abig * sqrt(RealScalar(1) + internal::abs2(asml/abig)); + return abig * sqrt(RealScalar(1) + numext::abs2(asml/abig)); } } // end namespace internal diff --git a/Eigen/src/Core/arch/SSE/Complex.h b/Eigen/src/Core/arch/SSE/Complex.h index bd76d75ed..91bba5e38 100644 --- a/Eigen/src/Core/arch/SSE/Complex.h +++ b/Eigen/src/Core/arch/SSE/Complex.h @@ -81,8 +81,8 @@ template<> EIGEN_STRONG_INLINE Packet2cf por (const Packet2cf& a, template<> EIGEN_STRONG_INLINE Packet2cf pxor (const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_xor_ps(a.v,b.v)); } template<> EIGEN_STRONG_INLINE Packet2cf pandnot(const Packet2cf& a, const Packet2cf& b) { return Packet2cf(_mm_andnot_ps(a.v,b.v)); } -template<> EIGEN_STRONG_INLINE Packet2cf pload (const std::complex* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload(&real_ref(*from))); } -template<> EIGEN_STRONG_INLINE Packet2cf ploadu(const std::complex* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu(&real_ref(*from))); } +template<> EIGEN_STRONG_INLINE Packet2cf pload (const std::complex* from) { EIGEN_DEBUG_ALIGNED_LOAD return Packet2cf(pload(&numext::real_ref(*from))); } +template<> EIGEN_STRONG_INLINE Packet2cf ploadu(const std::complex* from) { EIGEN_DEBUG_UNALIGNED_LOAD return Packet2cf(ploadu(&numext::real_ref(*from))); } template<> EIGEN_STRONG_INLINE Packet2cf pset1(const std::complex& from) { @@ -104,8 +104,8 @@ template<> EIGEN_STRONG_INLINE Packet2cf pset1(const std::complex EIGEN_STRONG_INLINE Packet2cf ploaddup(const std::complex* from) { return pset1(*from); } -template<> EIGEN_STRONG_INLINE void pstore >(std::complex * to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&real_ref(*to), from.v); } -template<> EIGEN_STRONG_INLINE void pstoreu >(std::complex * to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&real_ref(*to), from.v); } +template<> EIGEN_STRONG_INLINE void pstore >(std::complex * to, const Packet2cf& from) { EIGEN_DEBUG_ALIGNED_STORE pstore(&numext::real_ref(*to), from.v); } +template<> EIGEN_STRONG_INLINE void pstoreu >(std::complex * to, const Packet2cf& from) { EIGEN_DEBUG_UNALIGNED_STORE pstoreu(&numext::real_ref(*to), from.v); } template<> EIGEN_STRONG_INLINE void prefetch >(const std::complex * addr) { _mm_prefetch((const char*)(addr), _MM_HINT_T0); } diff --git a/Eigen/src/Core/products/GeneralMatrixVector.h b/Eigen/src/Core/products/GeneralMatrixVector.h index 9bdd588df..c1cb78498 100644 --- a/Eigen/src/Core/products/GeneralMatrixVector.h +++ b/Eigen/src/Core/products/GeneralMatrixVector.h @@ -86,7 +86,7 @@ EIGEN_DONT_INLINE void general_matrix_vector_product cj; conj_helper pcj; if(ConjugateRhs) - alpha = conj(alpha); + alpha = numext::conj(alpha); enum { AllAligned = 0, EvenAligned, FirstAligned, NoneAligned }; const Index columnsAtOnce = 4; diff --git a/Eigen/src/Core/products/SelfadjointMatrixMatrix.h b/Eigen/src/Core/products/SelfadjointMatrixMatrix.h index ee619df99..99cf9e0ae 100644 --- a/Eigen/src/Core/products/SelfadjointMatrixMatrix.h +++ b/Eigen/src/Core/products/SelfadjointMatrixMatrix.h @@ -30,9 +30,9 @@ struct symm_pack_lhs for(Index k=i; k::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, IsRowMajor), ConjugateRhs> pcj0; conj_helper::IsComplex && EIGEN_LOGICAL_XOR(ConjugateLhs, !IsRowMajor), ConjugateRhs> pcj1; - Scalar cjAlpha = ConjugateRhs ? conj(alpha) : alpha; + Scalar cjAlpha = ConjugateRhs ? numext::conj(alpha) : alpha; // FIXME this copy is now handled outside product_selfadjoint_vector, so it could probably be removed. // if the rhs is not sequentially stored in memory we copy it to a temporary buffer, @@ -98,8 +98,8 @@ EIGEN_DONT_INLINE void selfadjoint_matrix_vector_product huge speed up) // gcc 4.2 does this optimization automatically. @@ -152,7 +152,7 @@ EIGEN_DONT_INLINE void selfadjoint_matrix_vector_product for (Index i=0; i >(mat+stride*i+i, size-i) += - (conj(alpha) * conj(u.coeff(i))) * v.tail(size-i) - + (alpha * conj(v.coeff(i))) * u.tail(size-i); + (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.tail(size-i) + + (alpha * numext::conj(v.coeff(i))) * u.tail(size-i); } } }; @@ -44,8 +44,8 @@ struct selfadjoint_rank2_update_selector const Index size = u.size(); for (Index i=0; i >(mat+stride*i, i+1) += - (conj(alpha) * conj(u.coeff(i))) * v.head(i+1) - + (alpha * conj(v.coeff(i))) * u.head(i+1); + (numext::conj(alpha) * numext::conj(u.coeff(i))) * v.head(i+1) + + (alpha * numext::conj(v.coeff(i))) * u.head(i+1); } }; @@ -75,9 +75,9 @@ SelfAdjointView& SelfAdjointView enum { IsRowMajor = (internal::traits::Flags&RowMajorBit) ? 1 : 0 }; Scalar actualAlpha = alpha * UBlasTraits::extractScalarFactor(u.derived()) - * internal::conj(VBlasTraits::extractScalarFactor(v.derived())); + * numext::conj(VBlasTraits::extractScalarFactor(v.derived())); if (IsRowMajor) - actualAlpha = internal::conj(actualAlpha); + actualAlpha = numext::conj(actualAlpha); internal::selfadjoint_rank2_update_selector::type>::type, diff --git a/Eigen/src/Core/products/TriangularMatrixVector.h b/Eigen/src/Core/products/TriangularMatrixVector.h index c8b7d28c4..6117d5a82 100644 --- a/Eigen/src/Core/products/TriangularMatrixVector.h +++ b/Eigen/src/Core/products/TriangularMatrixVector.h @@ -245,7 +245,7 @@ template<> struct trmv_selector gemv_static_vector_if static_dest; - bool alphaIsCompatible = (!ComplexByReal) || (imag(actualAlpha)==RealScalar(0)); + bool alphaIsCompatible = (!ComplexByReal) || (numext::imag(actualAlpha)==RealScalar(0)); bool evalToDest = EvalToDestAtCompileTime && alphaIsCompatible; RhsScalar compatibleAlpha = get_factor::run(actualAlpha); diff --git a/Eigen/src/Core/util/BlasUtil.h b/Eigen/src/Core/util/BlasUtil.h index 91496651c..a28f16fa0 100644 --- a/Eigen/src/Core/util/BlasUtil.h +++ b/Eigen/src/Core/util/BlasUtil.h @@ -42,7 +42,7 @@ template struct conj_if; template<> struct conj_if { template - inline T operator()(const T& x) { return conj(x); } + inline T operator()(const T& x) { return numext::conj(x); } template inline T pconj(const T& x) { return internal::pconj(x); } }; @@ -67,7 +67,7 @@ template struct conj_helper, std:: { return c + pmul(x,y); } EIGEN_STRONG_INLINE Scalar pmul(const Scalar& x, const Scalar& y) const - { return Scalar(real(x)*real(y) + imag(x)*imag(y), imag(x)*real(y) - real(x)*imag(y)); } + { return Scalar(numext::real(x)*numext::real(y) + numext::imag(x)*numext::imag(y), numext::imag(x)*numext::real(y) - numext::real(x)*numext::imag(y)); } }; template struct conj_helper, std::complex, true,false> @@ -77,7 +77,7 @@ template struct conj_helper, std:: { return c + pmul(x,y); } EIGEN_STRONG_INLINE Scalar pmul(const Scalar& x, const Scalar& y) const - { return Scalar(real(x)*real(y) + imag(x)*imag(y), real(x)*imag(y) - imag(x)*real(y)); } + { return Scalar(numext::real(x)*numext::real(y) + numext::imag(x)*numext::imag(y), numext::real(x)*numext::imag(y) - numext::imag(x)*numext::real(y)); } }; template struct conj_helper, std::complex, true,true> @@ -87,7 +87,7 @@ template struct conj_helper, std:: { return c + pmul(x,y); } EIGEN_STRONG_INLINE Scalar pmul(const Scalar& x, const Scalar& y) const - { return Scalar(real(x)*real(y) - imag(x)*imag(y), - real(x)*imag(y) - imag(x)*real(y)); } + { return Scalar(numext::real(x)*numext::real(y) - numext::imag(x)*numext::imag(y), - numext::real(x)*numext::imag(y) - numext::imag(x)*numext::real(y)); } }; template struct conj_helper, RealScalar, Conj,false> @@ -113,7 +113,7 @@ template struct get_factor { }; template struct get_factor::Real> { - static EIGEN_STRONG_INLINE typename NumTraits::Real run(const Scalar& x) { return real(x); } + static EIGEN_STRONG_INLINE typename NumTraits::Real run(const Scalar& x) { return numext::real(x); } }; // Lightweight helper class to access matrix coefficients. diff --git a/Eigen/src/Eigen2Support/MathFunctions.h b/Eigen/src/Eigen2Support/MathFunctions.h index bde5dd441..3544af253 100644 --- a/Eigen/src/Eigen2Support/MathFunctions.h +++ b/Eigen/src/Eigen2Support/MathFunctions.h @@ -12,18 +12,18 @@ namespace Eigen { -template inline typename NumTraits::Real ei_real(const T& x) { return internal::real(x); } -template inline typename NumTraits::Real ei_imag(const T& x) { return internal::imag(x); } -template inline T ei_conj(const T& x) { return internal::conj(x); } +template inline typename NumTraits::Real ei_real(const T& x) { return numext::real(x); } +template inline typename NumTraits::Real ei_imag(const T& x) { return numext::imag(x); } +template inline T ei_conj(const T& x) { return numext::conj(x); } template inline typename NumTraits::Real ei_abs (const T& x) { using std::abs; return abs(x); } -template inline typename NumTraits::Real ei_abs2(const T& x) { return internal::abs2(x); } +template inline typename NumTraits::Real ei_abs2(const T& x) { return numext::abs2(x); } template inline T ei_sqrt(const T& x) { using std::sqrt; return sqrt(x); } template inline T ei_exp (const T& x) { using std::exp; return exp(x); } template inline T ei_log (const T& x) { using std::log; return log(x); } template inline T ei_sin (const T& x) { using std::sin; return sin(x); } template inline T ei_cos (const T& x) { using std::cos; return cos(x); } template inline T ei_atan2(const T& x,const T& y) { using std::atan2; return atan2(x,y); } -template inline T ei_pow (const T& x,const T& y) { return internal::pow(x,y); } +template inline T ei_pow (const T& x,const T& y) { return numext::pow(x,y); } template inline T ei_random () { return internal::random(); } template inline T ei_random (const T& x, const T& y) { return internal::random(x, y); } diff --git a/Eigen/src/Eigen2Support/SVD.h b/Eigen/src/Eigen2Support/SVD.h index a08b695a4..077d26d54 100644 --- a/Eigen/src/Eigen2Support/SVD.h +++ b/Eigen/src/Eigen2Support/SVD.h @@ -315,7 +315,7 @@ void SVD::compute(const MatrixType& matrix) e[p-2] = 0.0; for (j = p-2; j >= k; --j) { - Scalar t(internal::hypot(m_sigma[j],f)); + Scalar t(numext::hypot(m_sigma[j],f)); Scalar cs(m_sigma[j]/t); Scalar sn(f/t); m_sigma[j] = t; @@ -344,7 +344,7 @@ void SVD::compute(const MatrixType& matrix) e[k-1] = 0.0; for (j = k; j < p; ++j) { - Scalar t(internal::hypot(m_sigma[j],f)); + Scalar t(numext::hypot(m_sigma[j],f)); Scalar cs( m_sigma[j]/t); Scalar sn(f/t); m_sigma[j] = t; @@ -392,7 +392,7 @@ void SVD::compute(const MatrixType& matrix) for (j = k; j < p-1; ++j) { - Scalar t = internal::hypot(f,g); + Scalar t = numext::hypot(f,g); Scalar cs = f/t; Scalar sn = g/t; if (j != k) @@ -410,7 +410,7 @@ void SVD::compute(const MatrixType& matrix) m_matV(i,j) = t; } } - t = internal::hypot(f,g); + t = numext::hypot(f,g); cs = f/t; sn = g/t; m_sigma[j] = t; diff --git a/Eigen/src/Eigenvalues/ComplexEigenSolver.h b/Eigen/src/Eigenvalues/ComplexEigenSolver.h index bd41bf7ed..af434bc9b 100644 --- a/Eigen/src/Eigenvalues/ComplexEigenSolver.h +++ b/Eigen/src/Eigenvalues/ComplexEigenSolver.h @@ -294,7 +294,7 @@ void ComplexEigenSolver::doComputeEigenvectors(const RealScalar& mat { // If the i-th and k-th eigenvalue are equal, then z equals 0. // Use a small value instead, to prevent division by zero. - internal::real_ref(z) = NumTraits::epsilon() * matrixnorm; + numext::real_ref(z) = NumTraits::epsilon() * matrixnorm; } m_matX.coeffRef(i,k) = m_matX.coeff(i,k) / z; } diff --git a/Eigen/src/Eigenvalues/ComplexSchur.h b/Eigen/src/Eigenvalues/ComplexSchur.h index 62b57ff66..89e6cade3 100644 --- a/Eigen/src/Eigenvalues/ComplexSchur.h +++ b/Eigen/src/Eigenvalues/ComplexSchur.h @@ -263,8 +263,8 @@ template class ComplexSchur template inline bool ComplexSchur::subdiagonalEntryIsNeglegible(Index i) { - RealScalar d = internal::norm1(m_matT.coeff(i,i)) + internal::norm1(m_matT.coeff(i+1,i+1)); - RealScalar sd = internal::norm1(m_matT.coeff(i+1,i)); + RealScalar d = numext::norm1(m_matT.coeff(i,i)) + numext::norm1(m_matT.coeff(i+1,i+1)); + RealScalar sd = numext::norm1(m_matT.coeff(i+1,i)); if (internal::isMuchSmallerThan(sd, d, NumTraits::epsilon())) { m_matT.coeffRef(i+1,i) = ComplexScalar(0); @@ -282,7 +282,7 @@ typename ComplexSchur::ComplexScalar ComplexSchur::compu if (iter == 10 || iter == 20) { // exceptional shift, taken from http://www.netlib.org/eispack/comqr.f - return abs(internal::real(m_matT.coeff(iu,iu-1))) + abs(internal::real(m_matT.coeff(iu-1,iu-2))); + return abs(numext::real(m_matT.coeff(iu,iu-1))) + abs(numext::real(m_matT.coeff(iu-1,iu-2))); } // compute the shift as one of the eigenvalues of t, the 2x2 @@ -299,13 +299,13 @@ typename ComplexSchur::ComplexScalar ComplexSchur::compu ComplexScalar eival1 = (trace + disc) / RealScalar(2); ComplexScalar eival2 = (trace - disc) / RealScalar(2); - if(internal::norm1(eival1) > internal::norm1(eival2)) + if(numext::norm1(eival1) > numext::norm1(eival2)) eival2 = det / eival1; else eival1 = det / eival2; // choose the eigenvalue closest to the bottom entry of the diagonal - if(internal::norm1(eival1-t.coeff(1,1)) < internal::norm1(eival2-t.coeff(1,1))) + if(numext::norm1(eival1-t.coeff(1,1)) < numext::norm1(eival2-t.coeff(1,1))) return normt * eival1; else return normt * eival2; diff --git a/Eigen/src/Eigenvalues/EigenSolver.h b/Eigen/src/Eigenvalues/EigenSolver.h index f0d4e5afa..6e7150685 100644 --- a/Eigen/src/Eigenvalues/EigenSolver.h +++ b/Eigen/src/Eigenvalues/EigenSolver.h @@ -317,12 +317,12 @@ MatrixType EigenSolver::pseudoEigenvalueMatrix() const MatrixType matD = MatrixType::Zero(n,n); for (Index i=0; i(i,i) << internal::real(m_eivalues.coeff(i)), internal::imag(m_eivalues.coeff(i)), - -internal::imag(m_eivalues.coeff(i)), internal::real(m_eivalues.coeff(i)); + matD.template block<2,2>(i,i) << numext::real(m_eivalues.coeff(i)), numext::imag(m_eivalues.coeff(i)), + -numext::imag(m_eivalues.coeff(i)), numext::real(m_eivalues.coeff(i)); ++i; } } @@ -338,7 +338,7 @@ typename EigenSolver::EigenvectorsType EigenSolver::eige EigenvectorsType matV(n,n); for (Index j=0; j(); @@ -515,8 +515,8 @@ void EigenSolver::doComputeEigenvectors() else { std::complex cc = cdiv(0.0,-m_matT.coeff(n-1,n),m_matT.coeff(n-1,n-1)-p,q); - m_matT.coeffRef(n-1,n-1) = internal::real(cc); - m_matT.coeffRef(n-1,n) = internal::imag(cc); + m_matT.coeffRef(n-1,n-1) = numext::real(cc); + m_matT.coeffRef(n-1,n) = numext::imag(cc); } m_matT.coeffRef(n,n-1) = 0.0; m_matT.coeffRef(n,n) = 1.0; @@ -538,8 +538,8 @@ void EigenSolver::doComputeEigenvectors() if (m_eivalues.coeff(i).imag() == RealScalar(0)) { std::complex cc = cdiv(-ra,-sa,w,q); - m_matT.coeffRef(i,n-1) = internal::real(cc); - m_matT.coeffRef(i,n) = internal::imag(cc); + m_matT.coeffRef(i,n-1) = numext::real(cc); + m_matT.coeffRef(i,n) = numext::imag(cc); } else { @@ -552,8 +552,8 @@ void EigenSolver::doComputeEigenvectors() vr = eps * norm * (abs(w) + abs(q) + abs(x) + abs(y) + abs(lastw)); std::complex cc = cdiv(x*lastra-lastw*ra+q*sa,x*lastsa-lastw*sa-q*ra,vr,vi); - m_matT.coeffRef(i,n-1) = internal::real(cc); - m_matT.coeffRef(i,n) = internal::imag(cc); + m_matT.coeffRef(i,n-1) = numext::real(cc); + m_matT.coeffRef(i,n) = numext::imag(cc); if (abs(x) > (abs(lastw) + abs(q))) { m_matT.coeffRef(i+1,n-1) = (-ra - w * m_matT.coeff(i,n-1) + q * m_matT.coeff(i,n)) / x; @@ -562,8 +562,8 @@ void EigenSolver::doComputeEigenvectors() else { cc = cdiv(-lastra-y*m_matT.coeff(i,n-1),-lastsa-y*m_matT.coeff(i,n),lastw,q); - m_matT.coeffRef(i+1,n-1) = internal::real(cc); - m_matT.coeffRef(i+1,n) = internal::imag(cc); + m_matT.coeffRef(i+1,n-1) = numext::real(cc); + m_matT.coeffRef(i+1,n) = numext::imag(cc); } } diff --git a/Eigen/src/Eigenvalues/HessenbergDecomposition.h b/Eigen/src/Eigenvalues/HessenbergDecomposition.h index ebd8ae908..afa636ffa 100644 --- a/Eigen/src/Eigenvalues/HessenbergDecomposition.h +++ b/Eigen/src/Eigenvalues/HessenbergDecomposition.h @@ -313,7 +313,7 @@ void HessenbergDecomposition::_compute(MatrixType& matA, CoeffVector // A = A H' matA.rightCols(remainingSize) - .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize-1).conjugate(), internal::conj(h), &temp.coeffRef(0)); + .applyHouseholderOnTheRight(matA.col(i).tail(remainingSize-1).conjugate(), numext::conj(h), &temp.coeffRef(0)); } } diff --git a/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h b/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h index 03c024927..3993046a8 100644 --- a/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h +++ b/Eigen/src/Eigenvalues/SelfAdjointEigenSolver.h @@ -395,7 +395,7 @@ SelfAdjointEigenSolver& SelfAdjointEigenSolver if(n==1) { - m_eivalues.coeffRef(0,0) = internal::real(matrix.coeff(0,0)); + m_eivalues.coeffRef(0,0) = numext::real(matrix.coeff(0,0)); if(computeEigenvectors) m_eivec.setOnes(n,n); m_info = Success; @@ -669,7 +669,7 @@ template struct direct_selfadjoint_eigenvalues struct direct_selfadjoint_eigenvaluesc2) { eivecs.col(1) << -scaledMat(1,0), scaledMat(0,0); @@ -744,7 +744,7 @@ static void tridiagonal_qr_step(RealScalar* diag, RealScalar* subdiag, Index sta RealScalar e = subdiag[end-1]; // Note that thanks to scaling, e^2 or td^2 cannot overflow, however they can still // underflow thus leading to inf/NaN values when using the following commented code: -// RealScalar e2 = abs2(subdiag[end-1]); +// RealScalar e2 = numext::abs2(subdiag[end-1]); // RealScalar mu = diag[end] - e2 / (td + (td>0 ? 1 : -1) * sqrt(td*td + e2)); // This explain the following, somewhat more complicated, version: RealScalar mu = diag[end]; @@ -752,8 +752,8 @@ static void tridiagonal_qr_step(RealScalar* diag, RealScalar* subdiag, Index sta mu -= abs(e); else { - RealScalar e2 = abs2(subdiag[end-1]); - RealScalar h = hypot(td,e); + RealScalar e2 = numext::abs2(subdiag[end-1]); + RealScalar h = numext::hypot(td,e); if(e2==0) mu -= (e / (td + (td>0 ? 1 : -1))) * (e / h); else mu -= e2 / (td + (td>0 ? h : -h)); } diff --git a/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_MKL.h b/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_MKL.h index 5de5f15d6..17c0dadd2 100644 --- a/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_MKL.h +++ b/Eigen/src/Eigenvalues/SelfAdjointEigenSolver_MKL.h @@ -56,7 +56,7 @@ SelfAdjointEigenSolver >::compute(c \ if(n==1) \ { \ - m_eivalues.coeffRef(0,0) = internal::real(matrix.coeff(0,0)); \ + m_eivalues.coeffRef(0,0) = numext::real(matrix.coeff(0,0)); \ if(computeEigenvectors) m_eivec.setOnes(n,n); \ m_info = Success; \ m_isInitialized = true; \ diff --git a/Eigen/src/Eigenvalues/Tridiagonalization.h b/Eigen/src/Eigenvalues/Tridiagonalization.h index e8408761d..b55a01d3a 100644 --- a/Eigen/src/Eigenvalues/Tridiagonalization.h +++ b/Eigen/src/Eigenvalues/Tridiagonalization.h @@ -345,7 +345,7 @@ namespace internal { template void tridiagonalization_inplace(MatrixType& matA, CoeffVectorType& hCoeffs) { - using internal::conj; + using numext::conj; typedef typename MatrixType::Index Index; typedef typename MatrixType::Scalar Scalar; typedef typename MatrixType::RealScalar RealScalar; @@ -468,7 +468,7 @@ struct tridiagonalization_inplace_selector { using std::sqrt; diag[0] = mat(0,0); - RealScalar v1norm2 = abs2(mat(2,0)); + RealScalar v1norm2 = numext::abs2(mat(2,0)); if(v1norm2 == RealScalar(0)) { diag[1] = mat(1,1); @@ -480,7 +480,7 @@ struct tridiagonalization_inplace_selector } else { - RealScalar beta = sqrt(abs2(mat(1,0)) + v1norm2); + RealScalar beta = sqrt(numext::abs2(mat(1,0)) + v1norm2); RealScalar invBeta = RealScalar(1)/beta; Scalar m01 = mat(1,0) * invBeta; Scalar m02 = mat(2,0) * invBeta; @@ -510,7 +510,7 @@ struct tridiagonalization_inplace_selector template static void run(MatrixType& mat, DiagonalType& diag, SubDiagonalType&, bool extractQ) { - diag(0,0) = real(mat(0,0)); + diag(0,0) = numext::real(mat(0,0)); if(extractQ) mat(0,0) = Scalar(1); } diff --git a/Eigen/src/Geometry/OrthoMethods.h b/Eigen/src/Geometry/OrthoMethods.h index 4c1bf5fcd..556bc8160 100644 --- a/Eigen/src/Geometry/OrthoMethods.h +++ b/Eigen/src/Geometry/OrthoMethods.h @@ -33,9 +33,9 @@ MatrixBase::cross(const MatrixBase& other) const typename internal::nested::type lhs(derived()); typename internal::nested::type rhs(other.derived()); return typename cross_product_return_type::type( - internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)), - internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)), - internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)) + numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)), + numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)), + numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)) ); } @@ -49,9 +49,9 @@ struct cross3_impl { run(const VectorLhs& lhs, const VectorRhs& rhs) { return typename internal::plain_matrix_type::type( - internal::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)), - internal::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)), - internal::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)), + numext::conj(lhs.coeff(1) * rhs.coeff(2) - lhs.coeff(2) * rhs.coeff(1)), + numext::conj(lhs.coeff(2) * rhs.coeff(0) - lhs.coeff(0) * rhs.coeff(2)), + numext::conj(lhs.coeff(0) * rhs.coeff(1) - lhs.coeff(1) * rhs.coeff(0)), 0 ); } @@ -141,8 +141,8 @@ struct unitOrthogonal_selector if (maxi==0) sndi = 1; RealScalar invnm = RealScalar(1)/(Vector2() << src.coeff(sndi),src.coeff(maxi)).finished().norm(); - perp.coeffRef(maxi) = -conj(src.coeff(sndi)) * invnm; - perp.coeffRef(sndi) = conj(src.coeff(maxi)) * invnm; + perp.coeffRef(maxi) = -numext::conj(src.coeff(sndi)) * invnm; + perp.coeffRef(sndi) = numext::conj(src.coeff(maxi)) * invnm; return perp; } @@ -168,8 +168,8 @@ struct unitOrthogonal_selector || (!isMuchSmallerThan(src.y(), src.z()))) { RealScalar invnm = RealScalar(1)/src.template head<2>().norm(); - perp.coeffRef(0) = -conj(src.y())*invnm; - perp.coeffRef(1) = conj(src.x())*invnm; + perp.coeffRef(0) = -numext::conj(src.y())*invnm; + perp.coeffRef(1) = numext::conj(src.x())*invnm; perp.coeffRef(2) = 0; } /* if both x and y are close to zero, then the vector is close @@ -180,8 +180,8 @@ struct unitOrthogonal_selector { RealScalar invnm = RealScalar(1)/src.template tail<2>().norm(); perp.coeffRef(0) = 0; - perp.coeffRef(1) = -conj(src.z())*invnm; - perp.coeffRef(2) = conj(src.y())*invnm; + perp.coeffRef(1) = -numext::conj(src.z())*invnm; + perp.coeffRef(2) = numext::conj(src.y())*invnm; } return perp; @@ -193,7 +193,7 @@ struct unitOrthogonal_selector { typedef typename plain_matrix_type::type VectorType; static inline VectorType run(const Derived& src) - { return VectorType(-conj(src.y()), conj(src.x())).normalized(); } + { return VectorType(-numext::conj(src.y()), numext::conj(src.x())).normalized(); } }; } // end namespace internal diff --git a/Eigen/src/Householder/Householder.h b/Eigen/src/Householder/Householder.h index b7cfa9b2b..32112af9b 100644 --- a/Eigen/src/Householder/Householder.h +++ b/Eigen/src/Householder/Householder.h @@ -68,7 +68,7 @@ void MatrixBase::makeHouseholder( RealScalar& beta) const { using std::sqrt; - using internal::conj; + using numext::conj; EIGEN_STATIC_ASSERT_VECTOR_ONLY(EssentialPart) VectorBlock tail(derived(), 1, size()-1); @@ -76,16 +76,16 @@ void MatrixBase::makeHouseholder( RealScalar tailSqNorm = size()==1 ? RealScalar(0) : tail.squaredNorm(); Scalar c0 = coeff(0); - if(tailSqNorm == RealScalar(0) && internal::imag(c0)==RealScalar(0)) + if(tailSqNorm == RealScalar(0) && numext::imag(c0)==RealScalar(0)) { tau = RealScalar(0); - beta = internal::real(c0); + beta = numext::real(c0); essential.setZero(); } else { - beta = sqrt(internal::abs2(c0) + tailSqNorm); - if (internal::real(c0)>=RealScalar(0)) + beta = sqrt(numext::abs2(c0) + tailSqNorm); + if (numext::real(c0)>=RealScalar(0)) beta = -beta; essential = tail / (c0 - beta); tau = conj((beta - c0) / beta); diff --git a/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h b/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h index 00b5647c6..a74a8155e 100644 --- a/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h +++ b/Eigen/src/IterativeLinearSolvers/ConjugateGradient.h @@ -63,7 +63,7 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x, p = precond.solve(residual); //initial search direction VectorType z(n), tmp(n); - RealScalar absNew = internal::real(residual.dot(p)); // the square of the absolute value of r scaled by invM + RealScalar absNew = numext::real(residual.dot(p)); // the square of the absolute value of r scaled by invM int i = 0; while(i < maxIters) { @@ -80,7 +80,7 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x, z = precond.solve(residual); // approximately solve for "A z = residual" RealScalar absOld = absNew; - absNew = internal::real(residual.dot(z)); // update the absolute value of r + absNew = numext::real(residual.dot(z)); // update the absolute value of r RealScalar beta = absNew / absOld; // calculate the Gram-Schmidt value used to create the new search direction p = z + beta * p; // update search direction i++; diff --git a/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h b/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h index 17d18ef58..50a870aec 100644 --- a/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h +++ b/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h @@ -310,7 +310,7 @@ void IncompleteLUT::factorize(const _MatrixType& amat) jr(k) = jpos; ++sizeu; } - rownorm += internal::abs2(j_it.value()); + rownorm += numext::abs2(j_it.value()); } // 2 - detect possible zero row diff --git a/Eigen/src/Jacobi/Jacobi.h b/Eigen/src/Jacobi/Jacobi.h index d9d75196c..956f72d57 100644 --- a/Eigen/src/Jacobi/Jacobi.h +++ b/Eigen/src/Jacobi/Jacobi.h @@ -50,16 +50,16 @@ template class JacobiRotation /** Concatenates two planar rotation */ JacobiRotation operator*(const JacobiRotation& other) { - using internal::conj; + using numext::conj; return JacobiRotation(m_c * other.m_c - conj(m_s) * other.m_s, conj(m_c * conj(other.m_s) + conj(m_s) * conj(other.m_c))); } /** Returns the transposed transformation */ - JacobiRotation transpose() const { using internal::conj; return JacobiRotation(m_c, -conj(m_s)); } + JacobiRotation transpose() const { using numext::conj; return JacobiRotation(m_c, -conj(m_s)); } /** Returns the adjoint transformation */ - JacobiRotation adjoint() const { using internal::conj; return JacobiRotation(conj(m_c), -m_s); } + JacobiRotation adjoint() const { using numext::conj; return JacobiRotation(conj(m_c), -m_s); } template bool makeJacobi(const MatrixBase&, typename Derived::Index p, typename Derived::Index q); @@ -94,7 +94,7 @@ bool JacobiRotation::makeJacobi(const RealScalar& x, const Scalar& y, co else { RealScalar tau = (x-z)/(RealScalar(2)*abs(y)); - RealScalar w = sqrt(internal::abs2(tau) + RealScalar(1)); + RealScalar w = sqrt(numext::abs2(tau) + RealScalar(1)); RealScalar t; if(tau>RealScalar(0)) { @@ -105,8 +105,8 @@ bool JacobiRotation::makeJacobi(const RealScalar& x, const Scalar& y, co t = RealScalar(1) / (tau - w); } RealScalar sign_t = t > RealScalar(0) ? RealScalar(1) : RealScalar(-1); - RealScalar n = RealScalar(1) / sqrt(internal::abs2(t)+RealScalar(1)); - m_s = - sign_t * (internal::conj(y) / abs(y)) * abs(t) * n; + RealScalar n = RealScalar(1) / sqrt(numext::abs2(t)+RealScalar(1)); + m_s = - sign_t * (numext::conj(y) / abs(y)) * abs(t) * n; m_c = n; return true; } @@ -125,7 +125,7 @@ template template inline bool JacobiRotation::makeJacobi(const MatrixBase& m, typename Derived::Index p, typename Derived::Index q) { - return makeJacobi(internal::real(m.coeff(p,p)), m.coeff(p,q), internal::real(m.coeff(q,q))); + return makeJacobi(numext::real(m.coeff(p,p)), m.coeff(p,q), numext::real(m.coeff(q,q))); } /** Makes \c *this as a Givens rotation \c G such that applying \f$ G^* \f$ to the left of the vector @@ -157,11 +157,11 @@ void JacobiRotation::makeGivens(const Scalar& p, const Scalar& q, Scalar { using std::sqrt; using std::abs; - using internal::conj; + using numext::conj; if(q==Scalar(0)) { - m_c = internal::real(p)<0 ? Scalar(-1) : Scalar(1); + m_c = numext::real(p)<0 ? Scalar(-1) : Scalar(1); m_s = 0; if(r) *r = m_c * p; } @@ -173,17 +173,17 @@ void JacobiRotation::makeGivens(const Scalar& p, const Scalar& q, Scalar } else { - RealScalar p1 = internal::norm1(p); - RealScalar q1 = internal::norm1(q); + RealScalar p1 = numext::norm1(p); + RealScalar q1 = numext::norm1(q); if(p1>=q1) { Scalar ps = p / p1; - RealScalar p2 = internal::abs2(ps); + RealScalar p2 = numext::abs2(ps); Scalar qs = q / p1; - RealScalar q2 = internal::abs2(qs); + RealScalar q2 = numext::abs2(qs); RealScalar u = sqrt(RealScalar(1) + q2/p2); - if(internal::real(p)::makeGivens(const Scalar& p, const Scalar& q, Scalar else { Scalar ps = p / q1; - RealScalar p2 = internal::abs2(ps); + RealScalar p2 = numext::abs2(ps); Scalar qs = q / q1; - RealScalar q2 = internal::abs2(qs); + RealScalar q2 = numext::abs2(qs); RealScalar u = q1 * sqrt(p2 + q2); - if(internal::real(p)::makeGivens(const Scalar& p, const Scalar& q, Scalar else if(abs(p) > abs(q)) { Scalar t = q/p; - Scalar u = sqrt(Scalar(1) + internal::abs2(t)); + Scalar u = sqrt(Scalar(1) + numext::abs2(t)); if(p::makeGivens(const Scalar& p, const Scalar& q, Scalar else { Scalar t = p/q; - Scalar u = sqrt(Scalar(1) + internal::abs2(t)); + Scalar u = sqrt(Scalar(1) + numext::abs2(t)); if(q& ColPivHouseholderQR::compute(const for(Index k = 0; k < cols; ++k) m_colSqNorms.coeffRef(k) = m_qr.col(k).squaredNorm(); - RealScalar threshold_helper = m_colSqNorms.maxCoeff() * internal::abs2(NumTraits::epsilon()) / RealScalar(rows); + RealScalar threshold_helper = m_colSqNorms.maxCoeff() * numext::abs2(NumTraits::epsilon()) / RealScalar(rows); m_nonzero_pivots = size; // the generic case is that in which all pivots are nonzero (invertible case) m_maxpivot = RealScalar(0); diff --git a/Eigen/src/QR/FullPivHouseholderQR.h b/Eigen/src/QR/FullPivHouseholderQR.h index f82126494..0dd5ad347 100644 --- a/Eigen/src/QR/FullPivHouseholderQR.h +++ b/Eigen/src/QR/FullPivHouseholderQR.h @@ -572,7 +572,7 @@ public: template void evalTo(ResultType& result, WorkVectorType& workspace) const { - using internal::conj; + using numext::conj; // compute the product H'_0 H'_1 ... H'_n-1, // where H_k is the k-th Householder transformation I - h_k v_k v_k' // and v_k is the k-th Householder vector [1,m_qr(k+1,k), m_qr(k+2,k), ...] diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index 495d3fabf..c7a7eeda0 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -374,7 +374,7 @@ struct svd_precondition_2x2_block_to_be_real using std::sqrt; Scalar z; JacobiRotation rot; - RealScalar n = sqrt(abs2(work_matrix.coeff(p,p)) + abs2(work_matrix.coeff(q,p))); + RealScalar n = sqrt(numext::abs2(work_matrix.coeff(p,p)) + numext::abs2(work_matrix.coeff(q,p))); if(n==0) { z = abs(work_matrix.coeff(p,q)) / work_matrix.coeff(p,q); @@ -413,8 +413,8 @@ void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q, { using std::sqrt; Matrix m; - m << real(matrix.coeff(p,p)), real(matrix.coeff(p,q)), - real(matrix.coeff(q,p)), real(matrix.coeff(q,q)); + m << numext::real(matrix.coeff(p,p)), numext::real(matrix.coeff(p,q)), + numext::real(matrix.coeff(q,p)), numext::real(matrix.coeff(q,q)); JacobiRotation rot1; RealScalar t = m.coeff(0,0) + m.coeff(1,1); RealScalar d = m.coeff(1,0) - m.coeff(0,1); @@ -426,7 +426,7 @@ void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q, else { RealScalar u = d / t; - rot1.c() = RealScalar(1) / sqrt(RealScalar(1) + abs2(u)); + rot1.c() = RealScalar(1) / sqrt(RealScalar(1) + numext::abs2(u)); rot1.s() = rot1.c() * u; } m.applyOnTheLeft(0,1,rot1); diff --git a/Eigen/src/SparseCholesky/SimplicialCholesky.h b/Eigen/src/SparseCholesky/SimplicialCholesky.h index 62747279d..f41d7e010 100644 --- a/Eigen/src/SparseCholesky/SimplicialCholesky.h +++ b/Eigen/src/SparseCholesky/SimplicialCholesky.h @@ -364,7 +364,7 @@ public: Scalar determinant() const { Scalar detL = Base::m_matrix.diagonal().prod(); - return internal::abs2(detL); + return numext::abs2(detL); } }; @@ -599,7 +599,7 @@ public: else { Scalar detL = Diagonal(Base::m_matrix).prod(); - return internal::abs2(detL); + return numext::abs2(detL); } } diff --git a/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h b/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h index 4b249868f..7aaf702be 100644 --- a/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h +++ b/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h @@ -131,7 +131,7 @@ void SimplicialCholeskyBase::factorize_preordered(const CholMatrixType& Index i = it.index(); if(i <= k) { - y[i] += internal::conj(it.value()); /* scatter A(i,k) into Y (sum duplicates) */ + y[i] += numext::conj(it.value()); /* scatter A(i,k) into Y (sum duplicates) */ Index len; for(len = 0; tags[i] != k; i = m_parent[i]) { @@ -145,7 +145,7 @@ void SimplicialCholeskyBase::factorize_preordered(const CholMatrixType& /* compute numerical values kth row of L (a sparse triangular solve) */ - RealScalar d = internal::real(y[k]) * m_shiftScale + m_shiftOffset; // get D(k,k), apply the shift function, and clear Y(k) + RealScalar d = numext::real(y[k]) * m_shiftScale + m_shiftOffset; // get D(k,k), apply the shift function, and clear Y(k) y[k] = 0.0; for(; top < size; ++top) { @@ -163,8 +163,8 @@ void SimplicialCholeskyBase::factorize_preordered(const CholMatrixType& Index p2 = Lp[i] + m_nonZerosPerCol[i]; Index p; for(p = Lp[i] + (DoLDLT ? 0 : 1); p < p2; ++p) - y[Li[p]] -= internal::conj(Lx[p]) * yi; - d -= internal::real(l_ki * internal::conj(yi)); + y[Li[p]] -= numext::conj(Lx[p]) * yi; + d -= numext::real(l_ki * numext::conj(yi)); Li[p] = k; /* store L(k,i) in column form of L */ Lx[p] = l_ki; ++m_nonZerosPerCol[i]; /* increment count of nonzeros in col i */ diff --git a/Eigen/src/SparseCore/SparseDot.h b/Eigen/src/SparseCore/SparseDot.h index dfeb3a8df..db39c9aec 100644 --- a/Eigen/src/SparseCore/SparseDot.h +++ b/Eigen/src/SparseCore/SparseDot.h @@ -30,7 +30,7 @@ SparseMatrixBase::dot(const MatrixBase& other) const Scalar res(0); while (i) { - res += internal::conj(i.value()) * other.coeff(i.index()); + res += numext::conj(i.value()) * other.coeff(i.index()); ++i; } return res; @@ -64,7 +64,7 @@ SparseMatrixBase::dot(const SparseMatrixBase& other) cons { if (i.index()==j.index()) { - res += internal::conj(i.value()) * j.value(); + res += numext::conj(i.value()) * j.value(); ++i; ++j; } else if (i.index() inline typename NumTraits::Scalar>::Real SparseMatrixBase::squaredNorm() const { - return internal::real((*this).cwiseAbs2().sum()); + return numext::real((*this).cwiseAbs2().sum()); } template diff --git a/Eigen/src/SparseCore/SparseSelfAdjointView.h b/Eigen/src/SparseCore/SparseSelfAdjointView.h index 9630b60f5..d2e170410 100644 --- a/Eigen/src/SparseCore/SparseSelfAdjointView.h +++ b/Eigen/src/SparseCore/SparseSelfAdjointView.h @@ -240,7 +240,7 @@ class SparseSelfAdjointTimeDenseProduct Index b = LhsIsRowMajor ? i.index() : j; typename Lhs::Scalar v = i.value(); dest.row(a) += (v) * m_rhs.row(b); - dest.row(b) += internal::conj(v) * m_rhs.row(a); + dest.row(b) += numext::conj(v) * m_rhs.row(a); } if (ProcessFirstHalf && i && (i.index()==j)) dest.row(j) += i.value() * m_rhs.row(j); @@ -367,7 +367,7 @@ void permute_symm_to_fullsymm(const MatrixType& mat, SparseMatrixjp))) - dest.valuePtr()[k] = conj(it.value()); + dest.valuePtr()[k] = numext::conj(it.value()); else dest.valuePtr()[k] = it.value(); } @@ -461,7 +461,10 @@ class SparseSymmetricPermutationProduct template void evalTo(SparseMatrix& _dest) const { - internal::permute_symm_to_fullsymm(m_matrix,_dest,m_perm.indices().data()); +// internal::permute_symm_to_fullsymm(m_matrix,_dest,m_perm.indices().data()); + SparseMatrix tmp; + internal::permute_symm_to_fullsymm(m_matrix,tmp,m_perm.indices().data()); + _dest = tmp; } template void evalTo(SparseSelfAdjointView& dest) const diff --git a/Eigen/src/SparseCore/SparseView.h b/Eigen/src/SparseCore/SparseView.h index 4fd0cb3d8..67eb93245 100644 --- a/Eigen/src/SparseCore/SparseView.h +++ b/Eigen/src/SparseCore/SparseView.h @@ -18,7 +18,7 @@ namespace internal { template struct traits > : traits { - typedef int Index; + typedef typename MatrixType::Index Index; typedef Sparse StorageKind; enum { Flags = int(traits::Flags) & (RowMajorBit) diff --git a/Eigen/src/SparseQR/SparseQR.h b/Eigen/src/SparseQR/SparseQR.h index 1bf631507..07c46e4b9 100644 --- a/Eigen/src/SparseQR/SparseQR.h +++ b/Eigen/src/SparseQR/SparseQR.h @@ -435,23 +435,23 @@ void SparseQR::factorize(const MatrixType& mat) // First, the squared norm of Q((col+1):m, col) RealScalar sqrNorm = 0.; - for (Index itq = 1; itq < nzcolQ; ++itq) sqrNorm += internal::abs2(tval(Qidx(itq))); + for (Index itq = 1; itq < nzcolQ; ++itq) sqrNorm += numext::abs2(tval(Qidx(itq))); - if(sqrNorm == RealScalar(0) && internal::imag(c0) == RealScalar(0)) + if(sqrNorm == RealScalar(0) && numext::imag(c0) == RealScalar(0)) { tau = RealScalar(0); - beta = internal::real(c0); + beta = numext::real(c0); tval(Qidx(0)) = 1; } else { - beta = std::sqrt(internal::abs2(c0) + sqrNorm); - if(internal::real(c0) >= RealScalar(0)) + beta = std::sqrt(numext::abs2(c0) + sqrNorm); + if(numext::real(c0) >= RealScalar(0)) beta = -beta; tval(Qidx(0)) = 1; for (Index itq = 1; itq < nzcolQ; ++itq) tval(Qidx(itq)) /= (c0 - beta); - tau = internal::conj((beta-c0) / beta); + tau = numext::conj((beta-c0) / beta); } diff --git a/Eigen/src/UmfPackSupport/UmfPackSupport.h b/Eigen/src/UmfPackSupport/UmfPackSupport.h index d85b8be85..3a48cecf7 100644 --- a/Eigen/src/UmfPackSupport/UmfPackSupport.h +++ b/Eigen/src/UmfPackSupport/UmfPackSupport.h @@ -39,7 +39,7 @@ inline int umfpack_symbolic(int n_row,int n_col, const int Ap[], const int Ai[], const std::complex Ax[], void **Symbolic, const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO]) { - return umfpack_zi_symbolic(n_row,n_col,Ap,Ai,&internal::real_ref(Ax[0]),0,Symbolic,Control,Info); + return umfpack_zi_symbolic(n_row,n_col,Ap,Ai,&numext::real_ref(Ax[0]),0,Symbolic,Control,Info); } inline int umfpack_numeric( const int Ap[], const int Ai[], const double Ax[], @@ -53,7 +53,7 @@ inline int umfpack_numeric( const int Ap[], const int Ai[], const std::complex X[], const std::complex B[], void *Numeric, const double Control[UMFPACK_CONTROL], double Info[UMFPACK_INFO]) { - return umfpack_zi_solve(sys,Ap,Ai,&internal::real_ref(Ax[0]),0,&internal::real_ref(X[0]),0,&internal::real_ref(B[0]),0,Numeric,Control,Info); + return umfpack_zi_solve(sys,Ap,Ai,&numext::real_ref(Ax[0]),0,&numext::real_ref(X[0]),0,&numext::real_ref(B[0]),0,Numeric,Control,Info); } inline int umfpack_get_lunz(int *lnz, int *unz, int *n_row, int *n_col, int *nz_udiag, void *Numeric, double) @@ -89,9 +89,9 @@ inline int umfpack_get_numeric(int Lp[], int Lj[], double Lx[], int Up[], int Ui inline int umfpack_get_numeric(int Lp[], int Lj[], std::complex Lx[], int Up[], int Ui[], std::complex Ux[], int P[], int Q[], std::complex Dx[], int *do_recip, double Rs[], void *Numeric) { - double& lx0_real = internal::real_ref(Lx[0]); - double& ux0_real = internal::real_ref(Ux[0]); - double& dx0_real = internal::real_ref(Dx[0]); + double& lx0_real = numext::real_ref(Lx[0]); + double& ux0_real = numext::real_ref(Ux[0]); + double& dx0_real = numext::real_ref(Dx[0]); return umfpack_zi_get_numeric(Lp,Lj,Lx?&lx0_real:0,0,Up,Ui,Ux?&ux0_real:0,0,P,Q, Dx?&dx0_real:0,0,do_recip,Rs,Numeric); } @@ -103,7 +103,7 @@ inline int umfpack_get_determinant(double *Mx, double *Ex, void *NumericHandle, inline int umfpack_get_determinant(std::complex *Mx, double *Ex, void *NumericHandle, double User_Info [UMFPACK_INFO]) { - double& mx_real = internal::real_ref(*Mx); + double& mx_real = numext::real_ref(*Mx); return umfpack_zi_get_determinant(&mx_real,0,Ex,NumericHandle,User_Info); } diff --git a/test/adjoint.cpp b/test/adjoint.cpp index 72ad9e407..b63e843c6 100644 --- a/test/adjoint.cpp +++ b/test/adjoint.cpp @@ -16,7 +16,7 @@ template struct adjoint_specific; template<> struct adjoint_specific { template static void run(const Vec& v1, const Vec& v2, Vec& v3, const Mat& square, Scalar s1, Scalar s2) { - VERIFY(test_isApproxWithRef((s1 * v1 + s2 * v2).dot(v3), internal::conj(s1) * v1.dot(v3) + internal::conj(s2) * v2.dot(v3), 0)); + VERIFY(test_isApproxWithRef((s1 * v1 + s2 * v2).dot(v3), numext::conj(s1) * v1.dot(v3) + numext::conj(s2) * v2.dot(v3), 0)); VERIFY(test_isApproxWithRef(v3.dot(s1 * v1 + s2 * v2), s1*v3.dot(v1)+s2*v3.dot(v2), 0)); // check compatibility of dot and adjoint @@ -30,7 +30,7 @@ template<> struct adjoint_specific { typedef typename NumTraits::Real RealScalar; RealScalar ref = NumTraits::IsInteger ? RealScalar(0) : (std::max)((s1 * v1 + s2 * v2).norm(),v3.norm()); - VERIFY(test_isApproxWithRef((s1 * v1 + s2 * v2).dot(v3), internal::conj(s1) * v1.dot(v3) + internal::conj(s2) * v2.dot(v3), ref)); + VERIFY(test_isApproxWithRef((s1 * v1 + s2 * v2).dot(v3), numext::conj(s1) * v1.dot(v3) + numext::conj(s2) * v2.dot(v3), ref)); VERIFY(test_isApproxWithRef(v3.dot(s1 * v1 + s2 * v2), s1*v3.dot(v1)+s2*v3.dot(v2), ref)); VERIFY_IS_APPROX(v1.squaredNorm(), v1.norm() * v1.norm()); @@ -85,11 +85,11 @@ template void adjoint(const MatrixType& m) // check multiplicative behavior VERIFY_IS_APPROX((m1.adjoint() * m2).adjoint(), m2.adjoint() * m1); - VERIFY_IS_APPROX((s1 * m1).adjoint(), internal::conj(s1) * m1.adjoint()); + VERIFY_IS_APPROX((s1 * m1).adjoint(), numext::conj(s1) * m1.adjoint()); // check basic properties of dot, squaredNorm - VERIFY_IS_APPROX(internal::conj(v1.dot(v2)), v2.dot(v1)); - VERIFY_IS_APPROX(internal::real(v1.dot(v1)), v1.squaredNorm()); + VERIFY_IS_APPROX(numext::conj(v1.dot(v2)), v2.dot(v1)); + VERIFY_IS_APPROX(numext::real(v1.dot(v1)), v1.squaredNorm()); adjoint_specific::IsInteger>::run(v1, v2, v3, square, s1, s2); @@ -98,8 +98,8 @@ template void adjoint(const MatrixType& m) // like in testBasicStuff, test operator() to check const-qualification Index r = internal::random(0, rows-1), c = internal::random(0, cols-1); - VERIFY_IS_APPROX(m1.conjugate()(r,c), internal::conj(m1(r,c))); - VERIFY_IS_APPROX(m1.adjoint()(c,r), internal::conj(m1(r,c))); + VERIFY_IS_APPROX(m1.conjugate()(r,c), numext::conj(m1(r,c))); + VERIFY_IS_APPROX(m1.adjoint()(c,r), numext::conj(m1(r,c))); // check inplace transpose m3 = m1; diff --git a/test/array.cpp b/test/array.cpp index ceb00fa05..e39bd6352 100644 --- a/test/array.cpp +++ b/test/array.cpp @@ -182,12 +182,12 @@ template void array_real(const ArrayType& m) // VERIFY_IS_APPROX(m1.abs().sqrt(), std::sqrt(std::abs(m1))); VERIFY_IS_APPROX(m1.abs().sqrt(), sqrt(abs(m1))); - VERIFY_IS_APPROX(m1.abs(), sqrt(internal::abs2(m1))); + VERIFY_IS_APPROX(m1.abs(), sqrt(numext::abs2(m1))); - VERIFY_IS_APPROX(internal::abs2(internal::real(m1)) + internal::abs2(internal::imag(m1)), internal::abs2(m1)); - VERIFY_IS_APPROX(internal::abs2(real(m1)) + internal::abs2(imag(m1)), internal::abs2(m1)); + VERIFY_IS_APPROX(numext::abs2(numext::real(m1)) + numext::abs2(numext::imag(m1)), numext::abs2(m1)); + VERIFY_IS_APPROX(numext::abs2(real(m1)) + numext::abs2(imag(m1)), numext::abs2(m1)); if(!NumTraits::IsComplex) - VERIFY_IS_APPROX(internal::real(m1), m1); + VERIFY_IS_APPROX(numext::real(m1), m1); VERIFY((m1.abs().log() == log(abs(m1))).all()); diff --git a/test/array_for_matrix.cpp b/test/array_for_matrix.cpp index 99cda1ffe..1250c9ff5 100644 --- a/test/array_for_matrix.cpp +++ b/test/array_for_matrix.cpp @@ -25,10 +25,10 @@ template void array_for_matrix(const MatrixType& m) ColVectorType cv1 = ColVectorType::Random(rows); RowVectorType rv1 = RowVectorType::Random(cols); - + Scalar s1 = internal::random(), s2 = internal::random(); - + // scalar addition VERIFY_IS_APPROX(m1.array() + s1, s1 + m1.array()); VERIFY_IS_APPROX((m1.array() + s1).matrix(), MatrixType::Constant(rows,cols,s1) + m1); @@ -138,7 +138,7 @@ template void lpNorm(const VectorType& v) VERIFY_IS_APPROX(u.template lpNorm(), u.cwiseAbs().maxCoeff()); VERIFY_IS_APPROX(u.template lpNorm<1>(), u.cwiseAbs().sum()); VERIFY_IS_APPROX(u.template lpNorm<2>(), sqrt(u.array().abs().square().sum())); - VERIFY_IS_APPROX(internal::pow(u.template lpNorm<5>(), typename VectorType::RealScalar(5)), u.array().abs().pow(5).sum()); + VERIFY_IS_APPROX(numext::pow(u.template lpNorm<5>(), typename VectorType::RealScalar(5)), u.array().abs().pow(5).sum()); } template void cwise_min_max(const MatrixType& m) diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index 0fbae19e8..8c0621ecd 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -141,10 +141,10 @@ template void basicStuffComplex(const MatrixType& m) Scalar s1 = internal::random(), s2 = internal::random(); - VERIFY(internal::real(s1)==internal::real_ref(s1)); - VERIFY(internal::imag(s1)==internal::imag_ref(s1)); - internal::real_ref(s1) = internal::real(s2); - internal::imag_ref(s1) = internal::imag(s2); + VERIFY(numext::real(s1)==numext::real_ref(s1)); + VERIFY(numext::imag(s1)==numext::imag_ref(s1)); + numext::real_ref(s1) = numext::real(s2); + numext::imag_ref(s1) = numext::imag(s2); VERIFY(internal::isApprox(s1, s2, NumTraits::epsilon())); // extended precision in Intel FPUs means that s1 == s2 in the line above is not guaranteed. diff --git a/test/block.cpp b/test/block.cpp index 0969262ca..a3246f411 100644 --- a/test/block.cpp +++ b/test/block.cpp @@ -96,11 +96,11 @@ template void block(const MatrixType& m) } // stress some basic stuffs with block matrices - VERIFY(internal::real(ones.col(c1).sum()) == RealScalar(rows)); - VERIFY(internal::real(ones.row(r1).sum()) == RealScalar(cols)); + VERIFY(numext::real(ones.col(c1).sum()) == RealScalar(rows)); + VERIFY(numext::real(ones.row(r1).sum()) == RealScalar(cols)); - VERIFY(internal::real(ones.col(c1).dot(ones.col(c2))) == RealScalar(rows)); - VERIFY(internal::real(ones.row(r1).dot(ones.row(r2))) == RealScalar(cols)); + VERIFY(numext::real(ones.col(c1).dot(ones.col(c2))) == RealScalar(rows)); + VERIFY(numext::real(ones.row(r1).dot(ones.row(r2))) == RealScalar(cols)); // now test some block-inside-of-block. diff --git a/test/determinant.cpp b/test/determinant.cpp index e93f2f297..edf83fda9 100644 --- a/test/determinant.cpp +++ b/test/determinant.cpp @@ -39,7 +39,7 @@ template void determinant(const MatrixType& m) m2.col(i).swap(m2.col(j)); VERIFY_IS_APPROX(m2.determinant(), -m1.determinant()); VERIFY_IS_APPROX(m2.determinant(), m2.transpose().determinant()); - VERIFY_IS_APPROX(internal::conj(m2.determinant()), m2.adjoint().determinant()); + VERIFY_IS_APPROX(numext::conj(m2.determinant()), m2.adjoint().determinant()); m2 = m1; m2.row(i) += x*m2.row(j); VERIFY_IS_APPROX(m2.determinant(), m1.determinant()); diff --git a/test/eigen2support.cpp b/test/eigen2support.cpp index bfcc87323..ad1d98091 100644 --- a/test/eigen2support.cpp +++ b/test/eigen2support.cpp @@ -44,8 +44,8 @@ template void eigen2support(const MatrixType& m) VERIFY_IS_EQUAL((m1.col(0).template end<1>()), (m1.col(0).segment(rows-1,1))); using std::cos; - using internal::real; - using internal::abs2; + using numext::real; + using numext::abs2; VERIFY_IS_EQUAL(ei_cos(s1), cos(s1)); VERIFY_IS_EQUAL(ei_real(s1), real(s1)); VERIFY_IS_EQUAL(ei_abs2(s1), abs2(s1)); diff --git a/test/householder.cpp b/test/householder.cpp index 1dac4331f..d10cadd6c 100644 --- a/test/householder.cpp +++ b/test/householder.cpp @@ -60,8 +60,8 @@ template void householder(const MatrixType& m) m1.applyHouseholderOnTheLeft(essential,beta,tmp); VERIFY_IS_APPROX(m1.norm(), m2.norm()); if(rows>=2) VERIFY_IS_MUCH_SMALLER_THAN(m1.block(1,0,rows-1,cols).norm(), m1.norm()); - VERIFY_IS_MUCH_SMALLER_THAN(internal::imag(m1(0,0)), internal::real(m1(0,0))); - VERIFY_IS_APPROX(internal::real(m1(0,0)), alpha); + VERIFY_IS_MUCH_SMALLER_THAN(numext::imag(m1(0,0)), numext::real(m1(0,0))); + VERIFY_IS_APPROX(numext::real(m1(0,0)), alpha); v1 = VectorType::Random(rows); if(even) v1.tail(rows-1).setZero(); @@ -72,8 +72,8 @@ template void householder(const MatrixType& m) m3.applyHouseholderOnTheRight(essential,beta,tmp); VERIFY_IS_APPROX(m3.norm(), m4.norm()); if(rows>=2) VERIFY_IS_MUCH_SMALLER_THAN(m3.block(0,1,rows,rows-1).norm(), m3.norm()); - VERIFY_IS_MUCH_SMALLER_THAN(internal::imag(m3(0,0)), internal::real(m3(0,0))); - VERIFY_IS_APPROX(internal::real(m3(0,0)), alpha); + VERIFY_IS_MUCH_SMALLER_THAN(numext::imag(m3(0,0)), numext::real(m3(0,0))); + VERIFY_IS_APPROX(numext::real(m3(0,0)), alpha); // test householder sequence on the left with a shift diff --git a/test/jacobi.cpp b/test/jacobi.cpp index b123b9189..0e6f1de49 100644 --- a/test/jacobi.cpp +++ b/test/jacobi.cpp @@ -40,8 +40,8 @@ void jacobi(const MatrixType& m = MatrixType()) MatrixType b = a; b.applyOnTheLeft(p, q, rot); - VERIFY_IS_APPROX(b.row(p), c * a.row(p) + internal::conj(s) * a.row(q)); - VERIFY_IS_APPROX(b.row(q), -s * a.row(p) + internal::conj(c) * a.row(q)); + VERIFY_IS_APPROX(b.row(p), c * a.row(p) + numext::conj(s) * a.row(q)); + VERIFY_IS_APPROX(b.row(q), -s * a.row(p) + numext::conj(c) * a.row(q)); } { @@ -54,7 +54,7 @@ void jacobi(const MatrixType& m = MatrixType()) MatrixType b = a; b.applyOnTheRight(p, q, rot); VERIFY_IS_APPROX(b.col(p), c * a.col(p) - s * a.col(q)); - VERIFY_IS_APPROX(b.col(q), internal::conj(s) * a.col(p) + internal::conj(c) * a.col(q)); + VERIFY_IS_APPROX(b.col(q), numext::conj(s) * a.col(p) + numext::conj(c) * a.col(q)); } } diff --git a/test/main.h b/test/main.h index 3be0f9fca..fefeac358 100644 --- a/test/main.h +++ b/test/main.h @@ -170,7 +170,7 @@ namespace Eigen #define EIGEN_INTERNAL_DEBUGGING #include // required for createRandomPIMatrixOfRank -static void verify_impl(bool condition, const char *testname, const char *file, int line, const char *condition_as_string) +static inline void verify_impl(bool condition, const char *testname, const char *file, int line, const char *condition_as_string) { if (!condition) { diff --git a/test/packetmath.cpp b/test/packetmath.cpp index 9cdebd376..78a974e25 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -156,7 +156,7 @@ template void packetmath() CHECK_CWISE2(REF_DIV, internal::pdiv); #endif CHECK_CWISE1(internal::negate, internal::pnegate); - CHECK_CWISE1(internal::conj, internal::pconj); + CHECK_CWISE1(numext::conj, internal::pconj); for(int offset=0;offset<3;++offset) { diff --git a/test/product_extra.cpp b/test/product_extra.cpp index 53493bdd6..744a1ef7f 100644 --- a/test/product_extra.cpp +++ b/test/product_extra.cpp @@ -42,7 +42,7 @@ template void product_extra(const MatrixType& m) VERIFY_IS_APPROX(m3.noalias() = m1.adjoint() * square.adjoint(), m1.adjoint().eval() * square.adjoint().eval()); VERIFY_IS_APPROX(m3.noalias() = m1.adjoint() * m2, m1.adjoint().eval() * m2); VERIFY_IS_APPROX(m3.noalias() = (s1 * m1.adjoint()) * m2, (s1 * m1.adjoint()).eval() * m2); - VERIFY_IS_APPROX(m3.noalias() = ((s1 * m1).adjoint()) * m2, (internal::conj(s1) * m1.adjoint()).eval() * m2); + VERIFY_IS_APPROX(m3.noalias() = ((s1 * m1).adjoint()) * m2, (numext::conj(s1) * m1.adjoint()).eval() * m2); VERIFY_IS_APPROX(m3.noalias() = (- m1.adjoint() * s1) * (s3 * m2), (- m1.adjoint() * s1).eval() * (s3 * m2).eval()); VERIFY_IS_APPROX(m3.noalias() = (s2 * m1.adjoint() * s1) * m2, (s2 * m1.adjoint() * s1).eval() * m2); VERIFY_IS_APPROX(m3.noalias() = (-m1*s2) * s1*m2.adjoint(), (-m1*s2).eval() * (s1*m2.adjoint()).eval()); diff --git a/test/product_selfadjoint.cpp b/test/product_selfadjoint.cpp index aede15053..58e2ea90d 100644 --- a/test/product_selfadjoint.cpp +++ b/test/product_selfadjoint.cpp @@ -44,11 +44,11 @@ template void product_selfadjoint(const MatrixType& m) m2 = m1.template triangularView(); m2.template selfadjointView().rankUpdate(-v1,s2*v2,s3); - VERIFY_IS_APPROX(m2, (m1 + (s3*(-v1)*(s2*v2).adjoint()+internal::conj(s3)*(s2*v2)*(-v1).adjoint())).template triangularView().toDenseMatrix()); + VERIFY_IS_APPROX(m2, (m1 + (s3*(-v1)*(s2*v2).adjoint()+numext::conj(s3)*(s2*v2)*(-v1).adjoint())).template triangularView().toDenseMatrix()); m2 = m1.template triangularView(); m2.template selfadjointView().rankUpdate(-s2*r1.adjoint(),r2.adjoint()*s3,s1); - VERIFY_IS_APPROX(m2, (m1 + s1*(-s2*r1.adjoint())*(r2.adjoint()*s3).adjoint() + internal::conj(s1)*(r2.adjoint()*s3) * (-s2*r1.adjoint()).adjoint()).template triangularView().toDenseMatrix()); + VERIFY_IS_APPROX(m2, (m1 + s1*(-s2*r1.adjoint())*(r2.adjoint()*s3).adjoint() + numext::conj(s1)*(r2.adjoint()*s3) * (-s2*r1.adjoint()).adjoint()).template triangularView().toDenseMatrix()); if (rows>1) { diff --git a/test/product_trmm.cpp b/test/product_trmm.cpp index 31ac1b22e..506a1aeb9 100644 --- a/test/product_trmm.cpp +++ b/test/product_trmm.cpp @@ -54,7 +54,7 @@ void trmm(int rows=internal::random(1,EIGEN_TEST_MAX_SIZE), ge_sx_save = ge_sx; VERIFY_IS_APPROX( ge_sx_save - (ge_right.adjoint() * (-s1 * triTr).conjugate()).eval(), ge_sx.noalias() -= (ge_right.adjoint() * (-s1 * mat).adjoint().template triangularView()).eval()); - VERIFY_IS_APPROX( ge_xs = (s1*mat).adjoint().template triangularView() * ge_left.adjoint(), internal::conj(s1) * triTr.conjugate() * ge_left.adjoint()); + VERIFY_IS_APPROX( ge_xs = (s1*mat).adjoint().template triangularView() * ge_left.adjoint(), numext::conj(s1) * triTr.conjugate() * ge_left.adjoint()); // TODO check with sub-matrix expressions ? } diff --git a/test/redux.cpp b/test/redux.cpp index dd6edd1bd..bf68d2212 100644 --- a/test/redux.cpp +++ b/test/redux.cpp @@ -26,22 +26,22 @@ template void matrixRedux(const MatrixType& m) VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows, cols).sum(), Scalar(1)); VERIFY_IS_APPROX(MatrixType::Ones(rows, cols).sum(), Scalar(float(rows*cols))); // the float() here to shut up excessive MSVC warning about int->complex conversion being lossy - Scalar s(0), p(1), minc(internal::real(m1.coeff(0))), maxc(internal::real(m1.coeff(0))); + Scalar s(0), p(1), minc(numext::real(m1.coeff(0))), maxc(numext::real(m1.coeff(0))); for(int j = 0; j < cols; j++) for(int i = 0; i < rows; i++) { s += m1(i,j); p *= m1_for_prod(i,j); - minc = (std::min)(internal::real(minc), internal::real(m1(i,j))); - maxc = (std::max)(internal::real(maxc), internal::real(m1(i,j))); + minc = (std::min)(numext::real(minc), numext::real(m1(i,j))); + maxc = (std::max)(numext::real(maxc), numext::real(m1(i,j))); } const Scalar mean = s/Scalar(RealScalar(rows*cols)); VERIFY_IS_APPROX(m1.sum(), s); VERIFY_IS_APPROX(m1.mean(), mean); VERIFY_IS_APPROX(m1_for_prod.prod(), p); - VERIFY_IS_APPROX(m1.real().minCoeff(), internal::real(minc)); - VERIFY_IS_APPROX(m1.real().maxCoeff(), internal::real(maxc)); + VERIFY_IS_APPROX(m1.real().minCoeff(), numext::real(minc)); + VERIFY_IS_APPROX(m1.real().maxCoeff(), numext::real(maxc)); // test slice vectorization assuming assign is ok Index r0 = internal::random(0,rows-1); @@ -73,13 +73,13 @@ template void vectorRedux(const VectorType& w) for(int i = 1; i < size; i++) { Scalar s(0), p(1); - RealScalar minc(internal::real(v.coeff(0))), maxc(internal::real(v.coeff(0))); + RealScalar minc(numext::real(v.coeff(0))), maxc(numext::real(v.coeff(0))); for(int j = 0; j < i; j++) { s += v[j]; p *= v_for_prod[j]; - minc = (std::min)(minc, internal::real(v[j])); - maxc = (std::max)(maxc, internal::real(v[j])); + minc = (std::min)(minc, numext::real(v[j])); + maxc = (std::max)(maxc, numext::real(v[j])); } VERIFY_IS_MUCH_SMALLER_THAN(abs(s - v.head(i).sum()), Scalar(1)); VERIFY_IS_APPROX(p, v_for_prod.head(i).prod()); @@ -90,13 +90,13 @@ template void vectorRedux(const VectorType& w) for(int i = 0; i < size-1; i++) { Scalar s(0), p(1); - RealScalar minc(internal::real(v.coeff(i))), maxc(internal::real(v.coeff(i))); + RealScalar minc(numext::real(v.coeff(i))), maxc(numext::real(v.coeff(i))); for(int j = i; j < size; j++) { s += v[j]; p *= v_for_prod[j]; - minc = (std::min)(minc, internal::real(v[j])); - maxc = (std::max)(maxc, internal::real(v[j])); + minc = (std::min)(minc, numext::real(v[j])); + maxc = (std::max)(maxc, numext::real(v[j])); } VERIFY_IS_MUCH_SMALLER_THAN(abs(s - v.tail(size-i).sum()), Scalar(1)); VERIFY_IS_APPROX(p, v_for_prod.tail(size-i).prod()); @@ -107,13 +107,13 @@ template void vectorRedux(const VectorType& w) for(int i = 0; i < size/2; i++) { Scalar s(0), p(1); - RealScalar minc(internal::real(v.coeff(i))), maxc(internal::real(v.coeff(i))); + RealScalar minc(numext::real(v.coeff(i))), maxc(numext::real(v.coeff(i))); for(int j = i; j < size-i; j++) { s += v[j]; p *= v_for_prod[j]; - minc = (std::min)(minc, internal::real(v[j])); - maxc = (std::max)(maxc, internal::real(v[j])); + minc = (std::min)(minc, numext::real(v[j])); + maxc = (std::max)(maxc, numext::real(v[j])); } VERIFY_IS_MUCH_SMALLER_THAN(abs(s - v.segment(i, size-2*i).sum()), Scalar(1)); VERIFY_IS_APPROX(p, v_for_prod.segment(i, size-2*i).prod()); diff --git a/test/sparse.h b/test/sparse.h index b6f6e6fce..7e2b98494 100644 --- a/test/sparse.h +++ b/test/sparse.h @@ -86,7 +86,7 @@ initSparse(double density, v = Scalar(0); if ((flags&ForceRealDiag) && (i==j)) - v = internal::real(v); + v = numext::real(v); if (v!=Scalar(0)) { @@ -136,7 +136,7 @@ initSparse(double density, v = Scalar(0); if ((flags&ForceRealDiag) && (i==j)) - v = internal::real(v); + v = numext::real(v); if (v!=Scalar(0)) { diff --git a/test/spqr_support.cpp b/test/spqr_support.cpp index 7e4b6e18a..b8980e081 100644 --- a/test/spqr_support.cpp +++ b/test/spqr_support.cpp @@ -59,4 +59,4 @@ void test_spqr_support() { CALL_SUBTEST_1(test_spqr_scalar()); CALL_SUBTEST_2(test_spqr_scalar >()); -} \ No newline at end of file +} diff --git a/test/triangular.cpp b/test/triangular.cpp index 7e1723af5..a2a7a1475 100644 --- a/test/triangular.cpp +++ b/test/triangular.cpp @@ -65,7 +65,7 @@ template void triangular_square(const MatrixType& m) m1 = MatrixType::Random(rows, cols); for (int i=0; i(); + while (numext::abs2(m1(i,i))<1e-1) m1(i,i) = internal::random(); Transpose trm4(m4); // test back and forward subsitution with a vector as the rhs diff --git a/test/umeyama.cpp b/test/umeyama.cpp index 814d19d01..738d0af70 100644 --- a/test/umeyama.cpp +++ b/test/umeyama.cpp @@ -82,7 +82,7 @@ Eigen::Matrix randMatrixSpecialUnitary(int si MatrixType Q = randMatrixUnitary(size); // tweak the first column to make the determinant be 1 - Q.col(0) *= internal::conj(Q.determinant()); + Q.col(0) *= numext::conj(Q.determinant()); return Q; } diff --git a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h index bb49191b7..8d42e69b9 100644 --- a/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h +++ b/unsupported/Eigen/src/AutoDiff/AutoDiffScalar.h @@ -47,8 +47,8 @@ template struct auto_diff_special_op; * * It supports the following list of global math function: * - std::abs, std::sqrt, std::pow, std::exp, std::log, std::sin, std::cos, - * - internal::abs, internal::sqrt, internal::pow, internal::exp, internal::log, internal::sin, internal::cos, - * - internal::conj, internal::real, internal::imag, internal::abs2. + * - internal::abs, internal::sqrt, numext::pow, internal::exp, internal::log, internal::sin, internal::cos, + * - internal::conj, internal::real, internal::imag, numext::abs2. * * AutoDiffScalar can be used as the scalar type of an Eigen::Matrix object. However, * in that case, the expression template mechanism only occurs at the top Matrix level, @@ -549,7 +549,7 @@ EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs, return ReturnType(abs(x.value()), x.derivatives() * (x.value()<0 ? -1 : 1) );) EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(abs2, - using internal::abs2; + using numext::abs2; return ReturnType(abs2(x.value()), x.derivatives() * (Scalar(2)*x.value()));) EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(sqrt, @@ -612,17 +612,17 @@ atan2(const AutoDiffScalar& a, const AutoDiffScalar& b) EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(tan, using std::tan; using std::cos; - return ReturnType(tan(x.value()),x.derivatives() * (Scalar(1)/internal::abs2(cos(x.value()))));) + return ReturnType(tan(x.value()),x.derivatives() * (Scalar(1)/numext::abs2(cos(x.value()))));) EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(asin, using std::sqrt; using std::asin; - return ReturnType(asin(x.value()),x.derivatives() * (Scalar(1)/sqrt(1-internal::abs2(x.value()))));) + return ReturnType(asin(x.value()),x.derivatives() * (Scalar(1)/sqrt(1-numext::abs2(x.value()))));) EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY(acos, using std::sqrt; using std::acos; - return ReturnType(acos(x.value()),x.derivatives() * (Scalar(-1)/sqrt(1-internal::abs2(x.value()))));) + return ReturnType(acos(x.value()),x.derivatives() * (Scalar(-1)/sqrt(1-numext::abs2(x.value()))));) #undef EIGEN_AUTODIFF_DECLARE_GLOBAL_UNARY diff --git a/unsupported/Eigen/src/AutoDiff/AutoDiffVector.h b/unsupported/Eigen/src/AutoDiff/AutoDiffVector.h index 0540add0a..8c2d04830 100644 --- a/unsupported/Eigen/src/AutoDiff/AutoDiffVector.h +++ b/unsupported/Eigen/src/AutoDiff/AutoDiffVector.h @@ -21,8 +21,8 @@ namespace Eigen { * * It supports the following list of global math function: * - std::abs, std::sqrt, std::pow, std::exp, std::log, std::sin, std::cos, - * - internal::abs, internal::sqrt, internal::pow, internal::exp, internal::log, internal::sin, internal::cos, - * - internal::conj, internal::real, internal::imag, internal::abs2. + * - internal::abs, internal::sqrt, numext::pow, internal::exp, internal::log, internal::sin, internal::cos, + * - internal::conj, internal::real, internal::imag, numext::abs2. * * AutoDiffScalar can be used as the scalar type of an Eigen::Matrix object. However, * in that case, the expression template mechanism only occurs at the top Matrix level, diff --git a/unsupported/Eigen/src/IterativeSolvers/DGMRES.h b/unsupported/Eigen/src/IterativeSolvers/DGMRES.h index 7b5b5a91b..9fcc8a8d9 100644 --- a/unsupported/Eigen/src/IterativeSolvers/DGMRES.h +++ b/unsupported/Eigen/src/IterativeSolvers/DGMRES.h @@ -539,4 +539,4 @@ struct solve_retval, Rhs> } // end namespace internal } // end namespace Eigen -#endif \ No newline at end of file +#endif diff --git a/unsupported/Eigen/src/LevenbergMarquardt/LMonestep.h b/unsupported/Eigen/src/LevenbergMarquardt/LMonestep.h index 60584c523..25b32ec5b 100644 --- a/unsupported/Eigen/src/LevenbergMarquardt/LMonestep.h +++ b/unsupported/Eigen/src/LevenbergMarquardt/LMonestep.h @@ -109,13 +109,13 @@ LevenbergMarquardt::minimizeOneStep(FVectorType &x) /* compute the scaled actual reduction. */ actred = -1.; if (Scalar(.1) * fnorm1 < m_fnorm) - actred = 1. - internal::abs2(fnorm1 / m_fnorm); + actred = 1. - numext::abs2(fnorm1 / m_fnorm); /* compute the scaled predicted reduction and */ /* the scaled directional derivative. */ m_wa3 = m_rfactor.template triangularView() * (m_permutation.inverse() *m_wa1); - temp1 = internal::abs2(m_wa3.stableNorm() / m_fnorm); - temp2 = internal::abs2(sqrt(m_par) * pnorm / m_fnorm); + temp1 = numext::abs2(m_wa3.stableNorm() / m_fnorm); + temp2 = numext::abs2(sqrt(m_par) * pnorm / m_fnorm); prered = temp1 + temp2 / Scalar(.5); dirder = -(temp1 + temp2); diff --git a/unsupported/Eigen/src/MatrixFunctions/MatrixPowerBase.h b/unsupported/Eigen/src/MatrixFunctions/MatrixPowerBase.h index 890225744..636df5363 100644 --- a/unsupported/Eigen/src/MatrixFunctions/MatrixPowerBase.h +++ b/unsupported/Eigen/src/MatrixFunctions/MatrixPowerBase.h @@ -338,7 +338,7 @@ void MatrixPowerTriangularAtomic::compute2x2(MatrixType& res, RealSc res.coeffRef(i-1,i) = m_A.coeff(i-1,i) * (res.coeff(i,i)-res.coeff(i-1,i-1)) / (m_A.coeff(i,i)-m_A.coeff(i-1,i-1)); } else { - int unwindingNumber = std::ceil((internal::imag(logTdiag[i]-logTdiag[i-1]) - M_PI) / (2*M_PI)); + int unwindingNumber = std::ceil((numext::imag(logTdiag[i]-logTdiag[i-1]) - M_PI) / (2*M_PI)); Scalar w = internal::matrix_power_unwinder::run(m_A.coeff(i,i), m_A.coeff(i-1,i-1), unwindingNumber); res.coeffRef(i-1,i) = m_A.coeff(i-1,i) * RealScalar(2) * std::exp(RealScalar(0.5)*p*(logTdiag[i]+logTdiag[i-1])) * std::sinh(p * w) / (m_A.coeff(i,i) - m_A.coeff(i-1,i-1)); diff --git a/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h b/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h index 5b24b4619..b8ba6ddcb 100644 --- a/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h +++ b/unsupported/Eigen/src/NonLinearOptimization/HybridNonLinearSolver.h @@ -254,14 +254,14 @@ HybridNonLinearSolver::solveOneStep(FVectorType &x) /* compute the scaled actual reduction. */ actred = -1.; if (fnorm1 < fnorm) /* Computing 2nd power */ - actred = 1. - internal::abs2(fnorm1 / fnorm); + actred = 1. - numext::abs2(fnorm1 / fnorm); /* compute the scaled predicted reduction. */ wa3 = R.template triangularView()*wa1 + qtf; temp = wa3.stableNorm(); prered = 0.; if (temp < fnorm) /* Computing 2nd power */ - prered = 1. - internal::abs2(temp / fnorm); + prered = 1. - numext::abs2(temp / fnorm); /* compute the ratio of the actual to the predicted reduction. */ ratio = 0.; @@ -497,14 +497,14 @@ HybridNonLinearSolver::solveNumericalDiffOneStep(FVectorType /* compute the scaled actual reduction. */ actred = -1.; if (fnorm1 < fnorm) /* Computing 2nd power */ - actred = 1. - internal::abs2(fnorm1 / fnorm); + actred = 1. - numext::abs2(fnorm1 / fnorm); /* compute the scaled predicted reduction. */ wa3 = R.template triangularView()*wa1 + qtf; temp = wa3.stableNorm(); prered = 0.; if (temp < fnorm) /* Computing 2nd power */ - prered = 1. - internal::abs2(temp / fnorm); + prered = 1. - numext::abs2(temp / fnorm); /* compute the ratio of the actual to the predicted reduction. */ ratio = 0.; diff --git a/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h b/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h index 3d0a9c8fc..bfeb26fc9 100644 --- a/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h +++ b/unsupported/Eigen/src/NonLinearOptimization/LevenbergMarquardt.h @@ -285,13 +285,13 @@ LevenbergMarquardt::minimizeOneStep(FVectorType &x) /* compute the scaled actual reduction. */ actred = -1.; if (Scalar(.1) * fnorm1 < fnorm) - actred = 1. - internal::abs2(fnorm1 / fnorm); + actred = 1. - numext::abs2(fnorm1 / fnorm); /* compute the scaled predicted reduction and */ /* the scaled directional derivative. */ wa3 = fjac.template triangularView() * (qrfac.colsPermutation().inverse() *wa1); - temp1 = internal::abs2(wa3.stableNorm() / fnorm); - temp2 = internal::abs2(sqrt(par) * pnorm / fnorm); + temp1 = numext::abs2(wa3.stableNorm() / fnorm); + temp2 = numext::abs2(sqrt(par) * pnorm / fnorm); prered = temp1 + temp2 / Scalar(.5); dirder = -(temp1 + temp2); @@ -535,13 +535,13 @@ LevenbergMarquardt::minimizeOptimumStorageOneStep(FVectorTyp /* compute the scaled actual reduction. */ actred = -1.; if (Scalar(.1) * fnorm1 < fnorm) - actred = 1. - internal::abs2(fnorm1 / fnorm); + actred = 1. - numext::abs2(fnorm1 / fnorm); /* compute the scaled predicted reduction and */ /* the scaled directional derivative. */ wa3 = fjac.topLeftCorner(n,n).template triangularView() * (permutation.inverse() * wa1); - temp1 = internal::abs2(wa3.stableNorm() / fnorm); - temp2 = internal::abs2(sqrt(par) * pnorm / fnorm); + temp1 = numext::abs2(wa3.stableNorm() / fnorm); + temp2 = numext::abs2(sqrt(par) * pnorm / fnorm); prered = temp1 + temp2 / Scalar(.5); dirder = -(temp1 + temp2); diff --git a/unsupported/Eigen/src/Polynomials/PolynomialSolver.h b/unsupported/Eigen/src/Polynomials/PolynomialSolver.h index ad486f08e..cd5c04bbf 100644 --- a/unsupported/Eigen/src/Polynomials/PolynomialSolver.h +++ b/unsupported/Eigen/src/Polynomials/PolynomialSolver.h @@ -83,10 +83,10 @@ class PolynomialSolverBase inline const RootType& selectComplexRoot_withRespectToNorm( squaredNormBinaryPredicate& pred ) const { Index res=0; - RealScalar norm2 = internal::abs2( m_roots[0] ); + RealScalar norm2 = numext::abs2( m_roots[0] ); for( Index i=1; i::Real Real; - if( internal::abs2( x ) <= Real(1) ){ + if( numext::abs2( x ) <= Real(1) ){ return poly_eval_horner( poly, x ); } else { -- cgit v1.2.3 From f3a029e9579c7290e1e6737f7239afac51ada097 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 12 Jun 2013 13:05:23 +0200 Subject: Remove meaningless explicit qualifier --- Eigen/src/Core/Array.h | 2 +- Eigen/src/Core/DenseStorage.h | 16 ++++++++-------- Eigen/src/Core/Matrix.h | 2 +- Eigen/src/Core/PlainObjectBase.h | 2 +- Eigen/src/Geometry/AlignedBox.h | 2 +- Eigen/src/Geometry/Hyperplane.h | 2 +- Eigen/src/Geometry/ParametrizedLine.h | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Array.h b/Eigen/src/Core/Array.h index bd47e6cbb..497efff66 100644 --- a/Eigen/src/Core/Array.h +++ b/Eigen/src/Core/Array.h @@ -107,7 +107,7 @@ class Array * * \sa resize(Index,Index) */ - EIGEN_STRONG_INLINE explicit Array() : Base() + EIGEN_STRONG_INLINE Array() : Base() { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED diff --git a/Eigen/src/Core/DenseStorage.h b/Eigen/src/Core/DenseStorage.h index 894dcf2c1..3e7f9c1b7 100644 --- a/Eigen/src/Core/DenseStorage.h +++ b/Eigen/src/Core/DenseStorage.h @@ -114,7 +114,7 @@ template class DenseSt { internal::plain_array m_data; public: - inline explicit DenseStorage() {} + inline DenseStorage() {} inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(internal::constructor_without_unaligned_array_assert()) {} inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {} @@ -131,7 +131,7 @@ template class DenseSt template class DenseStorage { public: - inline explicit DenseStorage() {} + inline DenseStorage() {} inline DenseStorage(internal::constructor_without_unaligned_array_assert) {} inline DenseStorage(DenseIndex,DenseIndex,DenseIndex) {} inline void swap(DenseStorage& ) {} @@ -160,7 +160,7 @@ template class DenseStorage class DenseStorage m_data; DenseIndex m_rows; public: - inline explicit DenseStorage() : m_rows(0) {} + inline DenseStorage() : m_rows(0) {} inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(internal::constructor_without_unaligned_array_assert()), m_rows(0) {} inline DenseStorage(DenseIndex, DenseIndex nbRows, DenseIndex) : m_rows(nbRows) {} @@ -199,7 +199,7 @@ template class DenseStorage m_data; DenseIndex m_cols; public: - inline explicit DenseStorage() : m_cols(0) {} + inline DenseStorage() : m_cols(0) {} inline DenseStorage(internal::constructor_without_unaligned_array_assert) : m_data(internal::constructor_without_unaligned_array_assert()), m_cols(0) {} inline DenseStorage(DenseIndex, DenseIndex, DenseIndex nbCols) : m_cols(nbCols) {} @@ -219,7 +219,7 @@ template class DenseStorage class DenseStorage(size)), m_cols(nbCols) { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN } @@ -296,7 +296,7 @@ template class DenseStorage(size)), m_rows(nbRows) { EIGEN_INTERNAL_DENSE_STORAGE_CTOR_PLUGIN } diff --git a/Eigen/src/Core/Matrix.h b/Eigen/src/Core/Matrix.h index 5f6df19fb..0ba5d90cc 100644 --- a/Eigen/src/Core/Matrix.h +++ b/Eigen/src/Core/Matrix.h @@ -200,7 +200,7 @@ class Matrix * * \sa resize(Index,Index) */ - EIGEN_STRONG_INLINE explicit Matrix() : Base() + EIGEN_STRONG_INLINE Matrix() : Base() { Base::_check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED diff --git a/Eigen/src/Core/PlainObjectBase.h b/Eigen/src/Core/PlainObjectBase.h index b01bd6df6..af0a479c7 100644 --- a/Eigen/src/Core/PlainObjectBase.h +++ b/Eigen/src/Core/PlainObjectBase.h @@ -418,7 +418,7 @@ class PlainObjectBase : public internal::dense_xpr_base::type return Base::operator=(func); } - EIGEN_STRONG_INLINE explicit PlainObjectBase() : m_storage() + EIGEN_STRONG_INLINE PlainObjectBase() : m_storage() { // _check_template_params(); // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED diff --git a/Eigen/src/Geometry/AlignedBox.h b/Eigen/src/Geometry/AlignedBox.h index 538a5afb7..8e186d57a 100644 --- a/Eigen/src/Geometry/AlignedBox.h +++ b/Eigen/src/Geometry/AlignedBox.h @@ -56,7 +56,7 @@ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim) /** Default constructor initializing a null box. */ - inline explicit AlignedBox() + inline AlignedBox() { if (AmbientDimAtCompileTime!=Dynamic) setEmpty(); } /** Constructs a null box with \a _dim the dimension of the ambient space. */ diff --git a/Eigen/src/Geometry/Hyperplane.h b/Eigen/src/Geometry/Hyperplane.h index 6b31efde9..aeff43fef 100644 --- a/Eigen/src/Geometry/Hyperplane.h +++ b/Eigen/src/Geometry/Hyperplane.h @@ -50,7 +50,7 @@ public: typedef const Block ConstNormalReturnType; /** Default constructor without initialization */ - inline explicit Hyperplane() {} + inline Hyperplane() {} template Hyperplane(const Hyperplane& other) diff --git a/Eigen/src/Geometry/ParametrizedLine.h b/Eigen/src/Geometry/ParametrizedLine.h index 98dd0f0d1..77fa228e6 100644 --- a/Eigen/src/Geometry/ParametrizedLine.h +++ b/Eigen/src/Geometry/ParametrizedLine.h @@ -41,7 +41,7 @@ public: typedef Matrix VectorType; /** Default constructor without initialization */ - inline explicit ParametrizedLine() {} + inline ParametrizedLine() {} template ParametrizedLine(const ParametrizedLine& other) -- cgit v1.2.3 From d541765e855c376d1abe053889dca39e2cd4e0e2 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 12 Jun 2013 18:02:13 +0200 Subject: Fix copy constructor signature --- Eigen/src/SparseLU/SparseLU.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index c8dcbfa21..ee79c7762 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -344,8 +344,8 @@ class SparseLU : public internal::SparseLUImpl Date: Thu, 13 Jun 2013 18:17:27 +0200 Subject: Fix bug #613: psqrt was incorrect for small numbers --- Eigen/src/Core/arch/SSE/MathFunctions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/arch/SSE/MathFunctions.h b/Eigen/src/Core/arch/SSE/MathFunctions.h index 5ede55fba..1d1a98a9d 100644 --- a/Eigen/src/Core/arch/SSE/MathFunctions.h +++ b/Eigen/src/Core/arch/SSE/MathFunctions.h @@ -450,7 +450,7 @@ Packet4f psqrt(const Packet4f& _x) Packet4f half = pmul(_x, pset1(.5f)); /* select only the inverse sqrt of non-zero inputs */ - Packet4f non_zero_mask = _mm_cmpgt_ps(_x, pset1(std::numeric_limits::epsilon())); + Packet4f non_zero_mask = _mm_cmpgt_ps(_x, pset1((std::numeric_limits::min)())); Packet4f x = _mm_and_ps(non_zero_mask, _mm_rsqrt_ps(_x)); x = pmul(x, psub(pset1(1.5f), pmul(half, pmul(x,x)))); -- cgit v1.2.3 From 9f11f80db1b53d0f9b9173a777c0a644e763619a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 14 Jun 2013 10:55:05 +0200 Subject: Make psqrt works with numeric_limits::min --- Eigen/src/Core/arch/SSE/MathFunctions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/arch/SSE/MathFunctions.h b/Eigen/src/Core/arch/SSE/MathFunctions.h index 1d1a98a9d..3376a984e 100644 --- a/Eigen/src/Core/arch/SSE/MathFunctions.h +++ b/Eigen/src/Core/arch/SSE/MathFunctions.h @@ -450,7 +450,7 @@ Packet4f psqrt(const Packet4f& _x) Packet4f half = pmul(_x, pset1(.5f)); /* select only the inverse sqrt of non-zero inputs */ - Packet4f non_zero_mask = _mm_cmpgt_ps(_x, pset1((std::numeric_limits::min)())); + Packet4f non_zero_mask = _mm_cmpge_ps(_x, pset1((std::numeric_limits::min)())); Packet4f x = _mm_and_ps(non_zero_mask, _mm_rsqrt_ps(_x)); x = pmul(x, psub(pset1(1.5f), pmul(half, pmul(x,x)))); -- cgit v1.2.3 From 55365566b2f81656a58e3d3dad1a82ec3038ca64 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 17 Jun 2013 00:14:42 +0200 Subject: Fix HouseholderSequence::conjugate() and ::adjoint() and add respective unit tests. --- Eigen/src/Eigenvalues/HessenbergDecomposition.h | 2 +- Eigen/src/Eigenvalues/Tridiagonalization.h | 2 +- Eigen/src/Householder/HouseholderSequence.h | 6 ++++-- Eigen/src/QR/ColPivHouseholderQR.h | 2 +- Eigen/src/QR/HouseholderQR.h | 2 +- Eigen/src/SVD/UpperBidiagonalization.h | 4 ++-- test/householder.cpp | 19 ++++++++++++++++++- test/upperbidiagonalization.cpp | 3 +++ 8 files changed, 31 insertions(+), 9 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Eigenvalues/HessenbergDecomposition.h b/Eigen/src/Eigenvalues/HessenbergDecomposition.h index afa636ffa..3db0c0106 100644 --- a/Eigen/src/Eigenvalues/HessenbergDecomposition.h +++ b/Eigen/src/Eigenvalues/HessenbergDecomposition.h @@ -82,7 +82,7 @@ template class HessenbergDecomposition typedef Matrix CoeffVectorType; /** \brief Return type of matrixQ() */ - typedef typename HouseholderSequence::ConjugateReturnType HouseholderSequenceType; + typedef HouseholderSequence::type> HouseholderSequenceType; typedef internal::HessenbergDecompositionMatrixHReturnType MatrixHReturnType; diff --git a/Eigen/src/Eigenvalues/Tridiagonalization.h b/Eigen/src/Eigenvalues/Tridiagonalization.h index b55a01d3a..192278d68 100644 --- a/Eigen/src/Eigenvalues/Tridiagonalization.h +++ b/Eigen/src/Eigenvalues/Tridiagonalization.h @@ -96,7 +96,7 @@ template class Tridiagonalization >::type SubDiagonalReturnType; /** \brief Return type of matrixQ() */ - typedef typename HouseholderSequence::ConjugateReturnType HouseholderSequenceType; + typedef HouseholderSequence::type> HouseholderSequenceType; /** \brief Default constructor. * diff --git a/Eigen/src/Householder/HouseholderSequence.h b/Eigen/src/Householder/HouseholderSequence.h index 0de2a0084..d800ca1fa 100644 --- a/Eigen/src/Householder/HouseholderSequence.h +++ b/Eigen/src/Householder/HouseholderSequence.h @@ -125,7 +125,9 @@ template class HouseholderS typedef typename VectorsType::Index Index; typedef HouseholderSequence< - VectorsType, + typename internal::conditional::IsComplex, + typename internal::remove_all::type, + VectorsType>::type, typename internal::conditional::IsComplex, typename internal::remove_all::type, CoeffsType>::type, @@ -206,7 +208,7 @@ template class HouseholderS /** \brief Complex conjugate of the Householder sequence. */ ConjugateReturnType conjugate() const { - return ConjugateReturnType(m_vectors, m_coeffs.conjugate()) + return ConjugateReturnType(m_vectors.conjugate(), m_coeffs.conjugate()) .setTrans(m_trans) .setLength(m_length) .setShift(m_shift); diff --git a/Eigen/src/QR/ColPivHouseholderQR.h b/Eigen/src/QR/ColPivHouseholderQR.h index 7d475b936..8a7c9b9e2 100644 --- a/Eigen/src/QR/ColPivHouseholderQR.h +++ b/Eigen/src/QR/ColPivHouseholderQR.h @@ -55,7 +55,7 @@ template class ColPivHouseholderQR typedef typename internal::plain_row_type::type IntRowVectorType; typedef typename internal::plain_row_type::type RowVectorType; typedef typename internal::plain_row_type::type RealRowVectorType; - typedef typename HouseholderSequence::ConjugateReturnType HouseholderSequenceType; + typedef HouseholderSequence::type> HouseholderSequenceType; private: diff --git a/Eigen/src/QR/HouseholderQR.h b/Eigen/src/QR/HouseholderQR.h index 5a620f495..abc61bcbb 100644 --- a/Eigen/src/QR/HouseholderQR.h +++ b/Eigen/src/QR/HouseholderQR.h @@ -57,7 +57,7 @@ template class HouseholderQR typedef Matrix MatrixQType; typedef typename internal::plain_diag_type::type HCoeffsType; typedef typename internal::plain_row_type::type RowVectorType; - typedef typename HouseholderSequence::ConjugateReturnType HouseholderSequenceType; + typedef HouseholderSequence::type> HouseholderSequenceType; /** * \brief Default Constructor. diff --git a/Eigen/src/SVD/UpperBidiagonalization.h b/Eigen/src/SVD/UpperBidiagonalization.h index 213b3100d..587de37a5 100644 --- a/Eigen/src/SVD/UpperBidiagonalization.h +++ b/Eigen/src/SVD/UpperBidiagonalization.h @@ -39,7 +39,7 @@ template class UpperBidiagonalization CwiseUnaryOp, const Diagonal > > HouseholderUSequenceType; typedef HouseholderSequence< - const MatrixType, + const typename internal::remove_all::type, Diagonal, OnTheRight > HouseholderVSequenceType; @@ -74,7 +74,7 @@ template class UpperBidiagonalization const HouseholderVSequenceType householderV() // const here gives nasty errors and i'm lazy { eigen_assert(m_isInitialized && "UpperBidiagonalization is not initialized."); - return HouseholderVSequenceType(m_householder, m_householder.const_derived().template diagonal<1>()) + return HouseholderVSequenceType(m_householder.conjugate(), m_householder.const_derived().template diagonal<1>()) .setLength(m_householder.cols()-1) .setShift(1); } diff --git a/test/householder.cpp b/test/householder.cpp index d10cadd6c..c5f6b5e4f 100644 --- a/test/householder.cpp +++ b/test/householder.cpp @@ -89,12 +89,29 @@ template void householder(const MatrixType& m) hseq.setLength(hc.size()).setShift(shift); VERIFY(hseq.length() == hc.size()); VERIFY(hseq.shift() == shift); - + MatrixType m5 = m2; m5.block(shift,0,brows,cols).template triangularView().setZero(); VERIFY_IS_APPROX(hseq * m5, m1); // test applying hseq directly m3 = hseq; VERIFY_IS_APPROX(m3 * m5, m1); // test evaluating hseq to a dense matrix, then applying + + SquareMatrixType hseq_mat = hseq; + SquareMatrixType hseq_mat_conj = hseq.conjugate(); + SquareMatrixType hseq_mat_adj = hseq.adjoint(); + SquareMatrixType hseq_mat_trans = hseq.transpose(); + SquareMatrixType m6 = SquareMatrixType::Random(rows, rows); + VERIFY_IS_APPROX(hseq_mat.adjoint(), hseq_mat_adj); + VERIFY_IS_APPROX(hseq_mat.conjugate(), hseq_mat_conj); + VERIFY_IS_APPROX(hseq_mat.transpose(), hseq_mat_trans); + VERIFY_IS_APPROX(hseq_mat * m6, hseq_mat * m6); + VERIFY_IS_APPROX(hseq_mat.adjoint() * m6, hseq_mat_adj * m6); + VERIFY_IS_APPROX(hseq_mat.conjugate() * m6, hseq_mat_conj * m6); + VERIFY_IS_APPROX(hseq_mat.transpose() * m6, hseq_mat_trans * m6); + VERIFY_IS_APPROX(m6 * hseq_mat, m6 * hseq_mat); + VERIFY_IS_APPROX(m6 * hseq_mat.adjoint(), m6 * hseq_mat_adj); + VERIFY_IS_APPROX(m6 * hseq_mat.conjugate(), m6 * hseq_mat_conj); + VERIFY_IS_APPROX(m6 * hseq_mat.transpose(), m6 * hseq_mat_trans); // test householder sequence on the right with a shift diff --git a/test/upperbidiagonalization.cpp b/test/upperbidiagonalization.cpp index 5897cffab..d15bf588b 100644 --- a/test/upperbidiagonalization.cpp +++ b/test/upperbidiagonalization.cpp @@ -16,6 +16,7 @@ template void upperbidiag(const MatrixType& m) const typename MatrixType::Index cols = m.cols(); typedef Matrix RealMatrixType; + typedef Matrix TransposeMatrixType; MatrixType a = MatrixType::Random(rows,cols); internal::UpperBidiagonalization ubd(a); @@ -24,6 +25,8 @@ template void upperbidiag(const MatrixType& m) b.block(0,0,cols,cols) = ubd.bidiagonal(); MatrixType c = ubd.householderU() * b * ubd.householderV().adjoint(); VERIFY_IS_APPROX(a,c); + TransposeMatrixType d = ubd.householderV() * b.adjoint() * ubd.householderU().adjoint(); + VERIFY_IS_APPROX(a.adjoint(),d); } void test_upperbidiagonalization() -- cgit v1.2.3 From 437e26d000f8a598574dacab53c052a455b893f4 Mon Sep 17 00:00:00 2001 From: Rhys Ulerich Date: Mon, 17 Jun 2013 14:28:42 +0000 Subject: Fix documentation typo --- Eigen/src/LU/Inverse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/LU/Inverse.h b/Eigen/src/LU/Inverse.h index a5ae83bf4..3cf887193 100644 --- a/Eigen/src/LU/Inverse.h +++ b/Eigen/src/LU/Inverse.h @@ -331,7 +331,7 @@ inline const internal::inverse_impl MatrixBase::inverse() cons * This is only for fixed-size square matrices of size up to 4x4. * * \param inverse Reference to the matrix in which to store the inverse. - * \param determinant Reference to the variable in which to store the inverse. + * \param determinant Reference to the variable in which to store the determinant. * \param invertible Reference to the bool variable in which to store whether the matrix is invertible. * \param absDeterminantThreshold Optional parameter controlling the invertibility check. * The matrix will be declared invertible if the absolute value of its -- cgit v1.2.3 From 33788b97dd2cd8662c598e14e1e901a7bd4df93b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 18 Jun 2013 00:48:47 +0200 Subject: Fix compilation issue with some compilers (when doing using Base::foo;, foo must be visible in the direct base class) --- Eigen/src/Core/Transpose.h | 1 + 1 file changed, 1 insertion(+) (limited to 'Eigen') diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 2bc828e19..95a7b95e5 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -104,6 +104,7 @@ template class TransposeImpl typedef typename internal::TransposeImpl_base::type Base; EIGEN_DENSE_PUBLIC_INTERFACE(Transpose) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(TransposeImpl) inline Index innerStride() const { return derived().nestedExpression().innerStride(); } inline Index outerStride() const { return derived().nestedExpression().outerStride(); } -- cgit v1.2.3 From e37ff98bbb21f2ee44c6d912002ddf2cdf05ccda Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Tue, 18 Jun 2013 14:29:15 +0100 Subject: Implement mixed static/dynamic-size .block() (bug #579) --- Eigen/src/plugins/BlockMethods.h | 158 ++++++++++++++++++++- doc/LinearLeastSquares.dox | 27 ++++ ...Base_template_int_int_block_int_int_int_int.cpp | 5 + ...e_template_int_int_bottomLeftCorner_int_int.cpp | 6 + ..._template_int_int_bottomRightCorner_int_int.cpp | 6 + ...Base_template_int_int_topLeftCorner_int_int.cpp | 6 + ...ase_template_int_int_topRightCorner_int_int.cpp | 6 + test/block.cpp | 6 + test/corners.cpp | 20 +++ 9 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 doc/LinearLeastSquares.dox create mode 100644 doc/snippets/MatrixBase_template_int_int_block_int_int_int_int.cpp create mode 100644 doc/snippets/MatrixBase_template_int_int_bottomLeftCorner_int_int.cpp create mode 100644 doc/snippets/MatrixBase_template_int_int_bottomRightCorner_int_int.cpp create mode 100644 doc/snippets/MatrixBase_template_int_int_topLeftCorner_int_int.cpp create mode 100644 doc/snippets/MatrixBase_template_int_int_topRightCorner_int_int.cpp (limited to 'Eigen') diff --git a/Eigen/src/plugins/BlockMethods.h b/Eigen/src/plugins/BlockMethods.h index 19a491cf7..6911bedef 100644 --- a/Eigen/src/plugins/BlockMethods.h +++ b/Eigen/src/plugins/BlockMethods.h @@ -90,12 +90,13 @@ inline const Block topRightCorner(Index cRows, Index cCols) const /** \returns an expression of a fixed-size top-right corner of *this. * - * The template parameters CRows and CCols are the number of rows and columns in the corner. + * \tparam CRows the number of rows in the corner + * \tparam CCols the number of columns in the corner * * Example: \include MatrixBase_template_int_int_topRightCorner.cpp * Output: \verbinclude MatrixBase_template_int_int_topRightCorner.out * - * \sa class Block, block(Index,Index,Index,Index) + * \sa class Block, block(Index,Index) */ template inline Block topRightCorner() @@ -110,6 +111,35 @@ inline const Block topRightCorner() const return Block(derived(), 0, cols() - CCols); } +/** \returns an expression of a top-right corner of *this. + * + * \tparam CRows number of rows in corner as specified at compile time + * \tparam CCols number of columns in corner as specified at compile time + * \param cRows number of rows in corner as specified at run time + * \param cCols number of columns in corner as specified at run time + * + * This function is mainly useful for corners where the number of rows is specified at compile time + * and the number of columns is specified at run time, or vice versa. The compile-time and run-time + * information should not contradict. In other words, \a cRows should equal \a CRows unless + * \a CRows is \a Dynamic, and the same for the number of columns. + * + * Example: \include MatrixBase_template_int_int_topRightCorner_int_int.cpp + * Output: \verbinclude MatrixBase_template_int_int_topRightCorner_int_int.out + * + * \sa class Block + */ +template +inline Block topRightCorner(Index cRows, Index cCols) +{ + return Block(derived(), 0, cols() - cCols, cRows, cCols); +} + +/** This is the const version of topRightCorner(Index, Index).*/ +template +inline const Block topRightCorner(Index cRows, Index cCols) const +{ + return Block(derived(), 0, cols() - cCols, cRows, cCols); +} @@ -156,6 +186,36 @@ inline const Block topLeftCorner() const return Block(derived(), 0, 0); } +/** \returns an expression of a top-left corner of *this. + * + * \tparam CRows number of rows in corner as specified at compile time + * \tparam CCols number of columns in corner as specified at compile time + * \param cRows number of rows in corner as specified at run time + * \param cCols number of columns in corner as specified at run time + * + * This function is mainly useful for corners where the number of rows is specified at compile time + * and the number of columns is specified at run time, or vice versa. The compile-time and run-time + * information should not contradict. In other words, \a cRows should equal \a CRows unless + * \a CRows is \a Dynamic, and the same for the number of columns. + * + * Example: \include MatrixBase_template_int_int_topLeftCorner_int_int.cpp + * Output: \verbinclude MatrixBase_template_int_int_topLeftCorner_int_int.out + * + * \sa class Block + */ +template +inline Block topLeftCorner(Index cRows, Index cCols) +{ + return Block(derived(), 0, 0, cRows, cCols); +} + +/** This is the const version of topLeftCorner(Index, Index).*/ +template +inline const Block topLeftCorner(Index cRows, Index cCols) const +{ + return Block(derived(), 0, 0, cRows, cCols); +} + /** \returns a dynamic-size expression of a bottom-right corner of *this. @@ -201,6 +261,36 @@ inline const Block bottomRightCorner() const return Block(derived(), rows() - CRows, cols() - CCols); } +/** \returns an expression of a bottom-right corner of *this. + * + * \tparam CRows number of rows in corner as specified at compile time + * \tparam CCols number of columns in corner as specified at compile time + * \param cRows number of rows in corner as specified at run time + * \param cCols number of columns in corner as specified at run time + * + * This function is mainly useful for corners where the number of rows is specified at compile time + * and the number of columns is specified at run time, or vice versa. The compile-time and run-time + * information should not contradict. In other words, \a cRows should equal \a CRows unless + * \a CRows is \a Dynamic, and the same for the number of columns. + * + * Example: \include MatrixBase_template_int_int_bottomRightCorner_int_int.cpp + * Output: \verbinclude MatrixBase_template_int_int_bottomRightCorner_int_int.out + * + * \sa class Block + */ +template +inline Block bottomRightCorner(Index cRows, Index cCols) +{ + return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); +} + +/** This is the const version of bottomRightCorner(Index, Index).*/ +template +inline const Block bottomRightCorner(Index cRows, Index cCols) const +{ + return Block(derived(), rows() - cRows, cols() - cCols, cRows, cCols); +} + /** \returns a dynamic-size expression of a bottom-left corner of *this. @@ -246,6 +336,36 @@ inline const Block bottomLeftCorner() const return Block(derived(), rows() - CRows, 0); } +/** \returns an expression of a bottom-left corner of *this. + * + * \tparam CRows number of rows in corner as specified at compile time + * \tparam CCols number of columns in corner as specified at compile time + * \param cRows number of rows in corner as specified at run time + * \param cCols number of columns in corner as specified at run time + * + * This function is mainly useful for corners where the number of rows is specified at compile time + * and the number of columns is specified at run time, or vice versa. The compile-time and run-time + * information should not contradict. In other words, \a cRows should equal \a CRows unless + * \a CRows is \a Dynamic, and the same for the number of columns. + * + * Example: \include MatrixBase_template_int_int_bottomLeftCorner_int_int.cpp + * Output: \verbinclude MatrixBase_template_int_int_bottomLeftCorner_int_int.out + * + * \sa class Block + */ +template +inline Block bottomLeftCorner(Index cRows, Index cCols) +{ + return Block(derived(), rows() - cRows, 0, cRows, cCols); +} + +/** This is the const version of bottomLeftCorner(Index, Index).*/ +template +inline const Block bottomLeftCorner(Index cRows, Index cCols) const +{ + return Block(derived(), rows() - cRows, 0, cRows, cCols); +} + /** \returns a block consisting of the top rows of *this. @@ -545,6 +665,40 @@ inline const Block block(Index startRow, In return Block(derived(), startRow, startCol); } +/** \returns an expression of a block in *this. + * + * \tparam BlockRows number of rows in block as specified at compile time + * \tparam BlockCols number of columns in block as specified at compile time + * \param startRow the first row in the block + * \param startCol the first column in the block + * \param blockRows number of rows in block as specified at run time + * \param blockCols number of columns in block as specified at run time + * + * This function is mainly useful for blocks where the number of rows is specified at compile time + * and the number of columns is specified at run time, or vice versa. The compile-time and run-time + * information should not contradict. In other words, \a blockRows should equal \a BlockRows unless + * \a BlockRows is \a Dynamic, and the same for the number of columns. + * + * Example: \include MatrixBase_template_int_int_block_int_int_int_int.cpp + * Output: \verbinclude MatrixBase_template_int_int_block_int_int_int_int.cpp + * + * \sa class Block, block(Index,Index,Index,Index) + */ +template +inline Block block(Index startRow, Index startCol, + Index blockRows, Index blockCols) +{ + return Block(derived(), startRow, startCol, blockRows, blockCols); +} + +/** This is the const version of block<>(Index, Index, Index, Index). */ +template +inline const Block block(Index startRow, Index startCol, + Index blockRows, Index blockCols) const +{ + return Block(derived(), startRow, startCol, blockRows, blockCols); +} + /** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0. * * Example: \include MatrixBase_col.cpp diff --git a/doc/LinearLeastSquares.dox b/doc/LinearLeastSquares.dox new file mode 100644 index 000000000..ab21a87ae --- /dev/null +++ b/doc/LinearLeastSquares.dox @@ -0,0 +1,27 @@ +namespace Eigen { + +/** \eigenManualPage LinearLeastSquares Solving linear least squares problems + +lede + +\eigenAutoToc + +\section LinearLeastSquaresCopied Copied + +The best way to do least squares solving is with a SVD decomposition. Eigen provides one as the JacobiSVD class, and its solve() +is doing least-squares solving. + +Here is an example: + + + + + + +
Example:Output:
\include TutorialLinAlgSVDSolve.cpp \verbinclude TutorialLinAlgSVDSolve.out
+ +For more information, including faster but less reliable methods, read our page concentrating on \ref LinearLeastSquares "linear least squares problems". + +*/ + +} diff --git a/doc/snippets/MatrixBase_template_int_int_block_int_int_int_int.cpp b/doc/snippets/MatrixBase_template_int_int_block_int_int_int_int.cpp new file mode 100644 index 000000000..4dced03ba --- /dev/null +++ b/doc/snippets/MatrixBase_template_int_int_block_int_int_int_int.cpp @@ -0,0 +1,5 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is the block:" << endl << m.block<2, Dynamic>(1, 1, 2, 3) << endl; +m.block<2, Dynamic>(1, 1, 2, 3).setZero(); +cout << "Now the matrix m is:" << endl << m << endl; diff --git a/doc/snippets/MatrixBase_template_int_int_bottomLeftCorner_int_int.cpp b/doc/snippets/MatrixBase_template_int_int_bottomLeftCorner_int_int.cpp new file mode 100644 index 000000000..a1edcc808 --- /dev/null +++ b/doc/snippets/MatrixBase_template_int_int_bottomLeftCorner_int_int.cpp @@ -0,0 +1,6 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.bottomLeftCorner<2,Dynamic>(2,2):" << endl; +cout << m.bottomLeftCorner<2,Dynamic>(2,2) << endl; +m.bottomLeftCorner<2,Dynamic>(2,2).setZero(); +cout << "Now the matrix m is:" << endl << m << endl; diff --git a/doc/snippets/MatrixBase_template_int_int_bottomRightCorner_int_int.cpp b/doc/snippets/MatrixBase_template_int_int_bottomRightCorner_int_int.cpp new file mode 100644 index 000000000..a65508fd8 --- /dev/null +++ b/doc/snippets/MatrixBase_template_int_int_bottomRightCorner_int_int.cpp @@ -0,0 +1,6 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.bottomRightCorner<2,Dynamic>(2,2):" << endl; +cout << m.bottomRightCorner<2,Dynamic>(2,2) << endl; +m.bottomRightCorner<2,Dynamic>(2,2).setZero(); +cout << "Now the matrix m is:" << endl << m << endl; diff --git a/doc/snippets/MatrixBase_template_int_int_topLeftCorner_int_int.cpp b/doc/snippets/MatrixBase_template_int_int_topLeftCorner_int_int.cpp new file mode 100644 index 000000000..fac761f63 --- /dev/null +++ b/doc/snippets/MatrixBase_template_int_int_topLeftCorner_int_int.cpp @@ -0,0 +1,6 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.topLeftCorner<2,Dynamic>(2,2):" << endl; +cout << m.topLeftCorner<2,Dynamic>(2,2) << endl; +m.topLeftCorner<2,Dynamic>(2,2).setZero(); +cout << "Now the matrix m is:" << endl << m << endl; diff --git a/doc/snippets/MatrixBase_template_int_int_topRightCorner_int_int.cpp b/doc/snippets/MatrixBase_template_int_int_topRightCorner_int_int.cpp new file mode 100644 index 000000000..a17acc004 --- /dev/null +++ b/doc/snippets/MatrixBase_template_int_int_topRightCorner_int_int.cpp @@ -0,0 +1,6 @@ +Matrix4i m = Matrix4i::Random(); +cout << "Here is the matrix m:" << endl << m << endl; +cout << "Here is m.topRightCorner<2,Dynamic>(2,2):" << endl; +cout << m.topRightCorner<2,Dynamic>(2,2) << endl; +m.topRightCorner<2,Dynamic>(2,2).setZero(); +cout << "Now the matrix m is:" << endl << m << endl; diff --git a/test/block.cpp b/test/block.cpp index a3246f411..189fa5aba 100644 --- a/test/block.cpp +++ b/test/block.cpp @@ -77,6 +77,12 @@ template void block(const MatrixType& m) // check that fixed block() and block() agree Matrix b = m1.template block(3,3); VERIFY_IS_EQUAL(b, m1.block(3,3,BlockRows,BlockCols)); + + // same tests with mixed fixed/dynamic size + m1.template block(1,1,BlockRows,BlockCols) *= s1; + m1.template block(1,1,BlockRows,BlockCols)(0,3) = m1.template block<2,5>(1,1)(1,2); + Matrix b2 = m1.template block(3,3,2,5); + VERIFY_IS_EQUAL(b2, m1.block(3,3,BlockRows,BlockCols)); } if (rows>2) diff --git a/test/corners.cpp b/test/corners.cpp index 4705c5f05..3c64c32a1 100644 --- a/test/corners.cpp +++ b/test/corners.cpp @@ -62,6 +62,16 @@ template void c VERIFY_IS_EQUAL((matrix.template bottomLeftCorner()), (matrix.template block(rows-r,0))); VERIFY_IS_EQUAL((matrix.template bottomRightCorner()), (matrix.template block(rows-r,cols-c))); + VERIFY_IS_EQUAL((matrix.template topLeftCorner()), (matrix.template topLeftCorner(r,c))); + VERIFY_IS_EQUAL((matrix.template topRightCorner()), (matrix.template topRightCorner(r,c))); + VERIFY_IS_EQUAL((matrix.template bottomLeftCorner()), (matrix.template bottomLeftCorner(r,c))); + VERIFY_IS_EQUAL((matrix.template bottomRightCorner()), (matrix.template bottomRightCorner(r,c))); + + VERIFY_IS_EQUAL((matrix.template topLeftCorner()), (matrix.template topLeftCorner(r,c))); + VERIFY_IS_EQUAL((matrix.template topRightCorner()), (matrix.template topRightCorner(r,c))); + VERIFY_IS_EQUAL((matrix.template bottomLeftCorner()), (matrix.template bottomLeftCorner(r,c))); + VERIFY_IS_EQUAL((matrix.template bottomRightCorner()), (matrix.template bottomRightCorner(r,c))); + VERIFY_IS_EQUAL((matrix.template topRows()), (matrix.template block(0,0))); VERIFY_IS_EQUAL((matrix.template middleRows(sr)), (matrix.template block(sr,0))); VERIFY_IS_EQUAL((matrix.template bottomRows()), (matrix.template block(rows-r,0))); @@ -74,6 +84,16 @@ template void c VERIFY_IS_EQUAL((const_matrix.template bottomLeftCorner()), (const_matrix.template block(rows-r,0))); VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner()), (const_matrix.template block(rows-r,cols-c))); + VERIFY_IS_EQUAL((const_matrix.template topLeftCorner()), (const_matrix.template topLeftCorner(r,c))); + VERIFY_IS_EQUAL((const_matrix.template topRightCorner()), (const_matrix.template topRightCorner(r,c))); + VERIFY_IS_EQUAL((const_matrix.template bottomLeftCorner()), (const_matrix.template bottomLeftCorner(r,c))); + VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner()), (const_matrix.template bottomRightCorner(r,c))); + + VERIFY_IS_EQUAL((const_matrix.template topLeftCorner()), (const_matrix.template topLeftCorner(r,c))); + VERIFY_IS_EQUAL((const_matrix.template topRightCorner()), (const_matrix.template topRightCorner(r,c))); + VERIFY_IS_EQUAL((const_matrix.template bottomLeftCorner()), (const_matrix.template bottomLeftCorner(r,c))); + VERIFY_IS_EQUAL((const_matrix.template bottomRightCorner()), (const_matrix.template bottomRightCorner(r,c))); + VERIFY_IS_EQUAL((const_matrix.template topRows()), (const_matrix.template block(0,0))); VERIFY_IS_EQUAL((const_matrix.template middleRows(sr)), (const_matrix.template block(sr,0))); VERIFY_IS_EQUAL((const_matrix.template bottomRows()), (const_matrix.template block(rows-r,0))); -- cgit v1.2.3 From ba79e39c5c641888f58bff01febe9b81c4a22cbc Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 18 Jun 2013 17:44:25 +0200 Subject: bug #71: enable vectorization of diagonal products in more cases. --- Eigen/src/Core/DiagonalProduct.h | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/DiagonalProduct.h b/Eigen/src/Core/DiagonalProduct.h index d55b2c250..c03a0c2e1 100644 --- a/Eigen/src/Core/DiagonalProduct.h +++ b/Eigen/src/Core/DiagonalProduct.h @@ -26,14 +26,15 @@ struct traits > MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, _StorageOrder = MatrixType::Flags & RowMajorBit ? RowMajor : ColMajor, - _PacketOnDiag = !((int(_StorageOrder) == RowMajor && int(ProductOrder) == OnTheLeft) - ||(int(_StorageOrder) == ColMajor && int(ProductOrder) == OnTheRight)), + _ScalarAccessOnDiag = !((int(_StorageOrder) == ColMajor && int(ProductOrder) == OnTheLeft) + ||(int(_StorageOrder) == RowMajor && int(ProductOrder) == OnTheRight)), _SameTypes = is_same::value, // FIXME currently we need same types, but in the future the next rule should be the one - //_Vectorizable = bool(int(MatrixType::Flags)&PacketAccessBit) && ((!_PacketOnDiag) || (_SameTypes && bool(int(DiagonalType::Flags)&PacketAccessBit))), - _Vectorizable = bool(int(MatrixType::Flags)&PacketAccessBit) && _SameTypes && ((!_PacketOnDiag) || (bool(int(DiagonalType::Flags)&PacketAccessBit))), + //_Vectorizable = bool(int(MatrixType::Flags)&PacketAccessBit) && ((!_PacketOnDiag) || (_SameTypes && bool(int(DiagonalType::DiagonalVectorType::Flags)&PacketAccessBit))), + _Vectorizable = bool(int(MatrixType::Flags)&PacketAccessBit) && _SameTypes && (_ScalarAccessOnDiag || (bool(int(DiagonalType::DiagonalVectorType::Flags)&PacketAccessBit))), + _LinearAccessMask = (RowsAtCompileTime==1 || ColsAtCompileTime==1) ? LinearAccessBit : 0, - Flags = (HereditaryBits & (unsigned int)(MatrixType::Flags)) | (_Vectorizable ? PacketAccessBit : 0), + Flags = ((HereditaryBits|_LinearAccessMask) & (unsigned int)(MatrixType::Flags)) | (_Vectorizable ? PacketAccessBit : 0) | AlignedBit,//(int(MatrixType::Flags)&int(DiagonalType::DiagonalVectorType::Flags)&AlignedBit), CoeffReadCost = NumTraits::MulCost + MatrixType::CoeffReadCost + DiagonalType::DiagonalVectorType::CoeffReadCost }; }; @@ -54,13 +55,21 @@ class DiagonalProduct : internal::no_assignment_operator, eigen_assert(diagonal.diagonal().size() == (ProductOrder == OnTheLeft ? matrix.rows() : matrix.cols())); } - inline Index rows() const { return m_matrix.rows(); } - inline Index cols() const { return m_matrix.cols(); } + EIGEN_STRONG_INLINE Index rows() const { return m_matrix.rows(); } + EIGEN_STRONG_INLINE Index cols() const { return m_matrix.cols(); } - const Scalar coeff(Index row, Index col) const + EIGEN_STRONG_INLINE const Scalar coeff(Index row, Index col) const { return m_diagonal.diagonal().coeff(ProductOrder == OnTheLeft ? row : col) * m_matrix.coeff(row, col); } + + EIGEN_STRONG_INLINE const Scalar coeff(Index idx) const + { + enum { + StorageOrder = int(MatrixType::Flags) & RowMajorBit ? RowMajor : ColMajor + }; + return coeff(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx); + } template EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col) const @@ -69,11 +78,19 @@ class DiagonalProduct : internal::no_assignment_operator, StorageOrder = Flags & RowMajorBit ? RowMajor : ColMajor }; const Index indexInDiagonalVector = ProductOrder == OnTheLeft ? row : col; - return packet_impl(row,col,indexInDiagonalVector,typename internal::conditional< ((int(StorageOrder) == RowMajor && int(ProductOrder) == OnTheLeft) ||(int(StorageOrder) == ColMajor && int(ProductOrder) == OnTheRight)), internal::true_type, internal::false_type>::type()); } + + template + EIGEN_STRONG_INLINE PacketScalar packet(Index idx) const + { + enum { + StorageOrder = int(MatrixType::Flags) & RowMajorBit ? RowMajor : ColMajor + }; + return packet(int(StorageOrder)==ColMajor?idx:0,int(StorageOrder)==ColMajor?0:idx); + } protected: template @@ -88,7 +105,7 @@ class DiagonalProduct : internal::no_assignment_operator, { enum { InnerSize = (MatrixType::Flags & RowMajorBit) ? MatrixType::ColsAtCompileTime : MatrixType::RowsAtCompileTime, - DiagonalVectorPacketLoadMode = (LoadMode == Aligned && ((InnerSize%16) == 0)) ? Aligned : Unaligned + DiagonalVectorPacketLoadMode = (LoadMode == Aligned && (((InnerSize%16) == 0) || (int(DiagonalType::DiagonalVectorType::Flags)&AlignedBit)==AlignedBit) ? Aligned : Unaligned) }; return internal::pmul(m_matrix.template packet(row, col), m_diagonal.diagonal().template packet(id)); -- cgit v1.2.3 From 8cc9b125899d47e19dd5d4e683af45390bfd565a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 21 Jun 2013 11:37:33 +0200 Subject: Add missing using std::pow in lpNorm. --- Eigen/src/Core/Dot.h | 1 + 1 file changed, 1 insertion(+) (limited to 'Eigen') diff --git a/Eigen/src/Core/Dot.h b/Eigen/src/Core/Dot.h index e4107a1ac..9d7651f1f 100644 --- a/Eigen/src/Core/Dot.h +++ b/Eigen/src/Core/Dot.h @@ -166,6 +166,7 @@ struct lpNorm_selector typedef typename NumTraits::Scalar>::Real RealScalar; static inline RealScalar run(const MatrixBase& m) { + using std::pow; return pow(m.cwiseAbs().array().pow(p).sum(), RealScalar(1)/p); } }; -- cgit v1.2.3 From 620e4277bc5cb434886ea8794c90def0c460fb02 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 21 Jun 2013 17:49:36 +0200 Subject: Disable ASM comments on non x86 architecture and do not redfine if EIGEN_ASM_COMMENT is already defined --- Eigen/src/Core/util/Macros.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 2368c896f..96737456a 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -240,10 +240,12 @@ // Suppresses 'unused variable' warnings. #define EIGEN_UNUSED_VARIABLE(var) (void)var; -#if !defined(EIGEN_ASM_COMMENT) && (defined __GNUC__) -#define EIGEN_ASM_COMMENT(X) asm("#" X) -#else -#define EIGEN_ASM_COMMENT(X) +#if !defined(EIGEN_ASM_COMMENT) + #if (defined __GNUC__) && ( defined(__i386__) || defined(__x86_64__) ) + #define EIGEN_ASM_COMMENT(X) asm("#" X) + #else + #define EIGEN_ASM_COMMENT(X) + #endif #endif /* EIGEN_ALIGN_TO_BOUNDARY(n) forces data to be n-byte aligned. This is used to satisfy SIMD requirements. -- cgit v1.2.3 From dd964ec08c76b744d4c51d340b9ca19b0b800d22 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 21 Jun 2013 19:06:45 +0200 Subject: Fix a couple of warnings --- Eigen/src/Eigen2Support/Geometry/AlignedBox.h | 2 +- Eigen/src/Eigen2Support/Geometry/Hyperplane.h | 2 +- Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h | 2 +- Eigen/src/Geometry/EulerAngles.h | 1 - unsupported/test/kronecker_product.cpp | 4 ++-- 5 files changed, 5 insertions(+), 6 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Eigen2Support/Geometry/AlignedBox.h b/Eigen/src/Eigen2Support/Geometry/AlignedBox.h index 7b2b865eb..2e4309dd9 100644 --- a/Eigen/src/Eigen2Support/Geometry/AlignedBox.h +++ b/Eigen/src/Eigen2Support/Geometry/AlignedBox.h @@ -34,7 +34,7 @@ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim== typedef Matrix VectorType; /** Default constructor initializing a null box. */ - inline explicit AlignedBox() + inline AlignedBox() { if (AmbientDimAtCompileTime!=Dynamic) setNull(); } /** Constructs a null box with \a _dim the dimension of the ambient space. */ diff --git a/Eigen/src/Eigen2Support/Geometry/Hyperplane.h b/Eigen/src/Eigen2Support/Geometry/Hyperplane.h index 49e37392d..b95bf00ec 100644 --- a/Eigen/src/Eigen2Support/Geometry/Hyperplane.h +++ b/Eigen/src/Eigen2Support/Geometry/Hyperplane.h @@ -44,7 +44,7 @@ public: typedef Block NormalReturnType; /** Default constructor without initialization */ - inline explicit Hyperplane() {} + inline Hyperplane() {} /** Constructs a dynamic-size hyperplane with \a _dim the dimension * of the ambient space */ diff --git a/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h b/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h index 3523611ee..9b57b7e0b 100644 --- a/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h +++ b/Eigen/src/Eigen2Support/Geometry/ParametrizedLine.h @@ -36,7 +36,7 @@ public: typedef Matrix VectorType; /** Default constructor without initialization */ - inline explicit ParametrizedLine() {} + inline ParametrizedLine() {} /** Constructs a dynamic-size line with \a _dim the dimension * of the ambient space */ diff --git a/Eigen/src/Geometry/EulerAngles.h b/Eigen/src/Geometry/EulerAngles.h index 28135a954..97984d590 100644 --- a/Eigen/src/Geometry/EulerAngles.h +++ b/Eigen/src/Geometry/EulerAngles.h @@ -44,7 +44,6 @@ MatrixBase::eulerAngles(Index a0, Index a1, Index a2) const Matrix res; typedef Matrix Vector2; - const Scalar epsilon = NumTraits::dummy_precision(); const Index odd = ((a0+1)%3 == a1) ? 0 : 1; const Index i = a0; diff --git a/unsupported/test/kronecker_product.cpp b/unsupported/test/kronecker_product.cpp index 108bf6fde..8ddc6ec28 100644 --- a/unsupported/test/kronecker_product.cpp +++ b/unsupported/test/kronecker_product.cpp @@ -112,8 +112,8 @@ void test_kronecker_product() CALL_SUBTEST(check_kronecker_product(DM_fix_ab)); - for(unsigned int i=0;i Date: Sun, 23 Jun 2013 14:13:21 +0200 Subject: Fix bug #590: NEON Duplicate lane load --- Eigen/src/Core/arch/NEON/PacketMath.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/arch/NEON/PacketMath.h b/Eigen/src/Core/arch/NEON/PacketMath.h index 4c0702715..163bac215 100644 --- a/Eigen/src/Core/arch/NEON/PacketMath.h +++ b/Eigen/src/Core/arch/NEON/PacketMath.h @@ -191,15 +191,15 @@ template<> EIGEN_STRONG_INLINE Packet4i ploadu(const int* from) { EI template<> EIGEN_STRONG_INLINE Packet4f ploaddup(const float* from) { float32x2_t lo, hi; - lo = vdup_n_f32(*from); - hi = vdup_n_f32(*(from+1)); + lo = vld1_dup_f32(from); + hi = vld1_dup_f32(from+1); return vcombine_f32(lo, hi); } template<> EIGEN_STRONG_INLINE Packet4i ploaddup(const int* from) { int32x2_t lo, hi; - lo = vdup_n_s32(*from); - hi = vdup_n_s32(*(from+1)); + lo = vld1_dup_s32(from); + hi = vld1_dup_s32(from+1); return vcombine_s32(lo, hi); } -- cgit v1.2.3 From 8bbde351e7b88e690ca3d59616528511ff809101 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 24 Jun 2013 13:08:09 +0200 Subject: bug #620: fix robustness issue in JacobiSVD::solve (also fix a perf. issue) --- Eigen/src/SVD/JacobiSVD.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index c7a7eeda0..8e2f99b6b 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -850,17 +850,13 @@ struct solve_retval, Rhs> // A = U S V^* // So A^{-1} = V S^{-1} U^* + Matrix tmp; Index diagSize = (std::min)(dec().rows(), dec().cols()); - typename JacobiSVDType::SingularValuesType invertedSingVals(diagSize); - Index nonzeroSingVals = dec().nonzeroSingularValues(); - invertedSingVals.head(nonzeroSingVals) = dec().singularValues().head(nonzeroSingVals).array().inverse(); - invertedSingVals.tail(diagSize - nonzeroSingVals).setZero(); - - dst = dec().matrixV().leftCols(diagSize) - * invertedSingVals.asDiagonal() - * dec().matrixU().leftCols(diagSize).adjoint() - * rhs(); + + tmp.noalias() = dec().matrixU().leftCols(nonzeroSingVals).adjoint() * rhs(); + tmp = dec().singularValues().head(nonzeroSingVals).asDiagonal().inverse() * tmp; + dst = dec().matrixV().leftCols(nonzeroSingVals) * tmp; } }; } // end namespace internal -- cgit v1.2.3 From c21a04bcf978556555f874b780cae14dbdf4827f Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 24 Jun 2013 13:35:13 +0200 Subject: fix compilation of ArrayBase::transposeInPlace --- Eigen/src/Core/Transpose.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 95a7b95e5..aa197db0b 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -253,7 +253,7 @@ struct inplace_transpose_selector; template struct inplace_transpose_selector { // square matrix static void run(MatrixType& m) { - m.template triangularView().swap(m.transpose()); + m.matrix().template triangularView().swap(m.matrix().transpose()); } }; @@ -261,7 +261,7 @@ template struct inplace_transpose_selector { // non square matrix static void run(MatrixType& m) { if (m.rows()==m.cols()) - m.template triangularView().swap(m.transpose()); + m.matrix().template triangularView().swap(m.matrix().transpose()); else m = m.transpose().eval(); } -- cgit v1.2.3 From 1330ca611b7129df3c4de37a5faa08678b8f7453 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 24 Jun 2013 13:45:33 +0200 Subject: CwiseUnaryView should not inherit no_assignment_operator! --- Eigen/src/Core/CwiseUnaryView.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/CwiseUnaryView.h b/Eigen/src/Core/CwiseUnaryView.h index 9f9d4972d..b2638d326 100644 --- a/Eigen/src/Core/CwiseUnaryView.h +++ b/Eigen/src/Core/CwiseUnaryView.h @@ -56,8 +56,7 @@ template class CwiseUnaryViewImpl; template -class CwiseUnaryView : internal::no_assignment_operator, - public CwiseUnaryViewImpl::StorageKind> +class CwiseUnaryView : public CwiseUnaryViewImpl::StorageKind> { public: @@ -99,6 +98,7 @@ class CwiseUnaryViewImpl typedef typename internal::dense_xpr_base< CwiseUnaryView >::type Base; EIGEN_DENSE_PUBLIC_INTERFACE(Derived) + EIGEN_INHERIT_ASSIGNMENT_OPERATORS(CwiseUnaryViewImpl) inline Scalar* data() { return &coeffRef(0); } inline const Scalar* data() const { return &coeff(0); } -- cgit v1.2.3 From 4cc937794117a27c7a1d2643fdadd242dc83359a Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 24 Jun 2013 17:24:32 +0200 Subject: fix casting from double* to void* in SuperLU and Cholmod support --- Eigen/src/CholmodSupport/CholmodSupport.h | 7 ++++--- Eigen/src/SuperLUSupport/SuperLUSupport.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/CholmodSupport/CholmodSupport.h b/Eigen/src/CholmodSupport/CholmodSupport.h index d4008e63d..783324b0b 100644 --- a/Eigen/src/CholmodSupport/CholmodSupport.h +++ b/Eigen/src/CholmodSupport/CholmodSupport.h @@ -126,7 +126,7 @@ cholmod_dense viewAsCholmod(MatrixBase& mat) res.ncol = mat.cols(); res.nzmax = res.nrow * res.ncol; res.d = Derived::IsVectorAtCompileTime ? mat.derived().size() : mat.derived().outerStride(); - res.x = mat.derived().data(); + res.x = (void*)(mat.derived().data()); res.z = 0; internal::cholmod_configure_matrix(res); @@ -295,7 +295,8 @@ class CholmodBase : internal::noncopyable eigen_assert(size==b.rows()); // note: cd stands for Cholmod Dense - cholmod_dense b_cd = viewAsCholmod(b.const_cast_derived()); + Rhs& b_ref(b.const_cast_derived()); + cholmod_dense b_cd = viewAsCholmod(b_ref); cholmod_dense* x_cd = cholmod_solve(CHOLMOD_A, m_cholmodFactor, &b_cd, &m_cholmod); if(!x_cd) { @@ -345,7 +346,7 @@ class CholmodBase : internal::noncopyable } template - void dumpMemory(Stream& s) + void dumpMemory(Stream& /*s*/) {} protected: diff --git a/Eigen/src/SuperLUSupport/SuperLUSupport.h b/Eigen/src/SuperLUSupport/SuperLUSupport.h index 3034c7af5..bcb355760 100644 --- a/Eigen/src/SuperLUSupport/SuperLUSupport.h +++ b/Eigen/src/SuperLUSupport/SuperLUSupport.h @@ -160,7 +160,7 @@ struct SluMatrix : SuperMatrix res.ncol = mat.cols(); res.storage.lda = MatrixType::IsVectorAtCompileTime ? mat.size() : mat.outerStride(); - res.storage.values = mat.data(); + res.storage.values = (void*)(mat.data()); return res; } @@ -377,7 +377,7 @@ class SuperLUBase : internal::noncopyable } template - void dumpMemory(Stream& s) + void dumpMemory(Stream& /*s*/) {} protected: -- cgit v1.2.3 From 95f8a738ea23cf7d6f86ca99eddb5b22045c7f4b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 25 Jun 2013 11:42:04 +0200 Subject: Introduce a TEST_SET_BUT_UNUSED_VARIABLE macro for initialized but unused variables in the unit tests and also fix a few other warnings. --- Eigen/SPQRSupport | 2 +- Eigen/src/SVD/JacobiSVD.h | 1 - test/cholesky.cpp | 3 +-- test/determinant.cpp | 3 +-- test/eigensolver_complex.cpp | 3 +-- test/eigensolver_generalized_real.cpp | 3 +-- test/eigensolver_generic.cpp | 3 +-- test/eigensolver_selfadjoint.cpp | 3 +-- test/inverse.cpp | 3 +-- test/jacobisvd.cpp | 6 ++++-- test/main.h | 16 ++++++++++------ test/product_selfadjoint.cpp | 3 +-- test/product_trmv.cpp | 3 +-- test/real_qz.cpp | 3 +-- test/redux.cpp | 3 +-- test/selfadjoint.cpp | 3 +-- test/triangular.cpp | 4 ++-- 17 files changed, 29 insertions(+), 36 deletions(-) (limited to 'Eigen') diff --git a/Eigen/SPQRSupport b/Eigen/SPQRSupport index 213e0284c..77016442e 100644 --- a/Eigen/SPQRSupport +++ b/Eigen/SPQRSupport @@ -26,4 +26,4 @@ #include "src/CholmodSupport/CholmodSupport.h" #include "src/SPQRSupport/SuiteSparseQRSupport.h" -#endif \ No newline at end of file +#endif diff --git a/Eigen/src/SVD/JacobiSVD.h b/Eigen/src/SVD/JacobiSVD.h index 8e2f99b6b..4786768ff 100644 --- a/Eigen/src/SVD/JacobiSVD.h +++ b/Eigen/src/SVD/JacobiSVD.h @@ -851,7 +851,6 @@ struct solve_retval, Rhs> // So A^{-1} = V S^{-1} U^* Matrix tmp; - Index diagSize = (std::min)(dec().rows(), dec().cols()); Index nonzeroSingVals = dec().nonzeroSingularValues(); tmp.noalias() = dec().matrixU().leftCols(nonzeroSingVals).adjoint() * rhs(); diff --git a/test/cholesky.cpp b/test/cholesky.cpp index d084ec72c..38862924a 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -305,7 +305,6 @@ template void cholesky_verify_assert() void test_cholesky() { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( cholesky(Matrix()) ); CALL_SUBTEST_3( cholesky(Matrix2d()) ); @@ -328,5 +327,5 @@ void test_cholesky() CALL_SUBTEST_9( LLT(10) ); CALL_SUBTEST_9( LDLT(10) ); - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } diff --git a/test/determinant.cpp b/test/determinant.cpp index 81ab4b084..758f3afbb 100644 --- a/test/determinant.cpp +++ b/test/determinant.cpp @@ -55,7 +55,6 @@ void test_determinant() { for(int i = 0; i < g_repeat; i++) { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used CALL_SUBTEST_1( determinant(Matrix()) ); CALL_SUBTEST_2( determinant(Matrix()) ); CALL_SUBTEST_3( determinant(Matrix()) ); @@ -63,6 +62,6 @@ void test_determinant() CALL_SUBTEST_5( determinant(Matrix, 10, 10>()) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE/4); CALL_SUBTEST_6( determinant(MatrixXd(s, s)) ); - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } } diff --git a/test/eigensolver_complex.cpp b/test/eigensolver_complex.cpp index 9a52cfa5e..c9d8c0877 100644 --- a/test/eigensolver_complex.cpp +++ b/test/eigensolver_complex.cpp @@ -102,7 +102,6 @@ template void eigensolver_verify_assert(const MatrixType& m void test_eigensolver_complex() { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( eigensolver(Matrix4cf()) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE/4); @@ -119,5 +118,5 @@ void test_eigensolver_complex() // Test problem size constructors CALL_SUBTEST_5(ComplexEigenSolver tmp(s)); - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } diff --git a/test/eigensolver_generalized_real.cpp b/test/eigensolver_generalized_real.cpp index c4dc8a775..566a4bdc6 100644 --- a/test/eigensolver_generalized_real.cpp +++ b/test/eigensolver_generalized_real.cpp @@ -45,7 +45,6 @@ void test_eigensolver_generalized_real() { for(int i = 0; i < g_repeat; i++) { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used CALL_SUBTEST_1( generalized_eigensolver_real(Matrix4f()) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE/4); CALL_SUBTEST_2( generalized_eigensolver_real(MatrixXd(s,s)) ); @@ -55,6 +54,6 @@ void test_eigensolver_generalized_real() CALL_SUBTEST_2( generalized_eigensolver_real(MatrixXd(2,2)) ); CALL_SUBTEST_3( generalized_eigensolver_real(Matrix()) ); CALL_SUBTEST_4( generalized_eigensolver_real(Matrix2d()) ); - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } } diff --git a/test/eigensolver_generic.cpp b/test/eigensolver_generic.cpp index 0e1e508ae..005af81eb 100644 --- a/test/eigensolver_generic.cpp +++ b/test/eigensolver_generic.cpp @@ -89,7 +89,6 @@ template void eigensolver_verify_assert(const MatrixType& m void test_eigensolver_generic() { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( eigensolver(Matrix4f()) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE/4); @@ -122,5 +121,5 @@ void test_eigensolver_generic() } ); - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } diff --git a/test/eigensolver_selfadjoint.cpp b/test/eigensolver_selfadjoint.cpp index 67d4c543b..5c6ecd875 100644 --- a/test/eigensolver_selfadjoint.cpp +++ b/test/eigensolver_selfadjoint.cpp @@ -111,7 +111,6 @@ template void selfadjointeigensolver(const MatrixType& m) void test_eigensolver_selfadjoint() { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat; i++) { // very important to test 3x3 and 2x2 matrices since we provide special paths for them CALL_SUBTEST_1( selfadjointeigensolver(Matrix2d()) ); @@ -139,6 +138,6 @@ void test_eigensolver_selfadjoint() CALL_SUBTEST_8(SelfAdjointEigenSolver tmp1(s)); CALL_SUBTEST_8(Tridiagonalization tmp2(s)); - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } diff --git a/test/inverse.cpp b/test/inverse.cpp index 8dd35f6ac..8187b088d 100644 --- a/test/inverse.cpp +++ b/test/inverse.cpp @@ -87,7 +87,6 @@ template void inverse(const MatrixType& m) void test_inverse() { int s = 0; - s = s; // ICC shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( inverse(Matrix()) ); CALL_SUBTEST_2( inverse(Matrix2d()) ); @@ -101,5 +100,5 @@ void test_inverse() CALL_SUBTEST_7( inverse(Matrix4d()) ); CALL_SUBTEST_7( inverse(Matrix()) ); } - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } diff --git a/test/jacobisvd.cpp b/test/jacobisvd.cpp index 8fda8d261..76157c30f 100644 --- a/test/jacobisvd.cpp +++ b/test/jacobisvd.cpp @@ -324,8 +324,10 @@ void test_jacobisvd() int r = internal::random(1, 30), c = internal::random(1, 30); - r = r; // shuts down ICC's remark #593: variable "s" was set but never used - c = c; + + TEST_SET_BUT_UNUSED_VARIABLE(r) + TEST_SET_BUT_UNUSED_VARIABLE(c) + CALL_SUBTEST_7(( jacobisvd(MatrixXf(r,c)) )); CALL_SUBTEST_8(( jacobisvd(MatrixXcd(r,c)) )); (void) r; diff --git a/test/main.h b/test/main.h index 1094b6b36..0d65d64c1 100644 --- a/test/main.h +++ b/test/main.h @@ -31,6 +31,10 @@ // B0 is defined in POSIX header termios.h #define B0 FORBIDDEN_IDENTIFIER + +// shuts down ICC's remark #593: variable "XXX" was set but never used +#define TEST_SET_BUT_UNUSED_VARIABLE(X) X = X + 0; + // the following file is automatically generated by cmake #include "split_test_helper.h" @@ -380,13 +384,13 @@ template struct GetDifferentType > // Forward declaration to avoid ICC warning template std::string type_name(); -template std::string type_name() { return "other"; } -template<> std::string type_name() { return "float"; } -template<> std::string type_name() { return "double"; } -template<> std::string type_name() { return "int"; } -template<> std::string type_name >() { return "complex"; } +template std::string type_name() { return "other"; } +template<> std::string type_name() { return "float"; } +template<> std::string type_name() { return "double"; } +template<> std::string type_name() { return "int"; } +template<> std::string type_name >() { return "complex"; } template<> std::string type_name >() { return "complex"; } -template<> std::string type_name >() { return "complex"; } +template<> std::string type_name >() { return "complex"; } // forward declaration of the main test function void EIGEN_CAT(test_,EIGEN_TEST_FUNC)(); diff --git a/test/product_selfadjoint.cpp b/test/product_selfadjoint.cpp index e3e2b2cf1..374e2393b 100644 --- a/test/product_selfadjoint.cpp +++ b/test/product_selfadjoint.cpp @@ -63,7 +63,6 @@ template void product_selfadjoint(const MatrixType& m) void test_product_selfadjoint() { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat ; i++) { CALL_SUBTEST_1( product_selfadjoint(Matrix()) ); CALL_SUBTEST_2( product_selfadjoint(Matrix()) ); @@ -77,5 +76,5 @@ void test_product_selfadjoint() s = internal::random(1,EIGEN_TEST_MAX_SIZE); CALL_SUBTEST_7( product_selfadjoint(Matrix(s,s)) ); } - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } diff --git a/test/product_trmv.cpp b/test/product_trmv.cpp index 50a414b29..4c3c435c2 100644 --- a/test/product_trmv.cpp +++ b/test/product_trmv.cpp @@ -74,7 +74,6 @@ template void trmv(const MatrixType& m) void test_product_trmv() { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat ; i++) { CALL_SUBTEST_1( trmv(Matrix()) ); CALL_SUBTEST_2( trmv(Matrix()) ); @@ -86,5 +85,5 @@ void test_product_trmv() s = internal::random(1,EIGEN_TEST_MAX_SIZE); CALL_SUBTEST_6( trmv(Matrix(s, s)) ); } - EIGEN_UNUSED_VARIABLE(s); + TEST_SET_BUT_UNUSED_VARIABLE(s); } diff --git a/test/real_qz.cpp b/test/real_qz.cpp index ed11e17f3..7d743a734 100644 --- a/test/real_qz.cpp +++ b/test/real_qz.cpp @@ -49,7 +49,6 @@ template void real_qz(const MatrixType& m) void test_real_qz() { int s = 0; - s = s; // shuts down ICC's remark #593: variable "s" was set but never used for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( real_qz(Matrix4f()) ); s = internal::random(1,EIGEN_TEST_MAX_SIZE/4); @@ -62,5 +61,5 @@ void test_real_qz() CALL_SUBTEST_4( real_qz(Matrix2d()) ); } - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } diff --git a/test/redux.cpp b/test/redux.cpp index 26082527e..bb65f9461 100644 --- a/test/redux.cpp +++ b/test/redux.cpp @@ -133,8 +133,7 @@ void test_redux() { // the max size cannot be too large, otherwise reduxion operations obviously generate large errors. int maxsize = (std::min)(100,EIGEN_TEST_MAX_SIZE); - maxsize = maxsize; // shuts down ICC's remark #593: variable "s" was set but never used - EIGEN_UNUSED_VARIABLE(maxsize); + TEST_SET_BUT_UNUSED_VARIABLE(maxsize); for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1( matrixRedux(Matrix()) ); CALL_SUBTEST_1( matrixRedux(Array()) ); diff --git a/test/selfadjoint.cpp b/test/selfadjoint.cpp index ab8eb8173..76dab6d64 100644 --- a/test/selfadjoint.cpp +++ b/test/selfadjoint.cpp @@ -47,7 +47,6 @@ void test_selfadjoint() for(int i = 0; i < g_repeat ; i++) { int s = internal::random(1,EIGEN_TEST_MAX_SIZE); - s = s; // shuts down ICC's remark #593: variable "s" was set but never used CALL_SUBTEST_1( selfadjoint(Matrix()) ); CALL_SUBTEST_2( selfadjoint(Matrix()) ); @@ -55,7 +54,7 @@ void test_selfadjoint() CALL_SUBTEST_4( selfadjoint(MatrixXcd(s,s)) ); CALL_SUBTEST_5( selfadjoint(Matrix(s, s)) ); - EIGEN_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(s) } CALL_SUBTEST_1( bug_159() ); diff --git a/test/triangular.cpp b/test/triangular.cpp index 78b2c31f7..54320390b 100644 --- a/test/triangular.cpp +++ b/test/triangular.cpp @@ -211,8 +211,8 @@ void test_triangular() int maxsize = (std::min)(EIGEN_TEST_MAX_SIZE,20); for(int i = 0; i < g_repeat ; i++) { - int r = internal::random(2,maxsize); r=r; // shuts down ICC's remark #593: variable "s" was set but never used - int c = internal::random(2,maxsize); c=c; + int r = internal::random(2,maxsize); TEST_SET_BUT_UNUSED_VARIABLE(r) + int c = internal::random(2,maxsize); TEST_SET_BUT_UNUSED_VARIABLE(c) CALL_SUBTEST_1( triangular_square(Matrix()) ); CALL_SUBTEST_2( triangular_square(Matrix()) ); -- cgit v1.2.3 From 74beb218d25e155e074500739138e6bcface1474 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 26 Jun 2013 22:49:14 +0200 Subject: Fix bug #554: include unistd.h before checking the presence of posix_memalign. --- Eigen/src/Core/util/Memory.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/util/Memory.h b/Eigen/src/Core/util/Memory.h index 3ca666fd9..451535a0c 100644 --- a/Eigen/src/Core/util/Memory.h +++ b/Eigen/src/Core/util/Memory.h @@ -58,10 +58,17 @@ #endif -#if ((defined __QNXNTO__) || (defined _GNU_SOURCE) || ((defined _XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600))) \ - && (defined _POSIX_ADVISORY_INFO) && (_POSIX_ADVISORY_INFO > 0) - #define EIGEN_HAS_POSIX_MEMALIGN 1 -#else +// See bug 554 (http://eigen.tuxfamily.org/bz/show_bug.cgi?id=554) +// It seems to be unsafe to check _POSIX_ADVISORY_INFO without including unistd.h first. +// Currently, let's include it only on unix systems: +#if defined(__unix__) || defined(__unix) + #include + #if ((defined __QNXNTO__) || (defined _GNU_SOURCE) || ((defined _XOPEN_SOURCE) && (_XOPEN_SOURCE >= 600))) && (defined _POSIX_ADVISORY_INFO) && (_POSIX_ADVISORY_INFO > 0) + #define EIGEN_HAS_POSIX_MEMALIGN 1 + #endif +#endif + +#ifndef EIGEN_HAS_POSIX_MEMALIGN #define EIGEN_HAS_POSIX_MEMALIGN 0 #endif @@ -215,7 +222,7 @@ inline void* aligned_malloc(size_t size) if(posix_memalign(&result, 16, size)) result = 0; #elif EIGEN_HAS_MM_MALLOC result = _mm_malloc(size, 16); -#elif defined(_MSC_VER) && (!defined(_WIN32_WCE)) + #elif defined(_MSC_VER) && (!defined(_WIN32_WCE)) result = _aligned_malloc(size, 16); #else result = handmade_aligned_malloc(size); -- cgit v1.2.3 From 4cf742525f47129878fe561f56be9bd6ec83feb1 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 28 Jun 2013 15:56:43 +0200 Subject: bug #626: add compiletime check of the Options template parameter of SparseMatrix and SparseVector. Fix eval and plain_object for sparse objects. --- Eigen/src/SparseCore/SparseMatrix.h | 3 ++- Eigen/src/SparseCore/SparseUtil.h | 16 +++++++--------- Eigen/src/SparseCore/SparseVector.h | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 13 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index 072578132..fc6933a60 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -31,7 +31,7 @@ namespace Eigen { * * \tparam _Scalar the scalar type, i.e. the type of the coefficients * \tparam _Options Union of bit flags controlling the storage scheme. Currently the only possibility - * is RowMajor. The default is 0 which means column-major. + * is ColMajor or RowMajor. The default is 0 which means column-major. * \tparam _Index the type of the indices. It has to be a \b signed type (e.g., short, int, std::ptrdiff_t). Default is \c int. * * This class can be extended with the help of the plugin mechanism described on the page @@ -833,6 +833,7 @@ private: static void check_template_parameters() { EIGEN_STATIC_ASSERT(NumTraits::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE); + EIGEN_STATIC_ASSERT((Options&(ColMajor|RowMajor))==Options,INVALID_MATRIX_TEMPLATE_PARAMETERS); } struct default_prunning_func { diff --git a/Eigen/src/SparseCore/SparseUtil.h b/Eigen/src/SparseCore/SparseUtil.h index d58b51356..064a40707 100644 --- a/Eigen/src/SparseCore/SparseUtil.h +++ b/Eigen/src/SparseCore/SparseUtil.h @@ -98,16 +98,16 @@ template struct eval template struct sparse_eval { typedef typename traits::Scalar _Scalar; - enum { _Flags = traits::Flags| RowMajorBit }; + typedef typename traits::Index _Index; public: - typedef SparseVector<_Scalar, _Flags> type; + typedef SparseVector<_Scalar, RowMajor, _Index> type; }; template struct sparse_eval { typedef typename traits::Scalar _Scalar; - enum { _Flags = traits::Flags & (~RowMajorBit) }; + typedef typename traits::Index _Index; public: - typedef SparseVector<_Scalar, _Flags> type; + typedef SparseVector<_Scalar, ColMajor, _Index> type; }; template struct sparse_eval { @@ -127,12 +127,10 @@ template struct sparse_eval { template struct plain_matrix_type { typedef typename traits::Scalar _Scalar; - enum { - _Flags = traits::Flags - }; - + typedef typename traits::Index _Index; + enum { _Options = ((traits::Flags&RowMajorBit)==RowMajorBit) ? RowMajor : ColMajor }; public: - typedef SparseMatrix<_Scalar, _Flags> type; + typedef SparseMatrix<_Scalar, _Options, _Index> type; }; } // end namespace internal diff --git a/Eigen/src/SparseCore/SparseVector.h b/Eigen/src/SparseCore/SparseVector.h index cd1e76070..d29a0977c 100644 --- a/Eigen/src/SparseCore/SparseVector.h +++ b/Eigen/src/SparseCore/SparseVector.h @@ -184,22 +184,24 @@ class SparseVector void resizeNonZeros(Index size) { m_data.resize(size); } - inline SparseVector() : m_size(0) { resize(0); } + inline SparseVector() : m_size(0) { check_template_parameters(); resize(0); } - inline SparseVector(Index size) : m_size(0) { resize(size); } + inline SparseVector(Index size) : m_size(0) { check_template_parameters(); resize(size); } - inline SparseVector(Index rows, Index cols) : m_size(0) { resize(rows,cols); } + inline SparseVector(Index rows, Index cols) : m_size(0) { check_template_parameters(); resize(rows,cols); } template inline SparseVector(const SparseMatrixBase& other) : m_size(0) { + check_template_parameters(); *this = other.derived(); } inline SparseVector(const SparseVector& other) : SparseBase(other), m_size(0) { + check_template_parameters(); *this = other.derived(); } @@ -309,6 +311,13 @@ class SparseVector # endif protected: + + static void check_template_parameters() + { + EIGEN_STATIC_ASSERT(NumTraits::IsSigned,THE_INDEX_TYPE_MUST_BE_A_SIGNED_TYPE); + EIGEN_STATIC_ASSERT((_Options&(ColMajor|RowMajor))==Options,INVALID_MATRIX_TEMPLATE_PARAMETERS); + } + template EIGEN_DONT_INLINE SparseVector& assign(const SparseMatrixBase& _other); -- cgit v1.2.3 From a915f0292ee8a4db2731638376ed0a55ca6930e4 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 28 Jun 2013 16:16:02 +0200 Subject: Fix bug #626: add assertion on input ranges for coeff* and insert members for sparse objects --- Eigen/src/SparseCore/SparseMatrix.h | 10 +++++++++- Eigen/src/SparseCore/SparseVector.h | 15 ++++++++++++--- test/sparse_basic.cpp | 4 ++++ 3 files changed, 25 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index fc6933a60..5a3918e2d 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -170,6 +170,8 @@ class SparseMatrix * This function returns Scalar(0) if the element is an explicit \em zero */ inline Scalar coeff(Index row, Index col) const { + eigen_assert(row>=0 && row=0 && col=0 && row=0 && col=0 && row=0 && col inline void reserveInnerVectors(const SizesType& reserveSizes) { - if(isCompressed()) { std::size_t totalReserveSize = 0; @@ -929,7 +934,10 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa VectorXi wi(trMat.outerSize()); wi.setZero(); for(InputIterator it(begin); it!=end; ++it) + { + eigen_assert(it->row()>=0 && it->row()col()>=0 && it->col()col() : it->row())++; + } // pass 2: insert all the elements into trMat trMat.reserve(wi); diff --git a/Eigen/src/SparseCore/SparseVector.h b/Eigen/src/SparseCore/SparseVector.h index d29a0977c..b05d409c3 100644 --- a/Eigen/src/SparseCore/SparseVector.h +++ b/Eigen/src/SparseCore/SparseVector.h @@ -83,14 +83,18 @@ class SparseVector inline Scalar coeff(Index row, Index col) const { - eigen_assert((IsColVector ? col : row)==0); + eigen_assert(IsColVector ? (col==0 && row>=0 && row=0 && col=0 && i=0 && row=0 && col=0 && i=0 && row=0 && col=0 && i void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(m.row(r) + m.row(r), refMat.row(r) + refMat.row(r)); } */ + + // test assertion + VERIFY_RAISES_ASSERT( m.coeffRef(-1,1) = 0 ); + VERIFY_RAISES_ASSERT( m.coeffRef(0,m.cols()) = 0 ); } // test insert (inner random) -- cgit v1.2.3 From fc27cbd914b8afcf03b6120e3b23206bdc57b0a5 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 28 Jun 2013 17:10:53 +0200 Subject: Fix bug #611: fix const qualifier in cwiseProduct(sparse,dense) and SparseDiagonalProduct::InnerIterator --- Eigen/src/SparseCore/SparseDiagonalProduct.h | 16 ++++++++-------- Eigen/src/SparseCore/SparseMatrixBase.h | 4 ++-- test/sparse_product.cpp | 8 ++++++++ 3 files changed, 18 insertions(+), 10 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseDiagonalProduct.h b/Eigen/src/SparseCore/SparseDiagonalProduct.h index 5ec4018e6..3e314bcfc 100644 --- a/Eigen/src/SparseCore/SparseDiagonalProduct.h +++ b/Eigen/src/SparseCore/SparseDiagonalProduct.h @@ -118,13 +118,13 @@ class sparse_diagonal_product_inner_iterator_selector : public CwiseBinaryOp< scalar_product_op, - typename Rhs::ConstInnerVectorReturnType, - typename Lhs::DiagonalVectorType>::InnerIterator + const typename Rhs::ConstInnerVectorReturnType, + const typename Lhs::DiagonalVectorType>::InnerIterator { typedef typename CwiseBinaryOp< scalar_product_op, - typename Rhs::ConstInnerVectorReturnType, - typename Lhs::DiagonalVectorType>::InnerIterator Base; + const typename Rhs::ConstInnerVectorReturnType, + const typename Lhs::DiagonalVectorType>::InnerIterator Base; typedef typename Lhs::Index Index; Index m_outer; public: @@ -156,13 +156,13 @@ class sparse_diagonal_product_inner_iterator_selector : public CwiseBinaryOp< scalar_product_op, - typename Lhs::ConstInnerVectorReturnType, - Transpose >::InnerIterator + const typename Lhs::ConstInnerVectorReturnType, + const Transpose >::InnerIterator { typedef typename CwiseBinaryOp< scalar_product_op, - typename Lhs::ConstInnerVectorReturnType, - Transpose >::InnerIterator Base; + const typename Lhs::ConstInnerVectorReturnType, + const Transpose >::InnerIterator Base; typedef typename Lhs::Index Index; Index m_outer; public: diff --git a/Eigen/src/SparseCore/SparseMatrixBase.h b/Eigen/src/SparseCore/SparseMatrixBase.h index 6c73b7172..90fee01bc 100644 --- a/Eigen/src/SparseCore/SparseMatrixBase.h +++ b/Eigen/src/SparseCore/SparseMatrixBase.h @@ -322,8 +322,8 @@ template class SparseMatrixBase : public EigenBase typename internal::traits::Scalar \ >::ReturnType \ >, \ - Derived, \ - OtherDerived \ + const Derived, \ + const OtherDerived \ > template diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp index 67a59ecd8..338c3d378 100644 --- a/test/sparse_product.cpp +++ b/test/sparse_product.cpp @@ -153,6 +153,14 @@ template void sparse_product() VERIFY_IS_APPROX(m3=d2*m2, refM3=d2*refM2); VERIFY_IS_APPROX(m3=d1*m2.transpose(), refM3=d1*refM2.transpose()); + // also check with a SparseWrapper: + DenseVector v1 = DenseVector::Random(cols); + DenseVector v2 = DenseVector::Random(rows); + VERIFY_IS_APPROX(m3=m2*v1.asDiagonal(), refM3=refM2*v1.asDiagonal()); + VERIFY_IS_APPROX(m3=m2.transpose()*v2.asDiagonal(), refM3=refM2.transpose()*v2.asDiagonal()); + VERIFY_IS_APPROX(m3=v2.asDiagonal()*m2, refM3=v2.asDiagonal()*refM2); + VERIFY_IS_APPROX(m3=v1.asDiagonal()*m2.transpose(), refM3=v1.asDiagonal()*refM2.transpose()); + // evaluate to a dense matrix to check the .row() and .col() iterator functions VERIFY_IS_APPROX(d3=m2*d1, refM3=refM2*d1); VERIFY_IS_APPROX(d3=m2.transpose()*d2, refM3=refM2.transpose()*d2); -- cgit v1.2.3 From 9f035c876a9d84f32b39bacba179e9b2a542b57c Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Fri, 28 Jun 2013 22:27:45 +0200 Subject: Fiw bug #553: add support for sparse matrix time sparse self-adjoint view products --- Eigen/src/SparseCore/SparseSelfAdjointView.h | 16 ++++++++++++++++ test/sparse_product.cpp | 9 +++++++++ 2 files changed, 25 insertions(+) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseSelfAdjointView.h b/Eigen/src/SparseCore/SparseSelfAdjointView.h index d2e170410..1770f21e6 100644 --- a/Eigen/src/SparseCore/SparseSelfAdjointView.h +++ b/Eigen/src/SparseCore/SparseSelfAdjointView.h @@ -69,6 +69,22 @@ template class SparseSelfAdjointView const _MatrixTypeNested& matrix() const { return m_matrix; } _MatrixTypeNested& matrix() { return m_matrix.const_cast_derived(); } + /** Sparse self-adjoint matrix times sparse matrix product */ + template + SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor,Index>, OtherDerived> + operator*(const SparseMatrixBase& rhs) const + { + return SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor, Index>, OtherDerived>(*this, rhs.derived()); + } + + /**sparse matrix times Sparse self-adjoint matrix product */ + template friend + SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor,Index> > + operator*(const SparseMatrixBase& lhs, const SparseSelfAdjointView& rhs) + { + return SparseSparseProduct< OtherDerived, SparseMatrix::Flags&RowMajorBit) ? RowMajor : ColMajor, Index> >(lhs.derived(), rhs.derived()); + } + /** Efficient sparse self-adjoint matrix times dense vector/matrix product */ template SparseSelfAdjointTimeDenseProduct diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp index 338c3d378..51eed428b 100644 --- a/test/sparse_product.cpp +++ b/test/sparse_product.cpp @@ -201,7 +201,16 @@ template void sparse_product() 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); + + // sparse selfadjointView * sparse + SparseMatrixType mSres(rows,rows); + VERIFY_IS_APPROX(mSres = mLo.template selfadjointView()*mS, + refX = refLo.template selfadjointView()*refS); + // sparse * sparse selfadjointview + VERIFY_IS_APPROX(mSres = mS * mLo.template selfadjointView(), + refX = refS * refLo.template selfadjointView()); } + } // New test for Bug in SparseTimeDenseProduct -- cgit v1.2.3 From 99bef0957b218a493d8fc1649cf052677893f201 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 28 Jun 2013 22:56:26 +0200 Subject: Add missing sparse matrix constructor from sparse self-adjoint views, and add documentation for sparse time selfadjoint matrix --- Eigen/src/SparseCore/SparseMatrix.h | 9 +++++++++ Eigen/src/SparseCore/SparseSelfAdjointView.h | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index 5a3918e2d..2386dfecc 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -647,6 +647,15 @@ class SparseMatrix check_template_parameters(); *this = other.derived(); } + + /** Constructs a sparse matrix from the sparse selfadjoint view \a other */ + template + inline SparseMatrix(const SparseSelfAdjointView& other) + : m_outerSize(0), m_innerSize(0), m_outerIndex(0), m_innerNonZeros(0) + { + check_template_parameters(); + *this = other; + } /** Copy constructor (it performs a deep copy) */ inline SparseMatrix(const SparseMatrix& other) diff --git a/Eigen/src/SparseCore/SparseSelfAdjointView.h b/Eigen/src/SparseCore/SparseSelfAdjointView.h index 1770f21e6..60fcf3f40 100644 --- a/Eigen/src/SparseCore/SparseSelfAdjointView.h +++ b/Eigen/src/SparseCore/SparseSelfAdjointView.h @@ -69,7 +69,11 @@ template class SparseSelfAdjointView const _MatrixTypeNested& matrix() const { return m_matrix; } _MatrixTypeNested& matrix() { return m_matrix.const_cast_derived(); } - /** Sparse self-adjoint matrix times sparse matrix product */ + /** \returns an expression of the matrix product between a sparse self-adjoint matrix \c *this and a sparse matrix \a rhs. + * + * Note that there is no algorithmic advantage of performing such a product compared to a general sparse-sparse matrix product. + * Indeed, the SparseSelfadjointView operand is first copied into a temporary SparseMatrix before computing the product. + */ template SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor,Index>, OtherDerived> operator*(const SparseMatrixBase& rhs) const @@ -77,7 +81,11 @@ template class SparseSelfAdjointView return SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor, Index>, OtherDerived>(*this, rhs.derived()); } - /**sparse matrix times Sparse self-adjoint matrix product */ + /** \returns an expression of the matrix product between a sparse matrix \a lhs and a sparse self-adjoint matrix \a rhs. + * + * Note that there is no algorithmic advantage of performing such a product compared to a general sparse-sparse matrix product. + * Indeed, the SparseSelfadjointView operand is first copied into a temporary SparseMatrix before computing the product. + */ template friend SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor,Index> > operator*(const SparseMatrixBase& lhs, const SparseSelfAdjointView& rhs) -- cgit v1.2.3 From 22820e950e916917cebfc8aa1633162b847b53f7 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 1 Jul 2013 11:49:23 +0200 Subject: Improve BiCGSTAB robustness: fix a divide by zero and allow to restart with a new initial residual reference. --- Eigen/src/IterativeLinearSolvers/BiCGSTAB.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h b/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h index fbefb696f..048d59170 100644 --- a/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +++ b/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h @@ -43,8 +43,9 @@ bool bicgstab(const MatrixType& mat, const Rhs& rhs, Dest& x, VectorType r = rhs - mat * x; VectorType r0 = r; - RealScalar r0_sqnorm = rhs.squaredNorm(); - if(r0_sqnorm == 0) + RealScalar r0_sqnorm = r0.squaredNorm(); + RealScalar rhs_sqnorm = rhs.squaredNorm(); + if(rhs_sqnorm == 0) { x.setZero(); return true; @@ -61,13 +62,22 @@ bool bicgstab(const MatrixType& mat, const Rhs& rhs, Dest& x, RealScalar tol2 = tol*tol; int i = 0; + int restarts = 0; - while ( r.squaredNorm()/r0_sqnorm > tol2 && i tol2 && iRealScalar(0)) + w = t.dot(s) / t.squaredNorm(); x += alpha * y + w * z; r = s - w * t; ++i; } - tol_error = sqrt(r.squaredNorm()/r0_sqnorm); + tol_error = sqrt(r.squaredNorm()/rhs_sqnorm); iters = i; return true; } -- cgit v1.2.3 From 1caeb814f05b9477bcf385b31cc8f4cc95142bc2 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 2 Jul 2013 08:14:10 +0200 Subject: Fix bicgstab for complexes, and avoid a duplicate computation --- Eigen/src/IterativeLinearSolvers/BiCGSTAB.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h b/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h index 048d59170..6fc6ab852 100644 --- a/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h +++ b/Eigen/src/IterativeLinearSolvers/BiCGSTAB.h @@ -74,7 +74,7 @@ bool bicgstab(const MatrixType& mat, const Rhs& rhs, Dest& x, // The new residual vector became too orthogonal to the arbitrarily choosen direction r0 // Let's restart with a new r0: r0 = r; - r0_sqnorm = rho = r0.dot(r); + rho = r0_sqnorm = r.squaredNorm(); if(restarts++ == 0) i = 0; } @@ -91,9 +91,11 @@ bool bicgstab(const MatrixType& mat, const Rhs& rhs, Dest& x, z = precond.solve(s); t.noalias() = mat * z; - w = t.squaredNorm(); - if(w>RealScalar(0)) - w = t.dot(s) / t.squaredNorm(); + RealScalar tmp = t.squaredNorm(); + if(tmp>RealScalar(0)) + w = t.dot(s) / tmp; + else + w = Scalar(0); x += alpha * y + w * z; r = s - w * t; ++i; -- cgit v1.2.3 From 419b5cff44a6d2cdd3872a809f9dfdfa283f0dc3 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Tue, 2 Jul 2013 13:35:36 +0100 Subject: doc: Mention vec=vec.head(n) in aliasing page. --- Eigen/src/Core/Transpose.h | 2 +- doc/TopicAliasing.dox | 50 ++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 23 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index aa197db0b..798120bf4 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -388,7 +388,7 @@ struct checkTransposeAliasing_impl eigen_assert((!check_transpose_aliasing_run_time_selector ::IsTransposed,OtherDerived> ::run(extract_data(dst), other)) - && "aliasing detected during tranposition, use transposeInPlace() " + && "aliasing detected during transposition, use transposeInPlace() " "or evaluate the rhs into a temporary using .eval()"); } diff --git a/doc/TopicAliasing.dox b/doc/TopicAliasing.dox index bd1d329ce..c2654aed2 100644 --- a/doc/TopicAliasing.dox +++ b/doc/TopicAliasing.dox @@ -2,7 +2,7 @@ namespace Eigen { /** \eigenManualPage TopicAliasing Aliasing -In Eigen, aliasing refers to assignment statement in which the same matrix (or array or vector) appears on the +In %Eigen, aliasing refers to assignment statement in which the same matrix (or array or vector) appears on the left and on the right of the assignment operators. Statements like mat = 2 * mat; or mat = mat.transpose(); exhibit aliasing. The aliasing in the first example is harmless, but the aliasing in the second example leads to unexpected results. This page explains what aliasing is, when it is harmful, and what @@ -32,7 +32,7 @@ This assignment exhibits aliasing: the coefficient \c mat(1,1) appears both in t mat.bottomRightCorner(2,2) on the left-hand side of the assignment and the block mat.topLeftCorner(2,2) on the right-hand side. After the assignment, the (2,2) entry in the bottom right corner should have the value of \c mat(1,1) before the assignment, which is 5. However, the output shows -that \c mat(2,2) is actually 1. The problem is that Eigen uses lazy evaluation (see +that \c mat(2,2) is actually 1. The problem is that %Eigen uses lazy evaluation (see \ref TopicEigenExpressionTemplates) for mat.topLeftCorner(2,2). The result is similar to \code mat(1,1) = mat(0,0); @@ -43,10 +43,13 @@ mat(2,2) = mat(1,1); Thus, \c mat(2,2) is assigned the \e new value of \c mat(1,1) instead of the old value. The next section explains how to solve this problem by calling \link DenseBase::eval() eval()\endlink. -Note that if \c mat were a bigger, then the blocks would not overlap, and there would be no aliasing -problem. This means that in general aliasing cannot be detected at compile time. However, Eigen does detect -some instances of aliasing, albeit at run time. The following example exhibiting aliasing was mentioned in -\ref TutorialMatrixArithmetic : +Aliasing occurs more naturally when trying to shrink a matrix. For example, the expressions vec = +vec.head(n) and mat = mat.block(i,j,r,c) exhibit aliasing. + +In general, aliasing cannot be detected at compile time: if \c mat in the first example were a bit bigger, +then the blocks would not overlap, and there would be no aliasing problem. However, %Eigen does detect some +instances of aliasing, albeit at run time. The following example exhibiting aliasing was mentioned in \ref +TutorialMatrixArithmetic : @@ -57,24 +60,24 @@ some instances of aliasing, albeit at run time. The following example exhibitin \verbinclude tut_arithmetic_transpose_aliasing.out
ExampleOutput
-Again, the output shows the aliasing issue. However, by default Eigen uses a run-time assertion to detect this +Again, the output shows the aliasing issue. However, by default %Eigen uses a run-time assertion to detect this and exits with a message like \verbatim void Eigen::DenseBase::checkTransposeAliasing(const OtherDerived&) const [with OtherDerived = Eigen::Transpose >, Derived = Eigen::Matrix]: Assertion `(!internal::check_transpose_aliasing_selector::IsTransposed,OtherDerived>::run(internal::extract_data(derived()), other)) -&& "aliasing detected during tranposition, use transposeInPlace() or evaluate the rhs into a temporary using .eval()"' failed. +&& "aliasing detected during transposition, use transposeInPlace() or evaluate the rhs into a temporary using .eval()"' failed. \endverbatim -The user can turn Eigen's run-time assertions like the one to detect this aliasing problem off by defining the +The user can turn %Eigen's run-time assertions like the one to detect this aliasing problem off by defining the EIGEN_NO_DEBUG macro, and the above program was compiled with this macro turned off in order to illustrate the -aliasing problem. See \ref TopicAssertions for more information about Eigen's run-time assertions. +aliasing problem. See \ref TopicAssertions for more information about %Eigen's run-time assertions. \section TopicAliasingSolution Resolving aliasing issues -If you understand the cause of the aliasing issue, then it is obvious what must happen to solve it: Eigen has +If you understand the cause of the aliasing issue, then it is obvious what must happen to solve it: %Eigen has to evaluate the right-hand side fully into a temporary matrix/array and then assign it to the left-hand side. The function \link DenseBase::eval() eval() \endlink does precisely that. @@ -93,7 +96,7 @@ Now, \c mat(2,2) equals 5 after the assignment, as it should be. The same solution also works for the second example, with the transpose: simply replace the line a = a.transpose(); with a = a.transpose().eval();. However, in this common case there is a -better solution. Eigen provides the special-purpose function +better solution. %Eigen provides the special-purpose function \link DenseBase::transposeInPlace() transposeInPlace() \endlink which replaces a matrix by its transpose. This is shown below: @@ -107,7 +110,7 @@ This is shown below: If an xxxInPlace() function is available, then it is best to use it, because it indicates more clearly what you -are doing. This may also allow Eigen to optimize more aggressively. These are some of the xxxInPlace() +are doing. This may also allow %Eigen to optimize more aggressively. These are some of the xxxInPlace() functions provided: @@ -120,6 +123,9 @@ functions provided:
DenseBase::transpose() DenseBase::transposeInPlace()
+In the special case where a matrix or vector is shrunk using an expression like vec = vec.head(n), +you can use \link PlainObjectBase::conservativeResize() conservativeResize() \endlink. + \section TopicAliasingCwise Aliasing and component-wise operations @@ -128,8 +134,8 @@ right-hand side of an assignment operator, and it is then often necessary to eva explicitly. However, applying component-wise operations (such as matrix addition, scalar multiplication and array multiplication) is safe. -The following example has only component-wise operations. Thus, there is no need for .eval() even though -the same matrix appears on both sides of the assignments. +The following example has only component-wise operations. Thus, there is no need for \link DenseBase::eval() +eval() \endlink even though the same matrix appears on both sides of the assignments. @@ -147,8 +153,8 @@ not necessary to evaluate the right-hand side explicitly. \section TopicAliasingMatrixMult Aliasing and matrix multiplication -Matrix multiplication is the only operation in Eigen that assumes aliasing by default. Thus, if \c matA is a -matrix, then the statement matA = matA * matA; is safe. All other operations in Eigen assume that +Matrix multiplication is the only operation in %Eigen that assumes aliasing by default. Thus, if \c matA is a +matrix, then the statement matA = matA * matA; is safe. All other operations in %Eigen assume that there are no aliasing problems, either because the result is assigned to a different matrix or because it is a component-wise operation. @@ -161,14 +167,14 @@ component-wise operation. \verbinclude TopicAliasing_mult1.out
ExampleOutput
-However, this comes at a price. When executing the expression matA = matA * matA, Eigen evaluates the -product in a temporary matrix which is assigned to \c matA after the computation. This is fine. But Eigen does +However, this comes at a price. When executing the expression matA = matA * matA, %Eigen evaluates the +product in a temporary matrix which is assigned to \c matA after the computation. This is fine. But %Eigen does the same when the product is assigned to a different matrix (e.g., matB = matA * matA). In that case, it is more efficient to evaluate the product directly into \c matB instead of evaluating it first into a temporary matrix and copying that matrix to \c matB. The user can indicate with the \link MatrixBase::noalias() noalias()\endlink function that there is no -aliasing, as follows: matB.noalias() = matA * matA. This allows Eigen to evaluate the matrix product +aliasing, as follows: matB.noalias() = matA * matA. This allows %Eigen to evaluate the matrix product matA * matA directly into \c matB. @@ -199,9 +205,9 @@ Aliasing occurs when the same matrix or array coefficients appear both on the le an assignment operator. - Aliasing is harmless with coefficient-wise computations; this includes scalar multiplication and matrix or array addition. - - When you multiply two matrices, Eigen assumes that aliasing occurs. If you know that there is no aliasing, + - When you multiply two matrices, %Eigen assumes that aliasing occurs. If you know that there is no aliasing, then you can use \link MatrixBase::noalias() noalias()\endlink. - - In all other situations, Eigen assumes that there is no aliasing issue and thus gives the wrong result if + - In all other situations, %Eigen assumes that there is no aliasing issue and thus gives the wrong result if aliasing does in fact occur. To prevent this, you have to use \link DenseBase::eval() eval() \endlink or one of the xxxInPlace() functions. -- cgit v1.2.3 From 4e458d309c843dbeb91505a2c75f75494512ed47 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Tue, 2 Jul 2013 14:08:12 +0100 Subject: Fix some doxygen errors and warnings. --- Eigen/Sparse | 14 +++++++------- doc/A05_PortingFrom2To3.dox | 2 +- doc/Manual.dox | 2 ++ doc/TutorialSparse.dox | 4 ++-- doc/snippets/Cwise_asin.cpp | 2 ++ 5 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 doc/snippets/Cwise_asin.cpp (limited to 'Eigen') diff --git a/Eigen/Sparse b/Eigen/Sparse index 9d4da4c06..7cc9c0913 100644 --- a/Eigen/Sparse +++ b/Eigen/Sparse @@ -1,15 +1,15 @@ #ifndef EIGEN_SPARSE_MODULE_H #define EIGEN_SPARSE_MODULE_H -/** defgroup Sparse_modules Sparse modules +/** \defgroup Sparse_Module Sparse meta-module * * Meta-module including all related modules: - * - SparseCore - * - OrderingMethods - * - SparseCholesky - * - SparseLU - * - SparseQR - * - IterativeLinearSolvers + * - \ref SparseCore_Module + * - \ref OrderingMethods_Module + * - \ref SparseCholesky_Module + * - \ref SparseLU_Module + * - \ref SparseQR_Module + * - \ref IterativeLinearSolvers_Module * * \code * #include diff --git a/doc/A05_PortingFrom2To3.dox b/doc/A05_PortingFrom2To3.dox index 3750316c5..d885b4f6d 100644 --- a/doc/A05_PortingFrom2To3.dox +++ b/doc/A05_PortingFrom2To3.dox @@ -281,7 +281,7 @@ result = Vector4f::MapAligned(some_aligned_array); \section StdContainers STL Containers -In Eigen2, #include tweaked std::vector to automatically align elements. The problem was that that was quite invasive. In Eigen3, we only override standard behavior if you use Eigen::aligned_allocator as your allocator type. So for example, if you use std::vector, you need to do the following change (note that aligned_allocator is under namespace Eigen): +In Eigen2, #include tweaked std::vector to automatically align elements. The problem was that that was quite invasive. In Eigen3, we only override standard behavior if you use Eigen::aligned_allocator as your allocator type. So for example, if you use std::vector, you need to do the following change (note that aligned_allocator is under namespace Eigen):
diff --git a/doc/Manual.dox b/doc/Manual.dox index d6b9f7adf..3367982ca 100644 --- a/doc/Manual.dox +++ b/doc/Manual.dox @@ -135,6 +135,8 @@ namespace Eigen { \ingroup Sparse_Reference */ /** \addtogroup IterativeLinearSolvers_Module \ingroup Sparse_Reference */ +/** \addtogroup Sparse_Module + \ingroup Sparse_Reference */ /** \addtogroup Support_modules \ingroup Sparse_Reference */ diff --git a/doc/TutorialSparse.dox b/doc/TutorialSparse.dox index 065edbf69..41bae6b5c 100644 --- a/doc/TutorialSparse.dox +++ b/doc/TutorialSparse.dox @@ -2,7 +2,7 @@ namespace Eigen { /** \eigenManualPage TutorialSparse Sparse matrix manipulations -\eigeneigenAutoToc +\eigenAutoToc Manipulating and solving sparse problems involves various modules which are summarized below: @@ -14,7 +14,7 @@ Manipulating and solving sparse problems involves various modules which are summ - +
Eigen 2Eigen 3
%Sparse LU factorization to solve general square sparse systems
\link SparseQR_Module SparseQR \endlink\code #include\endcode %Sparse QR factorization for solving sparse linear least-squares problems
\link IterativeLinearSolvers_Module IterativeLinearSolvers \endlink\code#include \endcodeIterative solvers to solve large general linear square problems (including self-adjoint positive definite problems)
\link Sparse_modules Sparse \endlink\code#include \endcodeIncludes all the above modules
\link Sparse_Module Sparse \endlink\code#include \endcodeIncludes all the above modules
\section TutorialSparseIntro Sparse matrix format diff --git a/doc/snippets/Cwise_asin.cpp b/doc/snippets/Cwise_asin.cpp new file mode 100644 index 000000000..8dad838fd --- /dev/null +++ b/doc/snippets/Cwise_asin.cpp @@ -0,0 +1,2 @@ +Array3d v(0, sqrt(2.)/2, 1); +cout << v.asin() << endl; -- cgit v1.2.3 From 155fa0ca83715fca61c175251b0d7bef7344e8dc Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 3 Jul 2013 11:36:12 +0200 Subject: Add missing namespace prefix in pconj --- Eigen/src/Core/GenericPacketMath.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/GenericPacketMath.h b/Eigen/src/Core/GenericPacketMath.h index 64294420f..5f783ebee 100644 --- a/Eigen/src/Core/GenericPacketMath.h +++ b/Eigen/src/Core/GenericPacketMath.h @@ -106,7 +106,7 @@ pnegate(const Packet& a) { return -a; } /** \internal \returns conj(a) (coeff-wise) */ template inline Packet -pconj(const Packet& a) { return conj(a); } +pconj(const Packet& a) { return numext::conj(a); } /** \internal \returns a * b (coeff-wise) */ template inline Packet -- cgit v1.2.3 From edba612f68e6dd2d0e16d165c30d6c8338c4bb3a Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Thu, 4 Jul 2013 16:56:01 +0200 Subject: Fix unresolved typename bug for MSVC --- Eigen/src/SparseCore/SparseSelfAdjointView.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseSelfAdjointView.h b/Eigen/src/SparseCore/SparseSelfAdjointView.h index 60fcf3f40..d364c81df 100644 --- a/Eigen/src/SparseCore/SparseSelfAdjointView.h +++ b/Eigen/src/SparseCore/SparseSelfAdjointView.h @@ -75,7 +75,7 @@ template class SparseSelfAdjointView * Indeed, the SparseSelfadjointView operand is first copied into a temporary SparseMatrix before computing the product. */ template - SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor,Index>, OtherDerived> + SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor),Index>, OtherDerived> operator*(const SparseMatrixBase& rhs) const { return SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor, Index>, OtherDerived>(*this, rhs.derived()); @@ -87,7 +87,7 @@ template class SparseSelfAdjointView * Indeed, the SparseSelfadjointView operand is first copied into a temporary SparseMatrix before computing the product. */ template friend - SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor,Index> > + SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor),Index> > operator*(const SparseMatrixBase& lhs, const SparseSelfAdjointView& rhs) { return SparseSparseProduct< OtherDerived, SparseMatrix::Flags&RowMajorBit) ? RowMajor : ColMajor, Index> >(lhs.derived(), rhs.derived()); -- cgit v1.2.3 From 7d8823c8b7b637fcbf1f3356e2cdb8d5dc80c607 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 5 Jul 2013 09:14:32 +0200 Subject: Use true compile-time branching in SparseVector::assign to handle automatic transposition. --- Eigen/src/SparseCore/SparseSelfAdjointView.h | 2 +- Eigen/src/SparseCore/SparseVector.h | 54 +++++++++++++++------------- 2 files changed, 30 insertions(+), 26 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseSelfAdjointView.h b/Eigen/src/SparseCore/SparseSelfAdjointView.h index d364c81df..80e794411 100644 --- a/Eigen/src/SparseCore/SparseSelfAdjointView.h +++ b/Eigen/src/SparseCore/SparseSelfAdjointView.h @@ -86,7 +86,7 @@ template class SparseSelfAdjointView * Note that there is no algorithmic advantage of performing such a product compared to a general sparse-sparse matrix product. * Indeed, the SparseSelfadjointView operand is first copied into a temporary SparseMatrix before computing the product. */ - template friend + template friend SparseSparseProduct::Flags&RowMajorBit) ? RowMajor : ColMajor),Index> > operator*(const SparseMatrixBase& lhs, const SparseSelfAdjointView& rhs) { diff --git a/Eigen/src/SparseCore/SparseVector.h b/Eigen/src/SparseCore/SparseVector.h index b05d409c3..188d9e1f1 100644 --- a/Eigen/src/SparseCore/SparseVector.h +++ b/Eigen/src/SparseCore/SparseVector.h @@ -241,11 +241,11 @@ class SparseVector template inline SparseVector& operator=(const SparseMatrixBase& other) { - if ( (bool(OtherDerived::IsVectorAtCompileTime) && int(RowsAtCompileTime)!=int(OtherDerived::RowsAtCompileTime)) - || ((!bool(OtherDerived::IsVectorAtCompileTime)) && ( bool(IsColVector) ? other.cols()>1 : other.rows()>1 ))) - return assign(other.transpose()); + if ( (bool(OtherDerived::IsVectorAtCompileTime) && int(RowsAtCompileTime)!=int(OtherDerived::RowsAtCompileTime)) + || ((!bool(OtherDerived::IsVectorAtCompileTime)) && ( bool(IsColVector) ? other.cols()>1 : other.rows()>1 ))) + return assign(other.transpose(), typename internal::conditional<((Flags & RowMajorBit) == (OtherDerived::Flags & RowMajorBit)),internal::true_type,internal::false_type>::type()); else - return assign(other); + return assign(other, typename internal::conditional<((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)),internal::true_type,internal::false_type>::type()); } #ifndef EIGEN_PARSED_BY_DOXYGEN @@ -328,7 +328,10 @@ protected: } template - EIGEN_DONT_INLINE SparseVector& assign(const SparseMatrixBase& _other); + EIGEN_DONT_INLINE SparseVector& assign(const SparseMatrixBase& _other, internal::true_type); + + template + EIGEN_DONT_INLINE SparseVector& assign(const SparseMatrixBase& _other, internal::false_type); Storage m_data; Index m_size; @@ -400,31 +403,32 @@ class SparseVector::ReverseInnerIterator template template -EIGEN_DONT_INLINE SparseVector& SparseVector::assign(const SparseMatrixBase& _other) +EIGEN_DONT_INLINE SparseVector& SparseVector::assign(const SparseMatrixBase& _other, internal::true_type) { const OtherDerived& other(_other.derived()); - const bool needToTranspose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit); - if(needToTranspose) - { - Index size = other.size(); - Index nnz = other.nonZeros(); - resize(size); - reserve(nnz); - for(Index i=0; i +template +EIGEN_DONT_INLINE SparseVector& SparseVector::assign(const SparseMatrixBase& _other, internal::false_type) +{ + const OtherDerived& other(_other.derived()); + // there is no special optimization + return Base::operator=(other); +} + } // end namespace Eigen #endif // EIGEN_SPARSEVECTOR_H -- cgit v1.2.3 From 4f14b3fa726e25b14f1f06522353ee56707c2872 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 5 Jul 2013 22:42:46 +0200 Subject: Fix bug #611: diag * sparse * diag --- Eigen/src/SparseCore/SparseDiagonalProduct.h | 6 +++++- test/sparse_product.cpp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseDiagonalProduct.h b/Eigen/src/SparseCore/SparseDiagonalProduct.h index 3e314bcfc..1bb590e64 100644 --- a/Eigen/src/SparseCore/SparseDiagonalProduct.h +++ b/Eigen/src/SparseCore/SparseDiagonalProduct.h @@ -78,7 +78,11 @@ class SparseDiagonalProduct EIGEN_SPARSE_PUBLIC_INTERFACE(SparseDiagonalProduct) typedef internal::sparse_diagonal_product_inner_iterator_selector - <_LhsNested,_RhsNested,SparseDiagonalProduct,LhsMode,RhsMode> InnerIterator; + <_LhsNested,_RhsNested,SparseDiagonalProduct,LhsMode,RhsMode> InnerIterator; + + // We do not want ReverseInnerIterator for diagonal-sparse products, + // but this dummy declaration is needed to make diag * sparse * diag compile. + class ReverseInnerIterator; EIGEN_STRONG_INLINE SparseDiagonalProduct(const Lhs& lhs, const Rhs& rhs) : m_lhs(lhs), m_rhs(rhs) diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp index 51eed428b..664e33887 100644 --- a/test/sparse_product.cpp +++ b/test/sparse_product.cpp @@ -161,6 +161,8 @@ template void sparse_product() VERIFY_IS_APPROX(m3=v2.asDiagonal()*m2, refM3=v2.asDiagonal()*refM2); VERIFY_IS_APPROX(m3=v1.asDiagonal()*m2.transpose(), refM3=v1.asDiagonal()*refM2.transpose()); + VERIFY_IS_APPROX(m3=v2.asDiagonal()*m2*v1.asDiagonal(), refM3=v2.asDiagonal()*refM2*v1.asDiagonal()); + // evaluate to a dense matrix to check the .row() and .col() iterator functions VERIFY_IS_APPROX(d3=m2*d1, refM3=refM2*d1); VERIFY_IS_APPROX(d3=m2.transpose()*d2, refM3=refM2.transpose()*d2); -- cgit v1.2.3 From cc03c9d68354ea3fed03481de045c185ddc1fc49 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 5 Jul 2013 23:47:40 +0200 Subject: bug #556: workaround mingw bug with -O3 or -fipa-cp-clone --- Eigen/Core | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Eigen') diff --git a/Eigen/Core b/Eigen/Core index 7e068cbbd..97aa581e2 100644 --- a/Eigen/Core +++ b/Eigen/Core @@ -19,6 +19,12 @@ // defined e.g. EIGEN_DONT_ALIGN) so it needs to be done before we do anything with vectorization. #include "src/Core/util/Macros.h" +// Disable the ipa-cp-clone optimization flag with MinGW 6.x or newer (enabled by default with -O3) +// See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=556 for details. +#if defined(__MINGW32__) && EIGEN_GNUC_AT_LEAST(4,6) + #pragma GCC optimize ("-fno-ipa-cp-clone") +#endif + #include // this include file manages BLAS and MKL related macros -- cgit v1.2.3 From d0142e963bb6749373b1effeb59470b7163955b9 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 6 Jul 2013 17:33:49 +0200 Subject: Fix ambiguity from the origin of Index type in BlockImpl::InnerIterator --- Eigen/src/SparseCore/SparseBlock.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseBlock.h b/Eigen/src/SparseCore/SparseBlock.h index e025e4d40..0b3e193db 100644 --- a/Eigen/src/SparseCore/SparseBlock.h +++ b/Eigen/src/SparseCore/SparseBlock.h @@ -27,6 +27,7 @@ public: class InnerIterator: public XprType::InnerIterator { + typedef typename BlockImpl::Index Index; public: inline InnerIterator(const BlockType& xpr, Index outer) : XprType::InnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) @@ -38,6 +39,7 @@ public: }; class ReverseInnerIterator: public XprType::ReverseInnerIterator { + typedef typename BlockImpl::Index Index; public: inline ReverseInnerIterator(const BlockType& xpr, Index outer) : XprType::ReverseInnerIterator(xpr.m_matrix, xpr.m_outerStart + outer), m_outer(outer) -- cgit v1.2.3 From 3edd4681f2f04c1164cb3805f1ac37fbf9a618c0 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 6 Jul 2013 20:26:02 +0200 Subject: ReturnByValue should not be assignable! --- Eigen/src/Core/ReturnByValue.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/ReturnByValue.h b/Eigen/src/Core/ReturnByValue.h index 613912ffa..d66c24ba0 100644 --- a/Eigen/src/Core/ReturnByValue.h +++ b/Eigen/src/Core/ReturnByValue.h @@ -48,7 +48,7 @@ struct nested, n, PlainObject> } // end namespace internal template class ReturnByValue - : public internal::dense_xpr_base< ReturnByValue >::type + : internal::no_assignment_operator, public internal::dense_xpr_base< ReturnByValue >::type { public: typedef typename internal::traits::ReturnType ReturnType; -- cgit v1.2.3 From 4f28ccdd0e8456391dd503928d895d3ba68c5c22 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 6 Jul 2013 22:05:49 +0200 Subject: Rationalize the use of Index type in iterators --- Eigen/src/SparseCore/SparseCwiseBinaryOp.h | 2 +- Eigen/src/SparseCore/SparseDenseProduct.h | 1 + Eigen/src/SparseCore/SparseTranspose.h | 10 ++++++---- Eigen/src/SparseCore/SparseTriangularView.h | 2 ++ Eigen/src/SparseCore/SparseView.h | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h b/Eigen/src/SparseCore/SparseCwiseBinaryOp.h index 64b8c8547..ec86ca933 100644 --- a/Eigen/src/SparseCore/SparseCwiseBinaryOp.h +++ b/Eigen/src/SparseCore/SparseCwiseBinaryOp.h @@ -73,7 +73,7 @@ class CwiseBinaryOpImpl::InnerIterator typedef internal::sparse_cwise_binary_op_inner_iterator_selector< BinaryOp,Lhs,Rhs, InnerIterator> Base; - EIGEN_STRONG_INLINE InnerIterator(const CwiseBinaryOpImpl& binOp, typename CwiseBinaryOpImpl::Index outer) + EIGEN_STRONG_INLINE InnerIterator(const CwiseBinaryOpImpl& binOp, Index outer) : Base(binOp.derived(),outer) {} }; diff --git a/Eigen/src/SparseCore/SparseDenseProduct.h b/Eigen/src/SparseCore/SparseDenseProduct.h index 8c608a622..30975c29c 100644 --- a/Eigen/src/SparseCore/SparseDenseProduct.h +++ b/Eigen/src/SparseCore/SparseDenseProduct.h @@ -111,6 +111,7 @@ template class SparseDenseOuterProduct::InnerIterator : public _LhsNested::InnerIterator { typedef typename _LhsNested::InnerIterator Base; + typedef typename SparseDenseOuterProduct::Index Index; public: EIGEN_STRONG_INLINE InnerIterator(const SparseDenseOuterProduct& prod, Index outer) : Base(prod.lhs(), 0), m_outer(outer), m_factor(prod.rhs().coeff(outer)) diff --git a/Eigen/src/SparseCore/SparseTranspose.h b/Eigen/src/SparseCore/SparseTranspose.h index c78c20a2f..7c300ee8d 100644 --- a/Eigen/src/SparseCore/SparseTranspose.h +++ b/Eigen/src/SparseCore/SparseTranspose.h @@ -34,26 +34,28 @@ template class TransposeImpl::InnerItera : public _MatrixTypeNested::InnerIterator { typedef typename _MatrixTypeNested::InnerIterator Base; + typedef typename TransposeImpl::Index Index; public: EIGEN_STRONG_INLINE InnerIterator(const TransposeImpl& trans, typename TransposeImpl::Index outer) : Base(trans.derived().nestedExpression(), outer) {} - inline typename TransposeImpl::Index row() const { return Base::col(); } - inline typename TransposeImpl::Index col() const { return Base::row(); } + Index row() const { return Base::col(); } + Index col() const { return Base::row(); } }; template class TransposeImpl::ReverseInnerIterator : public _MatrixTypeNested::ReverseInnerIterator { typedef typename _MatrixTypeNested::ReverseInnerIterator Base; + typedef typename TransposeImpl::Index Index; public: EIGEN_STRONG_INLINE ReverseInnerIterator(const TransposeImpl& xpr, typename TransposeImpl::Index outer) : Base(xpr.derived().nestedExpression(), outer) {} - inline typename TransposeImpl::Index row() const { return Base::col(); } - inline typename TransposeImpl::Index col() const { return Base::row(); } + Index row() const { return Base::col(); } + Index col() const { return Base::row(); } }; } // end namespace Eigen diff --git a/Eigen/src/SparseCore/SparseTriangularView.h b/Eigen/src/SparseCore/SparseTriangularView.h index 88a345b22..333127b78 100644 --- a/Eigen/src/SparseCore/SparseTriangularView.h +++ b/Eigen/src/SparseCore/SparseTriangularView.h @@ -66,6 +66,7 @@ template class SparseTriangularView::InnerIterator : public MatrixTypeNestedCleaned::InnerIterator { typedef typename MatrixTypeNestedCleaned::InnerIterator Base; + typedef typename SparseTriangularView::Index Index; public: EIGEN_STRONG_INLINE InnerIterator(const SparseTriangularView& view, Index outer) @@ -135,6 +136,7 @@ template class SparseTriangularView::ReverseInnerIterator : public MatrixTypeNestedCleaned::ReverseInnerIterator { typedef typename MatrixTypeNestedCleaned::ReverseInnerIterator Base; + typedef typename SparseTriangularView::Index Index; public: EIGEN_STRONG_INLINE ReverseInnerIterator(const SparseTriangularView& view, Index outer) diff --git a/Eigen/src/SparseCore/SparseView.h b/Eigen/src/SparseCore/SparseView.h index 67eb93245..fd8450463 100644 --- a/Eigen/src/SparseCore/SparseView.h +++ b/Eigen/src/SparseCore/SparseView.h @@ -56,6 +56,7 @@ protected: template class SparseView::InnerIterator : public _MatrixTypeNested::InnerIterator { + typedef typename SparseView::Index Index; public: typedef typename _MatrixTypeNested::InnerIterator IterBase; InnerIterator(const SparseView& view, Index outer) : -- cgit v1.2.3 From 5a4519d2b4a816fd82be77e9aa1b2498af62375c Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 10 Jul 2013 21:11:41 +0200 Subject: Revisit the implementation of random_default_impl for integer to make sure avoid overflows and compiler warnings. --- Eigen/src/Core/MathFunctions.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 5df2d8bca..2bfc5ebd9 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -510,11 +510,10 @@ struct random_default_impl #else enum { rand_bits = floor_log2<(unsigned int)(RAND_MAX)+1>::value, scalar_bits = sizeof(Scalar) * CHAR_BIT, - shift = EIGEN_PLAIN_ENUM_MAX(0, int(rand_bits) - int(scalar_bits)) + shift = EIGEN_PLAIN_ENUM_MAX(0, int(rand_bits) - int(scalar_bits)), + offset = NumTraits::IsSigned ? (1 << (EIGEN_PLAIN_ENUM_MIN(rand_bits,scalar_bits)-1)) : 0 }; - Scalar x = Scalar(std::rand() >> shift); - Scalar offset = NumTraits::IsSigned ? Scalar(1 << (rand_bits-1)) : Scalar(0); - return x - offset; + return Scalar((std::rand() >> shift) - offset); #endif } }; -- cgit v1.2.3 From 6d1f5dbaaefcb9cc198aad362146131f8eec9cd7 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 10 Jul 2013 23:48:26 +0200 Subject: Add no_assignment_operator to a few classes that must not be assigned, and fix a couple of warnings. --- Eigen/src/Geometry/Homogeneous.h | 2 +- Eigen/src/SparseLU/SparseLU.h | 7 +-- Eigen/src/SparseLU/SparseLU_Memory.h | 6 +-- Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h | 29 +++++----- Eigen/src/SparseLU/SparseLU_column_dfs.h | 2 +- test/cholesky.cpp | 1 + test/geo_eulerangles.cpp | 8 +-- test/mapstride.cpp | 4 +- test/redux.cpp | 2 +- test/sizeof.cpp | 2 +- test/sparse.h | 16 +++--- test/sparse_basic.cpp | 63 +++++++++++----------- .../src/LevenbergMarquardt/LevenbergMarquardt.h | 2 +- 13 files changed, 75 insertions(+), 69 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Geometry/Homogeneous.h b/Eigen/src/Geometry/Homogeneous.h index df03feb55..00e71d190 100644 --- a/Eigen/src/Geometry/Homogeneous.h +++ b/Eigen/src/Geometry/Homogeneous.h @@ -59,7 +59,7 @@ template struct homogeneous_right_product_impl } // end namespace internal template class Homogeneous - : public MatrixBase > + : internal::no_assignment_operator, public MatrixBase > { public: diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index ee79c7762..dda79e5d2 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -511,7 +511,7 @@ void SparseLU::factorize(const MatrixType& matrix) m_perm_r.resize(m); m_perm_r.indices().setConstant(-1); marker.setConstant(-1); - m_detPermR = 1.0; // Record the determinant of the row permutation + m_detPermR = 1; // Record the determinant of the row permutation m_glu.supno(0) = emptyIdxLU; m_glu.xsup.setConstant(0); m_glu.xsup(0) = m_glu.xlsub(0) = m_glu.xusub(0) = m_glu.xlusup(0) = Index(0); @@ -630,7 +630,7 @@ void SparseLU::factorize(const MatrixType& matrix) } template -struct SparseLUMatrixLReturnType +struct SparseLUMatrixLReturnType : internal::no_assignment_operator { typedef typename MappedSupernodalType::Index Index; typedef typename MappedSupernodalType::Scalar Scalar; @@ -647,7 +647,7 @@ struct SparseLUMatrixLReturnType }; template -struct SparseLUMatrixUReturnType +struct SparseLUMatrixUReturnType : internal::no_assignment_operator { typedef typename MatrixLType::Index Index; typedef typename MatrixLType::Scalar Scalar; @@ -700,6 +700,7 @@ struct SparseLUMatrixUReturnType const MatrixLType& m_mapL; const MatrixUType& m_mapU; }; + namespace internal { template diff --git a/Eigen/src/SparseLU/SparseLU_Memory.h b/Eigen/src/SparseLU/SparseLU_Memory.h index 6d9570d19..a5158025c 100644 --- a/Eigen/src/SparseLU/SparseLU_Memory.h +++ b/Eigen/src/SparseLU/SparseLU_Memory.h @@ -70,7 +70,7 @@ Index SparseLUImpl::expand(VectorType& vec, Index& length, Index if(num_expansions == 0 || keep_prev) new_len = length ; // First time allocate requested else - new_len = alpha * length ; + new_len = Index(alpha * length); VectorType old_vec; // Temporary vector to hold the previous values if (nbElts > 0 ) @@ -100,7 +100,7 @@ Index SparseLUImpl::expand(VectorType& vec, Index& length, Index do { alpha = (alpha + 1)/2; - new_len = alpha * length ; + new_len = Index(alpha * length); try { vec.resize(new_len); @@ -141,7 +141,7 @@ Index SparseLUImpl::memInit(Index m, Index n, Index annz, Index lw Index& num_expansions = glu.num_expansions; //No memory expansions so far num_expansions = 0; glu.nzumax = glu.nzlumax = (std::max)(fillratio * annz, m*n); // estimated number of nonzeros in U - glu.nzlmax = (std::max)(1., fillratio/4.) * annz; // estimated nnz in L factor + glu.nzlmax = (std::max)(Index(4), fillratio) * annz / 4; // estimated nnz in L factor // Return the estimated size to the user if necessary Index tempSpace; diff --git a/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h b/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h index 3836d1096..ad6f2183f 100644 --- a/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h +++ b/Eigen/src/SparseLU/SparseLU_SupernodalMatrix.h @@ -216,13 +216,13 @@ class MappedSuperNodalMatrix::InnerIterator protected: const MappedSuperNodalMatrix& m_matrix; // Supernodal lower triangular matrix - const Index m_outer; // Current column - const Index m_supno; // Current SuperNode number - Index m_idval; //Index to browse the values in the current column - const Index m_startidval; // Start of the column value - const Index m_endidval; // End of the column value - Index m_idrow; //Index to browse the row indices - Index m_endidrow; // End index of row indices of the current column + const Index m_outer; // Current column + const Index m_supno; // Current SuperNode number + Index m_idval; // Index to browse the values in the current column + const Index m_startidval; // Start of the column value + const Index m_endidval; // End of the column value + Index m_idrow; // Index to browse the row indices + Index m_endidrow; // End index of row indices of the current column }; /** @@ -235,17 +235,17 @@ void MappedSuperNodalMatrix::solveInPlace( MatrixBase&X) con { Index n = X.rows(); Index nrhs = X.cols(); - const Scalar * Lval = valuePtr(); // Nonzero values - Matrix work(n, nrhs); // working vector + const Scalar * Lval = valuePtr(); // Nonzero values + Matrix work(n, nrhs); // working vector work.setZero(); for (Index k = 0; k <= nsuper(); k ++) { - Index fsupc = supToCol()[k]; // First column of the current supernode - Index istart = rowIndexPtr()[fsupc]; // Pointer index to the subscript of the current column + Index fsupc = supToCol()[k]; // First column of the current supernode + Index istart = rowIndexPtr()[fsupc]; // Pointer index to the subscript of the current column Index nsupr = rowIndexPtr()[fsupc+1] - istart; // Number of rows in the current supernode - Index nsupc = supToCol()[k+1] - fsupc; // Number of columns in the current supernode - Index nrow = nsupr - nsupc; // Number of rows in the non-diagonal part of the supernode - Index irow; //Current index row + Index nsupc = supToCol()[k+1] - fsupc; // Number of columns in the current supernode + Index nrow = nsupr - nsupc; // Number of rows in the non-diagonal part of the supernode + Index irow; //Current index row if (nsupc == 1 ) { @@ -294,4 +294,5 @@ void MappedSuperNodalMatrix::solveInPlace( MatrixBase&X) con } // end namespace internal } // end namespace Eigen + #endif // EIGEN_SPARSELU_MATRIX_H diff --git a/Eigen/src/SparseLU/SparseLU_column_dfs.h b/Eigen/src/SparseLU/SparseLU_column_dfs.h index bc4cfbf37..4c04b0e44 100644 --- a/Eigen/src/SparseLU/SparseLU_column_dfs.h +++ b/Eigen/src/SparseLU/SparseLU_column_dfs.h @@ -36,7 +36,7 @@ namespace Eigen { namespace internal { template -struct column_dfs_traits +struct column_dfs_traits : no_assignment_operator { typedef typename ScalarVector::Scalar Scalar; typedef typename IndexVector::Scalar Index; diff --git a/test/cholesky.cpp b/test/cholesky.cpp index 38862924a..378525a83 100644 --- a/test/cholesky.cpp +++ b/test/cholesky.cpp @@ -328,4 +328,5 @@ void test_cholesky() CALL_SUBTEST_9( LDLT(10) ); TEST_SET_BUT_UNUSED_VARIABLE(s) + TEST_SET_BUT_UNUSED_VARIABLE(nb_temporaries) } diff --git a/test/geo_eulerangles.cpp b/test/geo_eulerangles.cpp index 26456beee..4361625e3 100644 --- a/test/geo_eulerangles.cpp +++ b/test/geo_eulerangles.cpp @@ -41,7 +41,7 @@ template void check_all_var(const Matrix& ea) VERIFY_EULER(2,1,2, Z,Y,Z); } -template void eulerangles(void) +template void eulerangles() { typedef Matrix Matrix3; typedef Matrix Vector3; @@ -60,13 +60,13 @@ template void eulerangles(void) ea = m.eulerAngles(0,1,0); check_all_var(ea); - ea = (Array3::Random() + Array3(1,1,0))*M_PI*Array3(0.5,0.5,1); + ea = (Array3::Random() + Array3(1,1,0))*Scalar(M_PI)*Array3(0.5,0.5,1); check_all_var(ea); - ea[2] = ea[0] = internal::random(0,M_PI); + ea[2] = ea[0] = internal::random(0,Scalar(M_PI)); check_all_var(ea); - ea[0] = ea[1] = internal::random(0,M_PI); + ea[0] = ea[1] = internal::random(0,Scalar(M_PI)); check_all_var(ea); ea[1] = 0; diff --git a/test/mapstride.cpp b/test/mapstride.cpp index fe35b9d23..b1dc9de2a 100644 --- a/test/mapstride.cpp +++ b/test/mapstride.cpp @@ -116,7 +116,7 @@ template void map_class_matrix(const MatrixTy void test_mapstride() { for(int i = 0; i < g_repeat; i++) { - EIGEN_UNUSED int maxn = 30; + int maxn = 30; CALL_SUBTEST_1( map_class_vector(Matrix()) ); CALL_SUBTEST_1( map_class_vector(Matrix()) ); CALL_SUBTEST_2( map_class_vector(Vector4d()) ); @@ -142,5 +142,7 @@ void test_mapstride() CALL_SUBTEST_5( map_class_matrix(MatrixXi(internal::random(1,maxn),internal::random(1,maxn))) ); CALL_SUBTEST_6( map_class_matrix(MatrixXcd(internal::random(1,maxn),internal::random(1,maxn))) ); CALL_SUBTEST_6( map_class_matrix(MatrixXcd(internal::random(1,maxn),internal::random(1,maxn))) ); + + TEST_SET_BUT_UNUSED_VARIABLE(maxn); } } diff --git a/test/redux.cpp b/test/redux.cpp index bb65f9461..0d176e500 100644 --- a/test/redux.cpp +++ b/test/redux.cpp @@ -22,7 +22,7 @@ template void matrixRedux(const MatrixType& m) // The entries of m1 are uniformly distributed in [0,1], so m1.prod() is very small. This may lead to test // failures if we underflow into denormals. Thus, we scale so that entires are close to 1. - MatrixType m1_for_prod = MatrixType::Ones(rows, cols) + Scalar(0.2) * m1; + MatrixType m1_for_prod = MatrixType::Ones(rows, cols) + RealScalar(0.2) * m1; VERIFY_IS_MUCH_SMALLER_THAN(MatrixType::Zero(rows, cols).sum(), Scalar(1)); VERIFY_IS_APPROX(MatrixType::Ones(rows, cols).sum(), Scalar(float(rows*cols))); // the float() here to shut up excessive MSVC warning about int->complex conversion being lossy diff --git a/test/sizeof.cpp b/test/sizeof.cpp index 68463c9b6..c454780a6 100644 --- a/test/sizeof.cpp +++ b/test/sizeof.cpp @@ -13,7 +13,7 @@ template void verifySizeOf(const MatrixType&) { typedef typename MatrixType::Scalar Scalar; if (MatrixType::RowsAtCompileTime!=Dynamic && MatrixType::ColsAtCompileTime!=Dynamic) - VERIFY(sizeof(MatrixType)==sizeof(Scalar)*size_t(MatrixType::SizeAtCompileTime)); + VERIFY(sizeof(MatrixType)==sizeof(Scalar)*std::ptrdiff_t(MatrixType::SizeAtCompileTime)); else VERIFY(sizeof(MatrixType)==sizeof(Scalar*) + 2 * sizeof(typename MatrixType::Index)); } diff --git a/test/sparse.h b/test/sparse.h index 7e2b98494..1a5ceb38d 100644 --- a/test/sparse.h +++ b/test/sparse.h @@ -58,8 +58,8 @@ initSparse(double density, Matrix& refMat, SparseMatrix& sparseMat, int flags = 0, - std::vector* zeroCoords = 0, - std::vector* nonzeroCoords = 0) + std::vector >* zeroCoords = 0, + std::vector >* nonzeroCoords = 0) { enum { IsRowMajor = SparseMatrix::IsRowMajor }; sparseMat.setZero(); @@ -93,11 +93,11 @@ initSparse(double density, //sparseMat.insertBackByOuterInner(j,i) = v; sparseMat.insertByOuterInner(j,i) = v; if (nonzeroCoords) - nonzeroCoords->push_back(Vector2i(ai,aj)); + nonzeroCoords->push_back(Matrix (ai,aj)); } else if (zeroCoords) { - zeroCoords->push_back(Vector2i(ai,aj)); + zeroCoords->push_back(Matrix (ai,aj)); } refMat(ai,aj) = v; } @@ -110,8 +110,8 @@ initSparse(double density, Matrix& refMat, DynamicSparseMatrix& sparseMat, int flags = 0, - std::vector* zeroCoords = 0, - std::vector* nonzeroCoords = 0) + std::vector >* zeroCoords = 0, + std::vector >* nonzeroCoords = 0) { enum { IsRowMajor = DynamicSparseMatrix::IsRowMajor }; sparseMat.setZero(); @@ -142,11 +142,11 @@ initSparse(double density, { sparseMat.insertBackByOuterInner(j,i) = v; if (nonzeroCoords) - nonzeroCoords->push_back(Vector2i(ai,aj)); + nonzeroCoords->push_back(Matrix (ai,aj)); } else if (zeroCoords) { - zeroCoords->push_back(Vector2i(ai,aj)); + zeroCoords->push_back(Matrix (ai,aj)); } refMat(ai,aj) = v; } diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 8fc1904b1..d466b51da 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -14,7 +14,8 @@ template void sparse_basic(const SparseMatrixType& ref) { typedef typename SparseMatrixType::Index Index; - + typedef Matrix Vector2; + const Index rows = ref.rows(); const Index cols = ref.cols(); typedef typename SparseMatrixType::Scalar Scalar; @@ -31,8 +32,8 @@ template void sparse_basic(const SparseMatrixType& re DenseMatrix refMat = DenseMatrix::Zero(rows, cols); DenseVector vec1 = DenseVector::Random(rows); - std::vector zeroCoords; - std::vector nonzeroCoords; + std::vector zeroCoords; + std::vector nonzeroCoords; initSparse(density, refMat, m, 0, &zeroCoords, &nonzeroCoords); if (zeroCoords.size()==0 || nonzeroCoords.size()==0) @@ -104,11 +105,11 @@ template void sparse_basic(const SparseMatrixType& re SparseMatrixType m2(rows,cols); if(internal::random()%2) m2.reserve(VectorXi::Constant(m2.outerSize(), 2)); - for (int j=0; j(0,rows-1); + Index i = internal::random(0,rows-1); if (m1.coeff(i,j)==Scalar(0)) m2.insert(i,j) = m1(i,j) = internal::random(); } @@ -126,8 +127,8 @@ template void sparse_basic(const SparseMatrixType& re m2.reserve(VectorXi::Constant(m2.outerSize(), 2)); for (int k=0; k(0,rows-1); - int j = internal::random(0,cols-1); + Index i = internal::random(0,rows-1); + Index j = internal::random(0,cols-1); if ((m1.coeff(i,j)==Scalar(0)) && (internal::random()%2)) m2.insert(i,j) = m1(i,j) = internal::random(); else @@ -150,8 +151,8 @@ template void sparse_basic(const SparseMatrixType& re m2.reserve(r); for (int k=0; k(0,rows-1); - int j = internal::random(0,cols-1); + Index i = internal::random(0,rows-1); + Index j = internal::random(0,cols-1); if (m1.coeff(i,j)==Scalar(0)) m2.insert(i,j) = m1(i,j) = internal::random(); if(mode==3) @@ -167,8 +168,8 @@ template void sparse_basic(const SparseMatrixType& re DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); initSparse(density, refMat2, m2); - int j0 = internal::random(0,rows-1); - int j1 = internal::random(0,rows-1); + Index j0 = internal::random(0,rows-1); + Index j1 = internal::random(0,rows-1); if(SparseMatrixType::IsRowMajor) VERIFY_IS_APPROX(m2.innerVector(j0), refMat2.row(j0)); else @@ -181,17 +182,17 @@ template void sparse_basic(const SparseMatrixType& re SparseMatrixType m3(rows,rows); m3.reserve(VectorXi::Constant(rows,rows/2)); - for(int j=0; j0) VERIFY(j==numext::real(m3.innerVector(j).lastCoeff())); } m3.makeCompressed(); - for(int j=0; j0) @@ -210,9 +211,9 @@ template void sparse_basic(const SparseMatrixType& re initSparse(density, refMat2, m2); if(internal::random(0,1)>0.5) m2.makeCompressed(); - int j0 = internal::random(0,rows-2); - int j1 = internal::random(0,rows-2); - int n0 = internal::random(1,rows-(std::max)(j0,j1)); + Index j0 = internal::random(0,rows-2); + Index j1 = internal::random(0,rows-2); + Index n0 = internal::random(1,rows-(std::max)(j0,j1)); if(SparseMatrixType::IsRowMajor) VERIFY_IS_APPROX(m2.innerVectors(j0,n0), refMat2.block(j0,0,n0,cols)); else @@ -300,9 +301,9 @@ template void sparse_basic(const SparseMatrixType& re DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); initSparse(density, refMat2, m2); - int j0 = internal::random(0,rows-2); - int j1 = internal::random(0,rows-2); - int n0 = internal::random(1,rows-(std::max)(j0,j1)); + Index j0 = internal::random(0,rows-2); + Index j1 = internal::random(0,rows-2); + Index n0 = internal::random(1,rows-(std::max)(j0,j1)); if(SparseMatrixType::IsRowMajor) VERIFY_IS_APPROX(m2.block(j0,0,n0,cols), refMat2.block(j0,0,n0,cols)); else @@ -315,7 +316,7 @@ template void sparse_basic(const SparseMatrixType& re VERIFY_IS_APPROX(m2.block(0,j0,rows,n0)+m2.block(0,j1,rows,n0), refMat2.block(0,j0,rows,n0)+refMat2.block(0,j1,rows,n0)); - int i = internal::random(0,m2.outerSize()-1); + Index i = internal::random(0,m2.outerSize()-1); if(SparseMatrixType::IsRowMajor) { m2.innerVector(i) = m2.innerVector(i) * s1; refMat2.row(i) = refMat2.row(i) * s1; @@ -334,10 +335,10 @@ template void sparse_basic(const SparseMatrixType& re refM2.setZero(); int countFalseNonZero = 0; int countTrueNonZero = 0; - for (int j=0; j(0,1); if (x<0.1) @@ -378,8 +379,8 @@ template void sparse_basic(const SparseMatrixType& re refMat.setZero(); for(int i=0;i(0,rows-1); - int c = internal::random(0,cols-1); + Index r = internal::random(0,rows-1); + Index c = internal::random(0,cols-1); Scalar v = internal::random(); triplets.push_back(TripletType(r,c,v)); refMat(r,c) += v; @@ -456,8 +457,8 @@ template void sparse_basic(const SparseMatrixType& re inc.push_back(std::pair(0,3)); for(size_t i = 0; i< inc.size(); i++) { - int incRows = inc[i].first; - int incCols = inc[i].second; + Index incRows = inc[i].first; + Index incCols = inc[i].second; SparseMatrixType m1(rows, cols); DenseMatrix refMat1 = DenseMatrix::Zero(rows, cols); initSparse(density, refMat1, m1); @@ -502,7 +503,7 @@ void test_sparse_basic() CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); - CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); - CALL_SUBTEST_1(( sparse_basic(SparseMatrix(s, s)) )); + CALL_SUBTEST_1(( sparse_basic(SparseMatrix(short(s), short(s))) )); + CALL_SUBTEST_1(( sparse_basic(SparseMatrix(short(s), short(s))) )); } } diff --git a/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h b/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h index ad47d3d84..51dd1d3c4 100644 --- a/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h +++ b/unsupported/Eigen/src/LevenbergMarquardt/LevenbergMarquardt.h @@ -107,7 +107,7 @@ void lmpar2(const QRSolver &qr, const VectorType &diag, const VectorType &qtb, * http://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm */ template -class LevenbergMarquardt +class LevenbergMarquardt : internal::no_assignment_operator { public: typedef _FunctorType FunctorType; -- cgit v1.2.3 From 84f52ad317f64d01174c622ae596701088237487 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 10 Jul 2013 23:54:53 +0200 Subject: Remove double const qualifier --- Eigen/src/Core/Diagonal.h | 2 +- Eigen/src/Core/MatrixBase.h | 2 +- Eigen/src/Core/Transpose.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/Diagonal.h b/Eigen/src/Core/Diagonal.h index c106f93c4..aab8007b3 100644 --- a/Eigen/src/Core/Diagonal.h +++ b/Eigen/src/Core/Diagonal.h @@ -172,7 +172,7 @@ MatrixBase::diagonal() /** This is the const version of diagonal(). */ template -inline const typename MatrixBase::ConstDiagonalReturnType +inline typename MatrixBase::ConstDiagonalReturnType MatrixBase::diagonal() const { return ConstDiagonalReturnType(derived()); diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 198e51084..373c6821e 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -216,7 +216,7 @@ template class MatrixBase typedef Diagonal DiagonalReturnType; DiagonalReturnType diagonal(); typedef const Diagonal ConstDiagonalReturnType; - const ConstDiagonalReturnType diagonal() const; + ConstDiagonalReturnType diagonal() const; template struct DiagonalIndexReturnType { typedef Diagonal Type; }; template struct ConstDiagonalIndexReturnType { typedef const Diagonal Type; }; diff --git a/Eigen/src/Core/Transpose.h b/Eigen/src/Core/Transpose.h index 798120bf4..f21b3aa65 100644 --- a/Eigen/src/Core/Transpose.h +++ b/Eigen/src/Core/Transpose.h @@ -207,7 +207,7 @@ DenseBase::transpose() * * \sa transposeInPlace(), adjoint() */ template -inline const typename DenseBase::ConstTransposeReturnType +inline typename DenseBase::ConstTransposeReturnType DenseBase::transpose() const { return ConstTransposeReturnType(derived()); -- cgit v1.2.3 From 444c09e31359be498e7ba4a1b54c6cc78de7f6f0 Mon Sep 17 00:00:00 2001 From: Desire Nuentsa Date: Thu, 11 Jul 2013 12:36:57 +0200 Subject: Fix constness of diagonal() and transpose() for MSVC. --- Eigen/src/Core/DenseBase.h | 2 +- Eigen/src/Core/MatrixBase.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/DenseBase.h b/Eigen/src/Core/DenseBase.h index 4e8b820bb..9551b8384 100644 --- a/Eigen/src/Core/DenseBase.h +++ b/Eigen/src/Core/DenseBase.h @@ -281,7 +281,7 @@ template class DenseBase CommaInitializer operator<< (const DenseBase& other); Eigen::Transpose transpose(); - typedef const Transpose ConstTransposeReturnType; + typedef typename internal::add_const >::type ConstTransposeReturnType; ConstTransposeReturnType transpose() const; void transposeInPlace(); #ifndef EIGEN_NO_DEBUG diff --git a/Eigen/src/Core/MatrixBase.h b/Eigen/src/Core/MatrixBase.h index 373c6821e..9193b6abb 100644 --- a/Eigen/src/Core/MatrixBase.h +++ b/Eigen/src/Core/MatrixBase.h @@ -215,7 +215,7 @@ template class MatrixBase typedef Diagonal DiagonalReturnType; DiagonalReturnType diagonal(); - typedef const Diagonal ConstDiagonalReturnType; + typedef typename internal::add_const >::type ConstDiagonalReturnType; ConstDiagonalReturnType diagonal() const; template struct DiagonalIndexReturnType { typedef Diagonal Type; }; -- cgit v1.2.3 From 5431473d673bcfb0a573d0d762f5f99357d498f2 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 12 Jul 2013 14:10:02 +0200 Subject: Fix SparseMatrix::conservativeResize() when one dimension is null --- Eigen/src/SparseCore/SparseMatrix.h | 100 +++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index 2386dfecc..adceafe18 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -531,59 +531,63 @@ class SparseMatrix */ void conservativeResize(Index rows, Index cols) { - // No change - if (this->rows() == rows && this->cols() == cols) return; + // No change + if (this->rows() == rows && this->cols() == cols) return; + + // If one dimension is null, then there is nothing to be preserved + if(rows==0 || cols==0) return resize(rows,cols); - Index innerChange = IsRowMajor ? cols - this->cols() : rows - this->rows(); - Index outerChange = IsRowMajor ? rows - this->rows() : cols - this->cols(); - Index newInnerSize = IsRowMajor ? cols : rows; + Index innerChange = IsRowMajor ? cols - this->cols() : rows - this->rows(); + Index outerChange = IsRowMajor ? rows - this->rows() : cols - this->cols(); + Index newInnerSize = IsRowMajor ? cols : rows; - // Deals with inner non zeros - if (m_innerNonZeros) - { - // Resize m_innerNonZeros - Index *newInnerNonZeros = static_cast(std::realloc(m_innerNonZeros, (m_outerSize + outerChange) * sizeof(Index))); - if (!newInnerNonZeros) internal::throw_std_bad_alloc(); - m_innerNonZeros = newInnerNonZeros; - - for(Index i=m_outerSize; i(std::malloc((m_outerSize+outerChange+1) * sizeof(Index))); - if (!m_innerNonZeros) internal::throw_std_bad_alloc(); - for(Index i = 0; i < m_outerSize; i++) - m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i]; - } + // Deals with inner non zeros + if (m_innerNonZeros) + { + // Resize m_innerNonZeros + Index *newInnerNonZeros = static_cast(std::realloc(m_innerNonZeros, (m_outerSize + outerChange) * sizeof(Index))); + if (!newInnerNonZeros) internal::throw_std_bad_alloc(); + m_innerNonZeros = newInnerNonZeros; - // Change the m_innerNonZeros in case of a decrease of inner size - if (m_innerNonZeros && innerChange < 0) { - for(Index i = 0; i < m_outerSize + (std::min)(outerChange, Index(0)); i++) - { - Index &n = m_innerNonZeros[i]; - Index start = m_outerIndex[i]; - while (n > 0 && m_data.index(start+n-1) >= newInnerSize) --n; - } + for(Index i=m_outerSize; i(std::malloc((m_outerSize+outerChange+1) * sizeof(Index))); + if (!m_innerNonZeros) internal::throw_std_bad_alloc(); + for(Index i = 0; i < m_outerSize; i++) + m_innerNonZeros[i] = m_outerIndex[i+1] - m_outerIndex[i]; + } + + // Change the m_innerNonZeros in case of a decrease of inner size + if (m_innerNonZeros && innerChange < 0) + { + for(Index i = 0; i < m_outerSize + (std::min)(outerChange, Index(0)); i++) + { + Index &n = m_innerNonZeros[i]; + Index start = m_outerIndex[i]; + while (n > 0 && m_data.index(start+n-1) >= newInnerSize) --n; } - - m_innerSize = newInnerSize; + } + + m_innerSize = newInnerSize; - // Re-allocate outer index structure if necessary - if (outerChange == 0) - return; - - Index *newOuterIndex = static_cast(std::realloc(m_outerIndex, (m_outerSize + outerChange + 1) * sizeof(Index))); - if (!newOuterIndex) internal::throw_std_bad_alloc(); - m_outerIndex = newOuterIndex; - if (outerChange > 0) { - Index last = m_outerSize == 0 ? 0 : m_outerIndex[m_outerSize]; - for(Index i=m_outerSize; i(std::realloc(m_outerIndex, (m_outerSize + outerChange + 1) * sizeof(Index))); + if (!newOuterIndex) internal::throw_std_bad_alloc(); + m_outerIndex = newOuterIndex; + if (outerChange > 0) + { + Index last = m_outerSize == 0 ? 0 : m_outerIndex[m_outerSize]; + for(Index i=m_outerSize; i Date: Fri, 12 Jul 2013 16:40:02 +0200 Subject: Fix various scalar type conversion warnings. --- Eigen/src/QR/ColPivHouseholderQR.h | 4 ++-- Eigen/src/SparseLU/SparseLU_pruneL.h | 2 +- test/geo_quaternion.cpp | 4 ++-- test/sizeof.cpp | 2 +- test/sparse.h | 4 ++-- test/sparse_basic.cpp | 16 ++++++++-------- 6 files changed, 16 insertions(+), 16 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/QR/ColPivHouseholderQR.h b/Eigen/src/QR/ColPivHouseholderQR.h index 8a7c9b9e2..8b01f8179 100644 --- a/Eigen/src/QR/ColPivHouseholderQR.h +++ b/Eigen/src/QR/ColPivHouseholderQR.h @@ -525,8 +525,8 @@ struct solve_retval, Rhs> { eigen_assert(rhs().rows() == dec().rows()); - const int cols = dec().cols(), - nonzero_pivots = dec().nonzeroPivots(); + const Index cols = dec().cols(), + nonzero_pivots = dec().nonzeroPivots(); if(nonzero_pivots == 0) { diff --git a/Eigen/src/SparseLU/SparseLU_pruneL.h b/Eigen/src/SparseLU/SparseLU_pruneL.h index 5a855f82f..66460d168 100644 --- a/Eigen/src/SparseLU/SparseLU_pruneL.h +++ b/Eigen/src/SparseLU/SparseLU_pruneL.h @@ -56,7 +56,7 @@ void SparseLUImpl::pruneL(const Index jcol, const IndexVector& per Index jsupno = glu.supno(jcol); Index i,irep,irep1; bool movnum, do_prune = false; - Index kmin, kmax, minloc, maxloc,krow; + Index kmin = 0, kmax = 0, minloc, maxloc,krow; for (i = 0; i < nseg; i++) { irep = segrep(i); diff --git a/test/geo_quaternion.cpp b/test/geo_quaternion.cpp index e011879a5..1694b32c7 100644 --- a/test/geo_quaternion.cpp +++ b/test/geo_quaternion.cpp @@ -32,7 +32,7 @@ template void check_slerp(const QuatType& q0, const QuatType& Scalar theta_tot = AA(q1*q0.inverse()).angle(); if(theta_tot>M_PI) theta_tot = Scalar(2.*M_PI)-theta_tot; - for(Scalar t=0; t<=1.001; t+=0.1) + for(Scalar t=0; t<=Scalar(1.001); t+=Scalar(0.1)) { QuatType q = q0.slerp(t,q1); Scalar theta = AA(q*q0.inverse()).angle(); @@ -156,7 +156,7 @@ template void quaternion(void) check_slerp(q1,q2); q1 = AngleAxisx(b, v1.normalized()); - q2 = AngleAxisx(b+M_PI, v1.normalized()); + q2 = AngleAxisx(b+Scalar(M_PI), v1.normalized()); check_slerp(q1,q2); q1 = AngleAxisx(b, v1.normalized()); diff --git a/test/sizeof.cpp b/test/sizeof.cpp index c454780a6..d9ad35620 100644 --- a/test/sizeof.cpp +++ b/test/sizeof.cpp @@ -13,7 +13,7 @@ template void verifySizeOf(const MatrixType&) { typedef typename MatrixType::Scalar Scalar; if (MatrixType::RowsAtCompileTime!=Dynamic && MatrixType::ColsAtCompileTime!=Dynamic) - VERIFY(sizeof(MatrixType)==sizeof(Scalar)*std::ptrdiff_t(MatrixType::SizeAtCompileTime)); + VERIFY(std::ptrdiff_t(sizeof(MatrixType))==std::ptrdiff_t(sizeof(Scalar))*std::ptrdiff_t(MatrixType::SizeAtCompileTime)); else VERIFY(sizeof(MatrixType)==sizeof(Scalar*) + 2 * sizeof(typename MatrixType::Index)); } diff --git a/test/sparse.h b/test/sparse.h index 1a5ceb38d..a09c65e5f 100644 --- a/test/sparse.h +++ b/test/sparse.h @@ -66,10 +66,10 @@ initSparse(double density, //sparseMat.reserve(int(refMat.rows()*refMat.cols()*density)); sparseMat.reserve(VectorXi::Constant(IsRowMajor ? refMat.rows() : refMat.cols(), int((1.5*density)*(IsRowMajor?refMat.cols():refMat.rows())))); - for(int j=0; j void sparse_basic(const SparseMatrixType& re // test conservative resize { - std::vector< std::pair > inc; - inc.push_back(std::pair(-3,-2)); - inc.push_back(std::pair(0,0)); - inc.push_back(std::pair(3,2)); - inc.push_back(std::pair(3,0)); - inc.push_back(std::pair(0,3)); + std::vector< std::pair > inc; + inc.push_back(std::pair(-3,-2)); + inc.push_back(std::pair(0,0)); + inc.push_back(std::pair(3,2)); + inc.push_back(std::pair(3,0)); + inc.push_back(std::pair(0,3)); for(size_t i = 0; i< inc.size(); i++) { Index incRows = inc[i].first; @@ -472,9 +472,9 @@ template void sparse_basic(const SparseMatrixType& re // Insert new values if (incRows > 0) - m1.insert(refMat1.rows()-1, 0) = refMat1(refMat1.rows()-1, 0) = 1; + m1.insert(m1.rows()-1, 0) = refMat1(refMat1.rows()-1, 0) = 1; if (incCols > 0) - m1.insert(0, refMat1.cols()-1) = refMat1(0, refMat1.cols()-1) = 1; + m1.insert(0, m1.cols()-1) = refMat1(0, refMat1.cols()-1) = 1; VERIFY_IS_APPROX(m1, refMat1); -- cgit v1.2.3 From 4bb0fff151d587958e5b0e5b4a8a6c6ce822b3db Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 13 Jul 2013 19:45:05 +0200 Subject: Rationalize assignment to sparse vectors --- Eigen/src/SparseCore/SparseVector.h | 85 ++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 35 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseVector.h b/Eigen/src/SparseCore/SparseVector.h index 188d9e1f1..869556176 100644 --- a/Eigen/src/SparseCore/SparseVector.h +++ b/Eigen/src/SparseCore/SparseVector.h @@ -45,6 +45,21 @@ struct traits > SupportedAccessPatterns = InnerRandomAccessPattern }; }; + +// Sparse-Vector-Assignment kinds: +enum { + SVA_RuntimeSwitch, + SVA_Inner, + SVA_Outer +}; + +template< typename Dest, typename Src, + int AssignmentKind = !bool(Src::IsVectorAtCompileTime) ? SVA_RuntimeSwitch + : (((Src::Flags&RowMajorBit)==RowMajorBit) && (Src::RowsAtCompileTime==1)) + || (((Src::Flags&RowMajorBit)==0) && (Src::ColsAtCompileTime==1)) ? SVA_Inner + : SVA_Outer> +struct sparse_vector_assign_selector; + } template @@ -241,11 +256,11 @@ class SparseVector template inline SparseVector& operator=(const SparseMatrixBase& other) { - if ( (bool(OtherDerived::IsVectorAtCompileTime) && int(RowsAtCompileTime)!=int(OtherDerived::RowsAtCompileTime)) - || ((!bool(OtherDerived::IsVectorAtCompileTime)) && ( bool(IsColVector) ? other.cols()>1 : other.rows()>1 ))) - return assign(other.transpose(), typename internal::conditional<((Flags & RowMajorBit) == (OtherDerived::Flags & RowMajorBit)),internal::true_type,internal::false_type>::type()); - else - return assign(other, typename internal::conditional<((Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit)),internal::true_type,internal::false_type>::type()); + SparseVector tmp(other.size()); + tmp.reserve(other.nonZeros()); + internal::sparse_vector_assign_selector::run(tmp,other.derived()); + this->swap(tmp); + return *this; } #ifndef EIGEN_PARSED_BY_DOXYGEN @@ -327,12 +342,6 @@ protected: EIGEN_STATIC_ASSERT((_Options&(ColMajor|RowMajor))==Options,INVALID_MATRIX_TEMPLATE_PARAMETERS); } - template - EIGEN_DONT_INLINE SparseVector& assign(const SparseMatrixBase& _other, internal::true_type); - - template - EIGEN_DONT_INLINE SparseVector& assign(const SparseMatrixBase& _other, internal::false_type); - Storage m_data; Index m_size; }; @@ -401,32 +410,38 @@ class SparseVector::ReverseInnerIterator const Index m_start; }; -template -template -EIGEN_DONT_INLINE SparseVector& SparseVector::assign(const SparseMatrixBase& _other, internal::true_type) -{ - const OtherDerived& other(_other.derived()); - - Index size = other.size(); - Index nnz = other.nonZeros(); - resize(size); - reserve(nnz); - for(Index i=0; i +struct sparse_vector_assign_selector { + static void run(Dest& dst, const Src& src) { + eigen_internal_assert(src.innerSize()==src.size()); + for(typename Src::InnerIterator it(src, 0); it; ++it) + dst.insert(it.index()) = it.value(); } - return *this; -} +}; + +template< typename Dest, typename Src> +struct sparse_vector_assign_selector { + static void run(Dest& dst, const Src& src) { + eigen_internal_assert(src.outerSize()==src.size()); + for(typename Dest::Index i=0; i +struct sparse_vector_assign_selector { + static void run(Dest& dst, const Src& src) { + if(src.outerSize()==1) sparse_vector_assign_selector::run(dst, src); + else sparse_vector_assign_selector::run(dst, src); + } +}; -template -template -EIGEN_DONT_INLINE SparseVector& SparseVector::assign(const SparseMatrixBase& _other, internal::false_type) -{ - const OtherDerived& other(_other.derived()); - // there is no special optimization - return Base::operator=(other); } } // end namespace Eigen -- cgit v1.2.3 From ee244d54f434a889cbd266b5da3e65ebc4e4960c Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sun, 14 Jul 2013 11:56:08 +0200 Subject: SparseVector::assign: it is not always possible to reserve according to given non-zeros. --- Eigen/src/SparseCore/SparseVector.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseVector.h b/Eigen/src/SparseCore/SparseVector.h index 869556176..6e7235007 100644 --- a/Eigen/src/SparseCore/SparseVector.h +++ b/Eigen/src/SparseCore/SparseVector.h @@ -56,7 +56,7 @@ enum { template< typename Dest, typename Src, int AssignmentKind = !bool(Src::IsVectorAtCompileTime) ? SVA_RuntimeSwitch : (((Src::Flags&RowMajorBit)==RowMajorBit) && (Src::RowsAtCompileTime==1)) - || (((Src::Flags&RowMajorBit)==0) && (Src::ColsAtCompileTime==1)) ? SVA_Inner + || ((((Src::Flags&RowMajorBit)==0) && (Src::ColsAtCompileTime==1))) ? SVA_Inner : SVA_Outer> struct sparse_vector_assign_selector; @@ -257,7 +257,6 @@ class SparseVector inline SparseVector& operator=(const SparseMatrixBase& other) { SparseVector tmp(other.size()); - tmp.reserve(other.nonZeros()); internal::sparse_vector_assign_selector::run(tmp,other.derived()); this->swap(tmp); return *this; -- cgit v1.2.3 From adeaa657eb54739e0ed2641f8e94b2edb855a586 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Tue, 16 Jul 2013 09:49:01 +0200 Subject: Expose InnerSizeAtCompileTime in SparseMatrixBase (it was already present in DenseBase) and simplify sparse_vector_assign_selector (this also fix a stupid warning in old gcc versions) --- Eigen/src/SparseCore/SparseMatrixBase.h | 3 +++ Eigen/src/SparseCore/SparseVector.h | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseCore/SparseMatrixBase.h b/Eigen/src/SparseCore/SparseMatrixBase.h index 90fee01bc..89ace19e5 100644 --- a/Eigen/src/SparseCore/SparseMatrixBase.h +++ b/Eigen/src/SparseCore/SparseMatrixBase.h @@ -89,6 +89,9 @@ template class SparseMatrixBase : public EigenBase */ IsRowMajor = Flags&RowMajorBit ? 1 : 0, + + InnerSizeAtCompileTime = int(IsVectorAtCompileTime) ? int(SizeAtCompileTime) + : int(IsRowMajor) ? int(ColsAtCompileTime) : int(RowsAtCompileTime), #ifndef EIGEN_PARSED_BY_DOXYGEN _HasDirectAccess = (int(Flags)&DirectAccessBit) ? 1 : 0 // workaround sunCC diff --git a/Eigen/src/SparseCore/SparseVector.h b/Eigen/src/SparseCore/SparseVector.h index 6e7235007..7e15c814b 100644 --- a/Eigen/src/SparseCore/SparseVector.h +++ b/Eigen/src/SparseCore/SparseVector.h @@ -55,9 +55,8 @@ enum { template< typename Dest, typename Src, int AssignmentKind = !bool(Src::IsVectorAtCompileTime) ? SVA_RuntimeSwitch - : (((Src::Flags&RowMajorBit)==RowMajorBit) && (Src::RowsAtCompileTime==1)) - || ((((Src::Flags&RowMajorBit)==0) && (Src::ColsAtCompileTime==1))) ? SVA_Inner - : SVA_Outer> + : Src::InnerSizeAtCompileTime==1 ? SVA_Outer + : SVA_Inner> struct sparse_vector_assign_selector; } -- cgit v1.2.3 From 3e094af410caed08f4ef0fdf3c08df579dfd5337 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Tue, 16 Jul 2013 15:15:53 +0200 Subject: Fix Sparse LU for matrices in non compressed mode --- Eigen/src/SparseLU/SparseLU.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index dda79e5d2..a024b2e16 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -377,11 +377,19 @@ void SparseLU::analyzePattern(const MatrixType& mat) if (m_perm_c.size()) { m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. FIXME : This vector is filled but not subsequently used. //Then, permute only the column pointers + Index * outerIndexPtr; + if (mat.isCompressed()) outerIndexPtr = const_cast(mat.outerIndexPtr()); + else + { + outerIndexPtr = new Index[mat.cols()+1]; + for(Index i = 0; i <= mat.cols(); i++) outerIndexPtr[i] = m_mat.outerIndexPtr()[i]; + } for (Index i = 0; i < mat.cols(); i++) { - m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = mat.outerIndexPtr()[i]; - m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = mat.outerIndexPtr()[i+1] - mat.outerIndexPtr()[i]; + m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i]; + m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i]; } + if(!mat.isCompressed()) delete[] outerIndexPtr; } // Compute the column elimination tree of the permuted matrix IndexVector firstRowElt; @@ -453,11 +461,19 @@ void SparseLU::factorize(const MatrixType& matrix) { m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. //Then, permute only the column pointers + Index * outerIndexPtr; + if (matrix.isCompressed()) outerIndexPtr = const_cast(matrix.outerIndexPtr()); + else + { + outerIndexPtr = new Index[matrix.cols()+1]; + for(Index i = 0; i <= matrix.cols(); i++) outerIndexPtr[i] = m_mat.outerIndexPtr()[i]; + } for (Index i = 0; i < matrix.cols(); i++) { - m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = matrix.outerIndexPtr()[i]; - m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = matrix.outerIndexPtr()[i+1] - matrix.outerIndexPtr()[i]; + m_mat.outerIndexPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i]; + m_mat.innerNonZeroPtr()[m_perm_c.indices()(i)] = outerIndexPtr[i+1] - outerIndexPtr[i]; } + if(!matrix.isCompressed()) delete[] outerIndexPtr; } else { //FIXME This should not be needed if the empty permutation is handled transparently -- cgit v1.2.3 From cfd7f9b84a27d9b88a525560a5d7ee847bc8c507 Mon Sep 17 00:00:00 2001 From: Desire NUENTSA Date: Tue, 16 Jul 2013 15:56:05 +0200 Subject: avoid unneeded const_cast --- Eigen/src/SparseLU/SparseLU.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index a024b2e16..503942b84 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -377,12 +377,13 @@ void SparseLU::analyzePattern(const MatrixType& mat) if (m_perm_c.size()) { m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. FIXME : This vector is filled but not subsequently used. //Then, permute only the column pointers - Index * outerIndexPtr; - if (mat.isCompressed()) outerIndexPtr = const_cast(mat.outerIndexPtr()); + const Index * outerIndexPtr; + if (mat.isCompressed()) outerIndexPtr = mat.outerIndexPtr(); else { - outerIndexPtr = new Index[mat.cols()+1]; - for(Index i = 0; i <= mat.cols(); i++) outerIndexPtr[i] = m_mat.outerIndexPtr()[i]; + Index *outerIndexPtr_t = new Index[mat.cols()+1]; + for(Index i = 0; i <= mat.cols(); i++) outerIndexPtr_t[i] = m_mat.outerIndexPtr()[i]; + outerIndexPtr = outerIndexPtr_t; } for (Index i = 0; i < mat.cols(); i++) { @@ -461,12 +462,13 @@ void SparseLU::factorize(const MatrixType& matrix) { m_mat.uncompress(); //NOTE: The effect of this command is only to create the InnerNonzeros pointers. //Then, permute only the column pointers - Index * outerIndexPtr; - if (matrix.isCompressed()) outerIndexPtr = const_cast(matrix.outerIndexPtr()); + const Index * outerIndexPtr; + if (matrix.isCompressed()) outerIndexPtr = matrix.outerIndexPtr(); else { - outerIndexPtr = new Index[matrix.cols()+1]; - for(Index i = 0; i <= matrix.cols(); i++) outerIndexPtr[i] = m_mat.outerIndexPtr()[i]; + Index* outerIndexPtr_t = new Index[matrix.cols()+1]; + for(Index i = 0; i <= matrix.cols(); i++) outerIndexPtr_t[i] = m_mat.outerIndexPtr()[i]; + outerIndexPtr = outerIndexPtr_t; } for (Index i = 0; i < matrix.cols(); i++) { -- cgit v1.2.3 From bd689ccc2836ac0854961c7a3dc5b1151e576a9e Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 17 Jul 2013 09:21:07 +0200 Subject: IncompleteLUT should not raise an assert in compute if factorize failed. --- Eigen/src/IterativeLinearSolvers/IncompleteLUT.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h b/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h index 50a870aec..b55afc136 100644 --- a/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h +++ b/Eigen/src/IterativeLinearSolvers/IncompleteLUT.h @@ -150,8 +150,7 @@ class IncompleteLUT : internal::noncopyable { analyzePattern(amat); factorize(amat); - eigen_assert(m_factorizationIsOk == true); - m_isInitialized = true; + m_isInitialized = m_factorizationIsOk; return *this; } -- cgit v1.2.3 From bbaef8ebbaca890267062bbd605c218f2d765d29 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 17 Jul 2013 09:30:25 +0200 Subject: SparseLU: make COLAMDOrdering the default ordering method. --- Eigen/src/SparseLU/SparseLU.h | 111 ++++++++++++++++++++++-------------------- test/sparselu.cpp | 4 +- 2 files changed, 59 insertions(+), 56 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/SparseLU/SparseLU.h b/Eigen/src/SparseLU/SparseLU.h index 503942b84..dd9eab2c2 100644 --- a/Eigen/src/SparseLU/SparseLU.h +++ b/Eigen/src/SparseLU/SparseLU.h @@ -14,9 +14,10 @@ namespace Eigen { -template class SparseLU; +template > class SparseLU; template struct SparseLUMatrixLReturnType; template struct SparseLUMatrixUReturnType; + /** \ingroup SparseLU_Module * \class SparseLU * @@ -62,7 +63,7 @@ template struct SparseLUMatrixURetu * "unsupported/Eigen/src/IterativeSolvers/Scaling.h" * * \tparam _MatrixType The type of the sparse matrix. It must be a column-major SparseMatrix<> - * \tparam _OrderingType The ordering method to use, either AMD, COLAMD or METIS + * \tparam _OrderingType The ordering method to use, either AMD, COLAMD or METIS. Default is COLMAD * * * \sa \ref TutorialSparseDirectSolvers @@ -105,9 +106,9 @@ class SparseLU : public internal::SparseLUImpl matrixL() const { return SparseLUMatrixLReturnType(m_Lstore); } /** \returns an expression of the matrix U, - * The only operation available with this expression is the triangular solve - * \code - * y = b; matrixU().solveInPlace(y); - * \endcode - */ + * The only operation available with this expression is the triangular solve + * \code + * y = b; matrixU().solveInPlace(y); + * \endcode + */ SparseLUMatrixUReturnType > matrixU() const { return SparseLUMatrixUReturnType >(m_Lstore, m_Ustore); } /** - * \returns a reference to the row matrix permutation \f$ P_r \f$ such that \f$P_r A P_c^T = L U\f$ - * \sa colsPermutation() - */ + * \returns a reference to the row matrix permutation \f$ P_r \f$ such that \f$P_r A P_c^T = L U\f$ + * \sa colsPermutation() + */ inline const PermutationType& rowsPermutation() const { return m_perm_r; } /** - * \returns a reference to the column matrix permutation\f$ P_c^T \f$ such that \f$P_r A P_c^T = L U\f$ - * \sa rowsPermutation() - */ + * \returns a reference to the column matrix permutation\f$ P_c^T \f$ such that \f$P_r A P_c^T = L U\f$ + * \sa rowsPermutation() + */ inline const PermutationType& colsPermutation() const { return m_perm_c; @@ -182,7 +183,7 @@ class SparseLU : public internal::SparseLUImpl(*this, B.derived()); } - /** \returns the solution X of \f$ A X = B \f$ using the current decomposition of A. + /** \returns the solution X of \f$ A X = B \f$ using the current decomposition of A. * * \sa compute() */ @@ -195,7 +196,7 @@ class SparseLU : public internal::SparseLUImpl(*this, B.derived()); } - /** \brief Reports whether previous computation was successful. + /** \brief Reports whether previous computation was successful. * * \returns \c Success if computation was succesful, * \c NumericalIssue if the LU factorization reports a problem, zero diagonal for instance @@ -208,9 +209,10 @@ class SparseLU : public internal::SparseLUImpl void SparseLU::analyzePattern(const MatrixType& mat) { @@ -428,23 +431,23 @@ void SparseLU::analyzePattern(const MatrixType& mat) /** - * - Numerical factorization - * - Interleaved with the symbolic factorization - * On exit, info is - * - * = 0: successful factorization - * - * > 0: if info = i, and i is - * - * <= A->ncol: U(i,i) is exactly zero. The factorization has - * been completed, but the factor U is exactly singular, - * and division by zero will occur if it is used to solve a - * system of equations. - * - * > A->ncol: number of bytes allocated when memory allocation - * failure occurred, plus A->ncol. If lwork = -1, it is - * the estimated amount of space needed, plus A->ncol. - */ + * - Numerical factorization + * - Interleaved with the symbolic factorization + * On exit, info is + * + * = 0: successful factorization + * + * > 0: if info = i, and i is + * + * <= A->ncol: U(i,i) is exactly zero. The factorization has + * been completed, but the factor U is exactly singular, + * and division by zero will occur if it is used to solve a + * system of equations. + * + * > A->ncol: number of bytes allocated when memory allocation + * failure occurred, plus A->ncol. If lwork = -1, it is + * the estimated amount of space needed, plus A->ncol. + */ template void SparseLU::factorize(const MatrixType& matrix) { diff --git a/test/sparselu.cpp b/test/sparselu.cpp index 6a9eac065..37980defc 100644 --- a/test/sparselu.cpp +++ b/test/sparselu.cpp @@ -26,7 +26,7 @@ // SparseLU solve does not accept column major matrices for the destination. // However, as expected, the generic check_sparse_square_solving routines produces row-major // rhs and destination matrices when compiled with EIGEN_DEFAULT_TO_ROW_MAJOR -// + #ifdef EIGEN_DEFAULT_TO_ROW_MAJOR #undef EIGEN_DEFAULT_TO_ROW_MAJOR #endif @@ -37,7 +37,7 @@ template void test_sparselu_T() { - SparseLU, COLAMDOrdering > sparselu_colamd; + SparseLU /*, COLAMDOrdering*/ > sparselu_colamd; // COLAMDOrdering is the default SparseLU, AMDOrdering > sparselu_amd; SparseLU, NaturalOrdering > sparselu_natural; -- cgit v1.2.3 From 20e535e1429cdb2f2dace3e2e6915e33968aa198 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 17 Jul 2013 10:04:20 +0200 Subject: Bump default branch to 3.2.90 --- Eigen/src/Core/util/Macros.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Eigen') diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 96737456a..6798a3e0f 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -12,8 +12,8 @@ #define EIGEN_MACROS_H #define EIGEN_WORLD_VERSION 3 -#define EIGEN_MAJOR_VERSION 1 -#define EIGEN_MINOR_VERSION 91 +#define EIGEN_MAJOR_VERSION 2 +#define EIGEN_MINOR_VERSION 90 #define EIGEN_VERSION_AT_LEAST(x,y,z) (EIGEN_WORLD_VERSION>x || (EIGEN_WORLD_VERSION>=x && \ (EIGEN_MAJOR_VERSION>y || (EIGEN_MAJOR_VERSION>=y && \ -- cgit v1.2.3