* added a Tridiagonalization class for selfadjoint matrices

* added MatrixBase::real()
* added the ability to extract a selfadjoint matrix from the
  lower or upper part of a matrix, e.g.:
    m.extract<Upper|SelfAdjoint>()
  will ignore the strict lower part and return a selfadjoint.
  This is compatible with ZeroDiag and UnitDiag.
This commit is contained in:
Gael Guennebaud
2008-06-01 17:20:18 +00:00
parent dc5fd8dfff
commit 06752b2b77
8 changed files with 269 additions and 4 deletions

View File

@@ -139,7 +139,7 @@ MatrixBase<Derived>::cwiseAbs2() const
return derived();
}
/** \returns an expression of the complex conjugate of *this.
/** \returns an expression of the complex conjugate of \c *this.
*
* \sa adjoint() */
template<typename Derived>
@@ -149,6 +149,16 @@ MatrixBase<Derived>::conjugate() const
return ConjugateReturnType(derived());
}
/** \returns an expression of the real part of \c *this.
*
* \sa adjoint() */
template<typename Derived>
inline const typename MatrixBase<Derived>::RealReturnType
MatrixBase<Derived>::real() const
{
return derived();
}
/** \returns an expression of *this with the \a Scalar type casted to
* \a NewScalar.
*

View File

@@ -77,7 +77,7 @@ template<typename MatrixType, unsigned int Mode> class Extract
inline Scalar _coeff(int row, int col) const
{
if(Flags & LowerTriangularBit ? col>row : row>col)
return (Scalar)0;
return (Flags & SelfAdjointBit) ? ei_conj(m_matrix.coeff(col, row)) : (Scalar)0;
if(Flags & UnitDiagBit)
return col==row ? (Scalar)1 : m_matrix.coeff(row, col);
else if(Flags & ZeroDiagBit)

View File

@@ -204,6 +204,19 @@ template<typename Scalar, typename NewType>
struct ei_functor_traits<ei_scalar_cast_op<Scalar,NewType> >
{ enum { Cost = ei_is_same_type<Scalar, NewType>::ret ? 0 : NumTraits<NewType>::AddCost, IsVectorizable = false }; };
/** \internal
* \brief Template functor to extract the real part of a complex
*
* \sa class CwiseUnaryOp, MatrixBase::real()
*/
template<typename Scalar>
struct ei_scalar_real_op EIGEN_EMPTY_STRUCT {
typedef typename NumTraits<Scalar>::Real result_type;
inline result_type operator() (const Scalar& a) const { return ei_real(a); }
};
template<typename Scalar>
struct ei_functor_traits<ei_scalar_real_op<Scalar> >
{ enum { Cost = 0, IsVectorizable = false }; };
/** \internal
* \brief Template functor to multiply a scalar by a fixed other one

View File

@@ -197,6 +197,8 @@ template<typename Derived> class MatrixBase : public ArrayBase<Derived>
CwiseUnaryOp<ei_scalar_conjugate_op<Scalar>, Derived>,
Derived&
>::ret ConjugateReturnType;
/** the return type of MatrixBase::real() */
typedef CwiseUnaryOp<ei_scalar_real_op<Scalar>, Derived> RealReturnType;
/** the return type of MatrixBase::adjoint() */
typedef Transpose<NestByValue<typename ei_unref<ConjugateReturnType>::type> >
AdjointReturnType;
@@ -477,6 +479,7 @@ template<typename Derived> class MatrixBase : public ArrayBase<Derived>
/// \name Coefficient-wise operations
//@{
const ConjugateReturnType conjugate() const;
const RealReturnType real() const;
template<typename OtherDerived>
const CwiseBinaryOp<ei_scalar_product_op<typename ei_traits<Derived>::Scalar>, Derived, OtherDerived>

View File

@@ -59,8 +59,6 @@ const unsigned int Upper = UpperTriangularBit;
const unsigned int StrictlyUpper = UpperTriangularBit | ZeroDiagBit;
const unsigned int Lower = LowerTriangularBit;
const unsigned int StrictlyLower = LowerTriangularBit | ZeroDiagBit;
// additional possible values for the Mode parameter of part()
const unsigned int SelfAdjoint = SelfAdjointBit;
// additional possible values for the Mode parameter of extract()

View File

@@ -59,6 +59,7 @@ template<typename Scalar> struct ei_scalar_product_op;
template<typename Scalar> struct ei_scalar_quotient_op;
template<typename Scalar> struct ei_scalar_opposite_op;
template<typename Scalar> struct ei_scalar_conjugate_op;
template<typename Scalar> struct ei_scalar_real_op;
template<typename Scalar> struct ei_scalar_abs_op;
template<typename Scalar> struct ei_scalar_abs2_op;
template<typename Scalar> struct ei_scalar_sqrt_op;