This commit is contained in:
Gael Guennebaud
2011-01-26 16:36:07 +01:00
67 changed files with 1549 additions and 558 deletions

View File

@@ -415,17 +415,14 @@ template<typename Derived> class DenseBase
typename internal::traits<Derived>::Scalar minCoeff() const;
typename internal::traits<Derived>::Scalar maxCoeff() const;
typename internal::traits<Derived>::Scalar minCoeff(Index* row, Index* col) const;
typename internal::traits<Derived>::Scalar maxCoeff(Index* row, Index* col) const;
typename internal::traits<Derived>::Scalar minCoeff(Index* index) const;
typename internal::traits<Derived>::Scalar maxCoeff(Index* index) const;
#ifdef EIGEN2_SUPPORT
typename internal::traits<Derived>::Scalar minCoeff(int* row, int* col) const;
typename internal::traits<Derived>::Scalar maxCoeff(int* row, int* col) const;
typename internal::traits<Derived>::Scalar minCoeff(int* index) const;
typename internal::traits<Derived>::Scalar maxCoeff(int* index) const;
#endif
template<typename IndexType>
typename internal::traits<Derived>::Scalar minCoeff(IndexType* row, IndexType* col) const;
template<typename IndexType>
typename internal::traits<Derived>::Scalar maxCoeff(IndexType* row, IndexType* col) const;
template<typename IndexType>
typename internal::traits<Derived>::Scalar minCoeff(IndexType* index) const;
template<typename IndexType>
typename internal::traits<Derived>::Scalar maxCoeff(IndexType* index) const;
template<typename BinaryOp>
typename internal::result_of<BinaryOp(typename internal::traits<Derived>::Scalar)>::type

View File

@@ -243,8 +243,8 @@ template<typename Derived> class MatrixBase
typename MatrixBase::template ConstDiagonalIndexReturnType<Dynamic>::Type diagonal(Index index) const;
#ifdef EIGEN2_SUPPORT
template<unsigned int Mode> TriangularView<Derived, Mode> part();
template<unsigned int Mode> const TriangularView<Derived, Mode> part() const;
template<unsigned int Mode> typename internal::eigen2_part_return_type<Derived, Mode>::type part();
template<unsigned int Mode> const typename internal::eigen2_part_return_type<Derived, Mode>::type part() const;
// huuuge hack. make Eigen2's matrix.part<Diagonal>() work in eigen3. Problem: Diagonal is now a class template instead
// of an integer constant. Solution: overload the part() method template wrt template parameters list.
@@ -334,7 +334,26 @@ template<typename Derived> class MatrixBase
const FullPivLU<PlainObject> fullPivLu() const;
const PartialPivLU<PlainObject> partialPivLu() const;
#if EIGEN2_SUPPORT_STAGE < STAGE20_RESOLVE_API_CONFLICTS
const LU<PlainObject> lu() const;
#endif
#ifdef EIGEN2_SUPPORT
const LU<PlainObject> eigen2_lu() const;
#endif
#if EIGEN2_SUPPORT_STAGE > STAGE20_RESOLVE_API_CONFLICTS
const PartialPivLU<PlainObject> lu() const;
#endif
#ifdef EIGEN2_SUPPORT
template<typename ResultType>
void computeInverse(MatrixBase<ResultType> *result) const {
*result = this->inverse();
}
#endif
const internal::inverse_impl<Derived> inverse() const;
template<typename ResultType>
void computeInverseAndDetWithCheck(
@@ -361,6 +380,10 @@ template<typename Derived> class MatrixBase
const HouseholderQR<PlainObject> householderQr() const;
const ColPivHouseholderQR<PlainObject> colPivHouseholderQr() const;
const FullPivHouseholderQR<PlainObject> fullPivHouseholderQr() const;
#ifdef EIGEN2_SUPPORT
const QR<PlainObject> qr() const;
#endif
EigenvaluesReturnType eigenvalues() const;
RealScalar operatorNorm() const;
@@ -369,6 +392,10 @@ template<typename Derived> class MatrixBase
JacobiSVD<PlainObject> jacobiSvd(unsigned int computationOptions = 0) const;
#ifdef EIGEN2_SUPPORT
SVD<PlainObject> svd() const;
#endif
/////////// Geometry module ///////////
template<typename OtherDerived>

View File

@@ -46,13 +46,14 @@ template<typename MatrixType, unsigned int UpLo>
struct traits<SelfAdjointView<MatrixType, UpLo> > : traits<MatrixType>
{
typedef typename nested<MatrixType>::type MatrixTypeNested;
typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
typedef MatrixType ExpressionType;
typedef typename MatrixType::PlainObject DenseMatrixType;
enum {
Mode = UpLo | SelfAdjoint,
Flags = _MatrixTypeNested::Flags & (HereditaryBits)
Flags = MatrixTypeNestedCleaned::Flags & (HereditaryBits)
& (~(PacketAccessBit | DirectAccessBit | LinearAccessBit)), // FIXME these flags should be preserved
CoeffReadCost = _MatrixTypeNested::CoeffReadCost
CoeffReadCost = MatrixTypeNestedCleaned::CoeffReadCost
};
};
}
@@ -68,6 +69,8 @@ template<typename MatrixType, unsigned int UpLo> class SelfAdjointView
public:
typedef TriangularBase<SelfAdjointView> Base;
typedef typename internal::traits<SelfAdjointView>::MatrixTypeNested MatrixTypeNested;
typedef typename internal::traits<SelfAdjointView>::MatrixTypeNestedCleaned MatrixTypeNestedCleaned;
/** \brief The type of coefficients in this matrix */
typedef typename internal::traits<SelfAdjointView>::Scalar Scalar;
@@ -106,10 +109,10 @@ template<typename MatrixType, unsigned int UpLo> class SelfAdjointView
}
/** \internal */
const MatrixType& _expression() const { return m_matrix; }
const MatrixTypeNestedCleaned& _expression() const { return m_matrix; }
const MatrixType& nestedExpression() const { return m_matrix; }
MatrixType& nestedExpression() { return const_cast<MatrixType&>(m_matrix); }
const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; }
MatrixTypeNestedCleaned& nestedExpression() { return *const_cast<MatrixTypeNestedCleaned*>(&m_matrix); }
/** Efficient self-adjoint matrix times vector/matrix product */
template<typename OtherDerived>
@@ -171,9 +174,32 @@ template<typename MatrixType, unsigned int UpLo> class SelfAdjointView
EigenvaluesReturnType eigenvalues() const;
RealScalar operatorNorm() const;
#ifdef EIGEN2_SUPPORT
template<typename OtherDerived>
SelfAdjointView& operator=(const MatrixBase<OtherDerived>& other)
{
enum {
OtherPart = UpLo == Upper ? StrictlyLower : StrictlyUpper
};
m_matrix.const_cast_derived().template triangularView<UpLo>() = other;
m_matrix.const_cast_derived().template triangularView<OtherPart>() = other.adjoint();
return *this;
}
template<typename OtherMatrixType, unsigned int OtherMode>
SelfAdjointView& operator=(const TriangularView<OtherMatrixType, OtherMode>& other)
{
enum {
OtherPart = UpLo == Upper ? StrictlyLower : StrictlyUpper
};
m_matrix.const_cast_derived().template triangularView<UpLo>() = other.toDenseMatrix();
m_matrix.const_cast_derived().template triangularView<OtherPart>() = other.toDenseMatrix().adjoint();
return *this;
}
#endif
protected:
const typename MatrixType::Nested m_matrix;
const MatrixTypeNested m_matrix;
};

View File

@@ -48,6 +48,7 @@ template<typename Derived> class TriangularBase : public EigenBase<Derived>
typedef typename internal::traits<Derived>::Scalar Scalar;
typedef typename internal::traits<Derived>::StorageKind StorageKind;
typedef typename internal::traits<Derived>::Index Index;
typedef typename internal::traits<Derived>::DenseMatrixType DenseMatrixType;
inline TriangularBase() { eigen_assert(!((Mode&UnitDiag) && (Mode&ZeroDiag))); }
@@ -88,6 +89,13 @@ template<typename Derived> class TriangularBase : public EigenBase<Derived>
template<typename DenseDerived>
void evalToLazy(MatrixBase<DenseDerived> &other) const;
DenseMatrixType toDenseMatrix() const
{
DenseMatrixType res(rows(), cols());
evalToLazy(res);
return res;
}
protected:
void check_coordinates(Index row, Index col) const
@@ -135,12 +143,14 @@ template<typename MatrixType, unsigned int _Mode>
struct traits<TriangularView<MatrixType, _Mode> > : traits<MatrixType>
{
typedef typename nested<MatrixType>::type MatrixTypeNested;
typedef typename remove_reference<MatrixTypeNested>::type _MatrixTypeNested;
typedef typename remove_reference<MatrixTypeNested>::type MatrixTypeNestedNonRef;
typedef typename remove_all<MatrixTypeNested>::type MatrixTypeNestedCleaned;
typedef MatrixType ExpressionType;
typedef typename MatrixType::PlainObject DenseMatrixType;
enum {
Mode = _Mode,
Flags = (_MatrixTypeNested::Flags & (HereditaryBits) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit))) | Mode,
CoeffReadCost = _MatrixTypeNested::CoeffReadCost
Flags = (MatrixTypeNestedCleaned::Flags & (HereditaryBits) & (~(PacketAccessBit | DirectAccessBit | LinearAccessBit))) | Mode,
CoeffReadCost = MatrixTypeNestedCleaned::CoeffReadCost
};
};
}
@@ -159,11 +169,13 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
typedef typename internal::traits<TriangularView>::Scalar Scalar;
typedef _MatrixType MatrixType;
typedef typename MatrixType::PlainObject DenseMatrixType;
typedef typename internal::traits<TriangularView>::DenseMatrixType DenseMatrixType;
protected:
typedef typename MatrixType::Nested MatrixTypeNested;
typedef typename internal::remove_all<MatrixTypeNested>::type _MatrixTypeNested;
typedef typename internal::traits<TriangularView>::MatrixTypeNested MatrixTypeNested;
typedef typename internal::traits<TriangularView>::MatrixTypeNestedNonRef MatrixTypeNestedNonRef;
typedef typename internal::traits<TriangularView>::MatrixTypeNestedCleaned MatrixTypeNestedCleaned;
typedef typename internal::remove_all<typename MatrixType::ConjugateReturnType>::type MatrixConjugateReturnType;
public:
@@ -226,8 +238,8 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
return m_matrix.const_cast_derived().coeffRef(row, col);
}
const MatrixType& nestedExpression() const { return m_matrix; }
MatrixType& nestedExpression() { return const_cast<MatrixType&>(m_matrix); }
const MatrixTypeNestedCleaned& nestedExpression() const { return m_matrix; }
MatrixTypeNestedCleaned& nestedExpression() { return *const_cast<MatrixTypeNestedCleaned*>(&m_matrix); }
/** Assigns a triangular matrix to a triangular part of a dense matrix */
template<typename OtherDerived>
@@ -269,13 +281,6 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
inline const TriangularView<Transpose<MatrixType>,TransposeMode> transpose() const
{ return m_matrix.transpose(); }
DenseMatrixType toDenseMatrix() const
{
DenseMatrixType res(rows(), cols());
evalToLazy(res);
return res;
}
/** Efficient triangular matrix times vector/matrix product */
template<typename OtherDerived>
TriangularProduct<Mode,true,MatrixType,false,OtherDerived,OtherDerived::IsVectorAtCompileTime>
@@ -310,18 +315,18 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
const typename eigen2_product_return_type<OtherMatrixType>::type
operator*(const TriangularView<OtherMatrixType, Mode>& rhs) const
{
return toDenseMatrix() * rhs.toDenseMatrix();
return this->toDenseMatrix() * rhs.toDenseMatrix();
}
template<typename OtherMatrixType>
bool isApprox(const TriangularView<OtherMatrixType, Mode>& other, typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision()) const
{
return toDenseMatrix().isApprox(other.toDenseMatrix(), precision);
return this->toDenseMatrix().isApprox(other.toDenseMatrix(), precision);
}
template<typename OtherDerived>
bool isApprox(const MatrixBase<OtherDerived>& other, typename NumTraits<Scalar>::Real precision = NumTraits<Scalar>::dummy_precision()) const
{
return toDenseMatrix().isApprox(other, precision);
return this->toDenseMatrix().isApprox(other, precision);
}
#endif // EIGEN2_SUPPORT
@@ -342,15 +347,15 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
void solveInPlace(const MatrixBase<OtherDerived>& other) const
{ return solveInPlace<OnTheLeft>(other); }
const SelfAdjointView<_MatrixTypeNested,Mode> selfadjointView() const
const SelfAdjointView<MatrixTypeNestedNonRef,Mode> selfadjointView() const
{
EIGEN_STATIC_ASSERT((Mode&UnitDiag)==0,PROGRAMMING_ERROR);
return SelfAdjointView<_MatrixTypeNested,Mode>(m_matrix);
return SelfAdjointView<MatrixTypeNestedNonRef,Mode>(m_matrix);
}
SelfAdjointView<_MatrixTypeNested,Mode> selfadjointView()
SelfAdjointView<MatrixTypeNestedNonRef,Mode> selfadjointView()
{
EIGEN_STATIC_ASSERT((Mode&UnitDiag)==0,PROGRAMMING_ERROR);
return SelfAdjointView<_MatrixTypeNested,Mode>(m_matrix);
return SelfAdjointView<MatrixTypeNestedNonRef,Mode>(m_matrix);
}
template<typename OtherDerived>
@@ -692,7 +697,7 @@ void TriangularBase<Derived>::evalToLazy(MatrixBase<DenseDerived> &other) const
eigen_assert(this->rows() == other.rows() && this->cols() == other.cols());
internal::triangular_assignment_selector
<DenseDerived, typename internal::traits<Derived>::ExpressionType, Derived::Mode,
<DenseDerived, typename internal::traits<Derived>::MatrixTypeNestedCleaned, Derived::Mode,
unroll ? int(DenseDerived::SizeAtCompileTime) : Dynamic,
true // clear the opposite triangular part
>::run(other.derived(), derived().nestedExpression());
@@ -707,10 +712,27 @@ void TriangularBase<Derived>::evalToLazy(MatrixBase<DenseDerived> &other) const
***************************************************************************/
#ifdef EIGEN2_SUPPORT
// implementation of part<>(), including the SelfAdjoint case.
namespace internal {
template<typename MatrixType, unsigned int Mode>
struct eigen2_part_return_type
{
typedef TriangularView<MatrixType, Mode> type;
};
template<typename MatrixType>
struct eigen2_part_return_type<MatrixType, SelfAdjoint>
{
typedef SelfAdjointView<MatrixType, Upper> type;
};
}
/** \deprecated use MatrixBase::triangularView() */
template<typename Derived>
template<unsigned int Mode>
const TriangularView<Derived, Mode> MatrixBase<Derived>::part() const
const typename internal::eigen2_part_return_type<Derived, Mode>::type MatrixBase<Derived>::part() const
{
return derived();
}
@@ -718,7 +740,7 @@ const TriangularView<Derived, Mode> MatrixBase<Derived>::part() const
/** \deprecated use MatrixBase::triangularView() */
template<typename Derived>
template<unsigned int Mode>
TriangularView<Derived, Mode> MatrixBase<Derived>::part()
typename internal::eigen2_part_return_type<Derived, Mode>::type MatrixBase<Derived>::part()
{
return derived();
}

View File

@@ -183,8 +183,9 @@ struct functor_traits<max_coeff_visitor<Scalar> > {
* \sa DenseBase::minCoeff(Index*), DenseBase::maxCoeff(Index*,Index*), DenseBase::visitor(), DenseBase::minCoeff()
*/
template<typename Derived>
template<typename IndexType>
typename internal::traits<Derived>::Scalar
DenseBase<Derived>::minCoeff(Index* row, Index* col) const
DenseBase<Derived>::minCoeff(IndexType* row, IndexType* col) const
{
internal::min_coeff_visitor<Derived> minVisitor;
this->visit(minVisitor);
@@ -196,11 +197,12 @@ DenseBase<Derived>::minCoeff(Index* row, Index* col) const
/** \returns the minimum of all coefficients of *this
* and puts in *index its location.
*
* \sa DenseBase::minCoeff(Index*,Index*), DenseBase::maxCoeff(Index*,Index*), DenseBase::visitor(), DenseBase::minCoeff()
* \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::minCoeff()
*/
template<typename Derived>
template<typename IndexType>
typename internal::traits<Derived>::Scalar
DenseBase<Derived>::minCoeff(Index* index) const
DenseBase<Derived>::minCoeff(IndexType* index) const
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
internal::min_coeff_visitor<Derived> minVisitor;
@@ -212,11 +214,12 @@ DenseBase<Derived>::minCoeff(Index* index) const
/** \returns the maximum of all coefficients of *this
* and puts in *row and *col its location.
*
* \sa DenseBase::minCoeff(Index*,Index*), DenseBase::visitor(), DenseBase::maxCoeff()
* \sa DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::maxCoeff()
*/
template<typename Derived>
template<typename IndexType>
typename internal::traits<Derived>::Scalar
DenseBase<Derived>::maxCoeff(Index* row, Index* col) const
DenseBase<Derived>::maxCoeff(IndexType* row, IndexType* col) const
{
internal::max_coeff_visitor<Derived> maxVisitor;
this->visit(maxVisitor);
@@ -228,11 +231,12 @@ DenseBase<Derived>::maxCoeff(Index* row, Index* col) const
/** \returns the maximum of all coefficients of *this
* and puts in *index its location.
*
* \sa DenseBase::maxCoeff(Index*,Index*), DenseBase::minCoeff(Index*,Index*), DenseBase::visitor(), DenseBase::maxCoeff()
* \sa DenseBase::maxCoeff(IndexType*,IndexType*), DenseBase::minCoeff(IndexType*,IndexType*), DenseBase::visitor(), DenseBase::maxCoeff()
*/
template<typename Derived>
template<typename IndexType>
typename internal::traits<Derived>::Scalar
DenseBase<Derived>::maxCoeff(Index* index) const
DenseBase<Derived>::maxCoeff(IndexType* index) const
{
EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
internal::max_coeff_visitor<Derived> maxVisitor;
@@ -241,51 +245,4 @@ DenseBase<Derived>::maxCoeff(Index* index) const
return maxVisitor.res;
}
#ifdef EIGEN2_SUPPORT
template<typename Derived>
typename internal::traits<Derived>::Scalar
DenseBase<Derived>::minCoeff(int* row, int* col) const
{
Index r, c;
Scalar result = this->minCoeff(&r, &c);
*row = int(r);
*col = int(c);
return result;
}
template<typename Derived>
typename internal::traits<Derived>::Scalar
DenseBase<Derived>::minCoeff(int* index) const
{
Index i;
Scalar result = this->minCoeff(&i);
*index = int(i);
return result;
}
template<typename Derived>
typename internal::traits<Derived>::Scalar
DenseBase<Derived>::maxCoeff(int* row, int* col) const
{
Index r, c;
Scalar result = this->maxCoeff(&r, &c);
*row = int(r);
*col = int(c);
return result;
}
template<typename Derived>
typename internal::traits<Derived>::Scalar
DenseBase<Derived>::maxCoeff(int* index) const
{
Index i;
Scalar result = this->maxCoeff(&i);
*index = int(i);
return result;
}
#endif // EIGEN2_SUPPORT
#endif // EIGEN_VISITOR_H

View File

@@ -270,6 +270,12 @@ struct stem_function
#ifdef EIGEN2_SUPPORT
template<typename ExpressionType> class Cwise;
template<typename MatrixType> class Minor;
template<typename MatrixType> class LU;
template<typename MatrixType> class QR;
template<typename MatrixType> class SVD;
namespace internal {
template<typename MatrixType, unsigned int Mode> struct eigen2_part_return_type;
}
#endif
#endif // EIGEN_FORWARDDECLARATIONS_H