Eval is now implemented like the other expression types, it no longer

inherits Matrix. Remove the typedefs I added in Matrix.
This commit is contained in:
Benoit Jacob 2008-01-14 22:36:37 +00:00
parent 2ee7969f0a
commit 9c9a42cc49
3 changed files with 51 additions and 34 deletions

View File

@ -45,25 +45,53 @@
* *
* \sa MatrixBase::eval() * \sa MatrixBase::eval()
*/ */
template<typename Expression> class Eval : NoOperatorEquals, template<typename ExpressionType> class Eval
public Matrix< typename Expression::Scalar, : public MatrixBase<typename ExpressionType::Scalar, Eval<ExpressionType> >
Expression::Traits::RowsAtCompileTime,
Expression::Traits::ColsAtCompileTime,
EIGEN_DEFAULT_MATRIX_STORAGE_ORDER,
Expression::Traits::MaxRowsAtCompileTime,
Expression::Traits::MaxColsAtCompileTime>
{ {
public: public:
typedef typename Expression::Scalar Scalar; typedef typename ExpressionType::Scalar Scalar;
typedef Matrix<Scalar, friend class MatrixBase<Scalar, Eval>;
Expression::Traits::RowsAtCompileTime, typedef MatrixBase<Scalar, Eval> Base;
Expression::Traits::ColsAtCompileTime, friend class MatrixRef<Eval>;
EIGEN_DEFAULT_MATRIX_STORAGE_ORDER, typedef MatrixRef<Eval> Ref;
Expression::Traits::MaxRowsAtCompileTime,
Expression::Traits::MaxColsAtCompileTime> Base;
Eval() : Base() {} private:
explicit Eval(const Expression& other) : Base(other) {} enum {
RowsAtCompileTime = ExpressionType::Traits::RowsAtCompileTime,
ColsAtCompileTime = ExpressionType::Traits::ColsAtCompileTime,
MaxRowsAtCompileTime = ExpressionType::Traits::MaxRowsAtCompileTime,
MaxColsAtCompileTime = ExpressionType::Traits::MaxColsAtCompileTime
};
typedef Matrix<typename ExpressionType::Scalar,
ExpressionType::Traits::RowsAtCompileTime,
ExpressionType::Traits::ColsAtCompileTime,
EIGEN_DEFAULT_MATRIX_STORAGE_ORDER,
ExpressionType::Traits::MaxRowsAtCompileTime,
ExpressionType::Traits::MaxColsAtCompileTime> MatrixType;
int _rows() const { return m_matrix.rows(); }
int _cols() const { return m_matrix.cols(); }
Ref _ref() const { return Ref(*this); }
const Scalar& _coeff(int row, int col) const
{
return m_matrix._coeff(row, col);
}
Scalar& _coeffRef(int row, int col)
{
return m_matrix._coeffRef(row, col);
}
public:
template<typename Derived>
Eval(const MatrixBase<Scalar, Derived>& other) : m_matrix(other) {}
~Eval() {}
EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Eval)
protected:
MatrixType m_matrix;
}; };
/** Evaluates *this, which can be any expression, and returns the obtained matrix. /** Evaluates *this, which can be any expression, and returns the obtained matrix.
@ -82,7 +110,7 @@ template<typename Expression> class Eval : NoOperatorEquals,
template<typename Scalar, typename Derived> template<typename Scalar, typename Derived>
const Eval<Derived> MatrixBase<Scalar, Derived>::eval() const const Eval<Derived> MatrixBase<Scalar, Derived>::eval() const
{ {
return Eval<Derived>(*static_cast<const Derived*>(this)); return Eval<Derived>(ref());
} }
#endif // EIGEN_EVAL_H #endif // EIGEN_EVAL_H

View File

@ -61,4 +61,10 @@ struct Reference<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols
typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > Type; typedef MatrixRef<Matrix<_Scalar, _Rows, _Cols, _StorageOrder, _MaxRows, _MaxCols> > Type;
}; };
template<typename ExpressionType>
struct Reference<Eval<ExpressionType> >
{
typedef MatrixRef<Eval<ExpressionType> > Type;
};
#endif // EIGEN_FORWARDDECLARATIONS_H #endif // EIGEN_FORWARDDECLARATIONS_H

View File

@ -111,6 +111,7 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols,
typedef _Scalar Scalar; typedef _Scalar Scalar;
typedef MatrixRef<Matrix> Ref; typedef MatrixRef<Matrix> Ref;
friend class MatrixRef<Matrix>; friend class MatrixRef<Matrix>;
template<typename ExpressionType> friend class Eval;
private: private:
enum { enum {
@ -150,24 +151,6 @@ class Matrix : public MatrixBase<_Scalar, Matrix<_Scalar, _Rows, _Cols,
} }
public: public:
/** This type can be used to declare any matrix with smaller dimensions.
*/
typedef Matrix<
Scalar,
RowsAtCompileTime == 1 ? 1 : Dynamic,
ColsAtCompileTime == 1 ? 1 : Dynamic,
StorageOrder,
RowsAtCompileTime == 1 ? 1 : MaxRowsAtCompileTime,
ColsAtCompileTime == 1 ? 1 : MaxColsAtCompileTime
> BlockType;
/** This type can be used to declare a column-vector */
typedef Matrix<Scalar, RowsAtCompileTime, 1,
StorageOrder, MaxRowsAtCompileTime, 1> ColumnType;
/** This type can be used to declare a row-vector */
typedef Matrix<Scalar, 1, ColsAtCompileTime,
StorageOrder, 1, MaxColsAtCompileTime> RowType;
/** \returns a const pointer to the data array of this matrix */ /** \returns a const pointer to the data array of this matrix */
const Scalar *data() const const Scalar *data() const
{ return m_array.data(); } { return m_array.data(); }