Make all compute() methods return a reference to *this.

This commit is contained in:
Jitse Niesen 2010-06-01 17:40:51 +01:00
parent 4c6d182c42
commit e3e2380548
5 changed files with 21 additions and 10 deletions

View File

@ -200,6 +200,7 @@ template<typename _MatrixType> class ComplexEigenSolver
* \param[in] computeEigenvectors If true, both the eigenvectors and the
* eigenvalues are computed; if false, only the eigenvalues are
* computed.
* \returns Reference to \c *this
*
* This function computes the eigenvalues of the complex matrix \p matrix.
* The eigenvalues() function can be used to retrieve them. If
@ -217,7 +218,7 @@ template<typename _MatrixType> class ComplexEigenSolver
* Example: \include ComplexEigenSolver_compute.cpp
* Output: \verbinclude ComplexEigenSolver_compute.out
*/
void compute(const MatrixType& matrix, bool computeEigenvectors = true);
ComplexEigenSolver& compute(const MatrixType& matrix, bool computeEigenvectors = true);
protected:
EigenvectorType m_eivec;
@ -230,7 +231,7 @@ template<typename _MatrixType> class ComplexEigenSolver
template<typename MatrixType>
void ComplexEigenSolver<MatrixType>::compute(const MatrixType& matrix, bool computeEigenvectors)
ComplexEigenSolver<MatrixType>& ComplexEigenSolver<MatrixType>::compute(const MatrixType& matrix, bool computeEigenvectors)
{
// this code is inspired from Jampack
assert(matrix.cols() == matrix.rows());
@ -292,6 +293,8 @@ void ComplexEigenSolver<MatrixType>::compute(const MatrixType& matrix, bool comp
m_eivec.col(i).swap(m_eivec.col(k));
}
}
return *this;
}

View File

@ -175,6 +175,7 @@ template<typename _MatrixType> class ComplexSchur
*
* \param[in] matrix Square matrix whose Schur decomposition is to be computed.
* \param[in] computeU If true, both T and U are computed; if false, only T is computed.
* \returns Reference to \c *this
*
* The Schur decomposition is computed by first reducing the
* matrix to Hessenberg form using the class
@ -189,7 +190,7 @@ template<typename _MatrixType> class ComplexSchur
* Example: \include ComplexSchur_compute.cpp
* Output: \verbinclude ComplexSchur_compute.out
*/
void compute(const MatrixType& matrix, bool computeU = true);
ComplexSchur& compute(const MatrixType& matrix, bool computeU = true);
protected:
ComplexMatrixType m_matT, m_matU;
@ -296,7 +297,7 @@ typename ComplexSchur<MatrixType>::ComplexScalar ComplexSchur<MatrixType>::compu
template<typename MatrixType>
void ComplexSchur<MatrixType>::compute(const MatrixType& matrix, bool computeU)
ComplexSchur<MatrixType>& ComplexSchur<MatrixType>::compute(const MatrixType& matrix, bool computeU)
{
m_matUisUptodate = false;
ei_assert(matrix.cols() == matrix.rows());
@ -307,11 +308,12 @@ void ComplexSchur<MatrixType>::compute(const MatrixType& matrix, bool computeU)
if(computeU) m_matU = ComplexMatrixType::Identity(1,1);
m_isInitialized = true;
m_matUisUptodate = computeU;
return;
return *this;
}
ei_complex_schur_reduce_to_hessenberg<MatrixType, NumTraits<Scalar>::IsComplex>::run(*this, matrix, computeU);
reduceToTriangularForm(computeU);
return *this;
}
/* Reduce given matrix to Hessenberg form */

View File

@ -141,6 +141,7 @@ template<typename _MatrixType> class HessenbergDecomposition
/** \brief Computes Hessenberg decomposition of given matrix.
*
* \param[in] matrix Square matrix whose Hessenberg decomposition is to be computed.
* \returns Reference to \c *this
*
* The Hessenberg decomposition is computed by bringing the columns of the
* matrix successively in the required form using Householder reflections
@ -154,17 +155,18 @@ template<typename _MatrixType> class HessenbergDecomposition
* Example: \include HessenbergDecomposition_compute.cpp
* Output: \verbinclude HessenbergDecomposition_compute.out
*/
void compute(const MatrixType& matrix)
HessenbergDecomposition& compute(const MatrixType& matrix)
{
m_matrix = matrix;
if(matrix.rows()<2)
{
m_isInitialized = true;
return;
return *this;
}
m_hCoeffs.resize(matrix.rows()-1,1);
_compute(m_matrix, m_hCoeffs, m_temp);
m_isInitialized = true;
return *this;
}
/** \brief Returns the Householder coefficients.

View File

@ -161,6 +161,7 @@ template<typename _MatrixType> class RealSchur
*
* \param[in] matrix Square matrix whose Schur decomposition is to be computed.
* \param[in] computeU If true, both T and U are computed; if false, only T is computed.
* \returns Reference to \c *this
*
* The Schur decomposition is computed by first reducing the matrix to
* Hessenberg form using the class HessenbergDecomposition. The Hessenberg
@ -173,7 +174,7 @@ template<typename _MatrixType> class RealSchur
* Example: \include RealSchur_compute.cpp
* Output: \verbinclude RealSchur_compute.out
*/
void compute(const MatrixType& matrix, bool computeU = true);
RealSchur& compute(const MatrixType& matrix, bool computeU = true);
private:
@ -196,7 +197,7 @@ template<typename _MatrixType> class RealSchur
template<typename MatrixType>
void RealSchur<MatrixType>::compute(const MatrixType& matrix, bool computeU)
RealSchur<MatrixType>& RealSchur<MatrixType>::compute(const MatrixType& matrix, bool computeU)
{
assert(matrix.cols() == matrix.rows());
@ -251,6 +252,7 @@ void RealSchur<MatrixType>::compute(const MatrixType& matrix, bool computeU)
m_isInitialized = true;
m_matUisUptodate = computeU;
return *this;
}
/** \internal Computes and returns vector L1 norm of T */

View File

@ -137,6 +137,7 @@ template<typename _MatrixType> class Tridiagonalization
*
* \param[in] matrix Selfadjoint matrix whose tridiagonal decomposition
* is to be computed.
* \returns Reference to \c *this
*
* The tridiagonal decomposition is computed by bringing the columns of
* the matrix successively in the required form using Householder
@ -149,12 +150,13 @@ template<typename _MatrixType> class Tridiagonalization
* Example: \include Tridiagonalization_compute.cpp
* Output: \verbinclude Tridiagonalization_compute.out
*/
void compute(const MatrixType& matrix)
Tridiagonalization& compute(const MatrixType& matrix)
{
m_matrix = matrix;
m_hCoeffs.resize(matrix.rows()-1, 1);
_compute(m_matrix, m_hCoeffs);
m_isInitialized = true;
return *this;
}
/** \brief Returns the Householder coefficients.