mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-15 07:10:37 +08:00
some reorganization leading to simpler expression trees
This commit is contained in:
parent
aa3294f14e
commit
51e29ae4bd
@ -75,10 +75,10 @@ template<typename MatrixType> class EiBlock
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiBlock<EiObject<Scalar, Derived> >
|
||||
EiBlock<Derived>
|
||||
EiObject<Scalar, Derived>::block(int startRow, int endRow, int startCol, int endCol)
|
||||
{
|
||||
return EiBlock<EiObject>(ref(), startRow, endRow, startCol, endCol);
|
||||
return EiBlock<Derived>(static_cast<Derived*>(this)->ref(), startRow, endRow, startCol, endCol);
|
||||
}
|
||||
|
||||
#endif // EI_BLOCK_H
|
||||
|
@ -28,15 +28,14 @@
|
||||
|
||||
template<typename Expression> class EiEval
|
||||
: public EiMatrix< typename Expression::Scalar,
|
||||
Expression::Derived::RowsAtCompileTime,
|
||||
Expression::Derived::ColsAtCompileTime >
|
||||
Expression::RowsAtCompileTime,
|
||||
Expression::ColsAtCompileTime >
|
||||
{
|
||||
public:
|
||||
typedef typename Expression::Scalar Scalar;
|
||||
typedef typename Expression::Derived Derived;
|
||||
typedef EiMatrix< Scalar, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> MatrixType;
|
||||
typedef EiMatrix< Scalar, Expression::RowsAtCompileTime, Expression::ColsAtCompileTime> MatrixType;
|
||||
typedef Expression Base;
|
||||
friend class EiObject<Scalar, Derived>;
|
||||
friend class EiObject<Scalar, Expression>;
|
||||
|
||||
EI_INHERIT_ASSIGNMENT_OPERATORS(EiEval)
|
||||
|
||||
@ -44,9 +43,9 @@ template<typename Expression> class EiEval
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiEval<EiObject<Scalar, Derived> > EiObject<Scalar, Derived>::eval() const
|
||||
EiEval<Derived> EiObject<Scalar, Derived>::eval() const
|
||||
{
|
||||
return EiEval<EiObject<Scalar, Derived> >(*this);
|
||||
return EiEval<Derived>(*static_cast<const Derived*>(this));
|
||||
}
|
||||
|
||||
#endif // EI_EVAL_H
|
||||
|
@ -71,10 +71,10 @@ template<typename MatrixType> class EiMinor
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiMinor<EiObject<Scalar, Derived> >
|
||||
EiMinor<Derived>
|
||||
EiObject<Scalar, Derived>::minor(int row, int col)
|
||||
{
|
||||
return EiMinor<EiObject>(ref(), row, col);
|
||||
return EiMinor<Derived>(static_cast<Derived*>(this)->ref(), row, col);
|
||||
}
|
||||
|
||||
#endif // EI_MINOR_H
|
||||
|
@ -28,14 +28,21 @@
|
||||
|
||||
#include "Util.h"
|
||||
|
||||
template<typename _Scalar, typename _Derived> class EiObject
|
||||
template<typename Scalar, typename Derived> class EiObject
|
||||
{
|
||||
static const int RowsAtCompileTime = _Derived::RowsAtCompileTime,
|
||||
ColsAtCompileTime = _Derived::ColsAtCompileTime;
|
||||
static const int RowsAtCompileTime = Derived::RowsAtCompileTime,
|
||||
ColsAtCompileTime = Derived::ColsAtCompileTime;
|
||||
|
||||
template<typename OtherDerived>
|
||||
void _copy_helper(const EiObject<Scalar, OtherDerived>& other)
|
||||
{
|
||||
for(int i = 0; i < rows(); i++)
|
||||
for(int j = 0; j < cols(); j++)
|
||||
write(i, j) = other.read(i, j);
|
||||
}
|
||||
|
||||
public:
|
||||
typedef typename EiForwardDecl<_Derived>::Ref Ref;
|
||||
typedef _Scalar Scalar;
|
||||
typedef _Derived Derived;
|
||||
typedef typename EiForwardDecl<Derived>::Ref Ref;
|
||||
|
||||
int rows() const { return static_cast<const Derived *>(this)->_rows(); }
|
||||
int cols() const { return static_cast<const Derived *>(this)->_cols(); }
|
||||
@ -61,9 +68,7 @@ template<typename _Scalar, typename _Derived> class EiObject
|
||||
Derived& operator=(const EiObject<Scalar, OtherDerived>& other)
|
||||
{
|
||||
assert(rows() == other.rows() && cols() == other.cols());
|
||||
for(int i = 0; i < rows(); i++)
|
||||
for(int j = 0; j < cols(); j++)
|
||||
write(i, j) = other.read(i, j);
|
||||
_copy_helper(other);
|
||||
return *static_cast<Derived*>(this);
|
||||
}
|
||||
|
||||
@ -72,17 +77,14 @@ template<typename _Scalar, typename _Derived> class EiObject
|
||||
Derived& operator=(const EiObject& other)
|
||||
{
|
||||
assert(rows() == other.rows() && cols() == other.cols());
|
||||
for(int i = 0; i < rows(); i++)
|
||||
for(int j = 0; j < cols(); j++)
|
||||
write(i, j) = other.read(i, j);
|
||||
_copy_helper(other);
|
||||
return *static_cast<Derived*>(this);
|
||||
}
|
||||
|
||||
EiRow<EiObject> row(int i);
|
||||
EiColumn<EiObject> col(int i);
|
||||
EiMinor<EiObject> minor(int row, int col);
|
||||
EiBlock<EiObject>
|
||||
block(int startRow, int endRow, int startCol= 0, int endCol = 0);
|
||||
EiRow<Derived> row(int i);
|
||||
EiColumn<Derived> col(int i);
|
||||
EiMinor<Derived> minor(int row, int col);
|
||||
EiBlock<Derived> block(int startRow, int endRow, int startCol= 0, int endCol = 0);
|
||||
|
||||
template<typename OtherDerived>
|
||||
Derived& operator+=(const EiObject<Scalar, OtherDerived>& other);
|
||||
@ -111,7 +113,7 @@ template<typename _Scalar, typename _Derived> class EiObject
|
||||
Scalar& operator()(int row, int col = 0)
|
||||
{ return write(row, col); }
|
||||
|
||||
EiEval<EiObject> eval() const;
|
||||
EiEval<Derived> eval() const;
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
|
@ -128,17 +128,17 @@ template<typename MatrixType> class EiColumn
|
||||
};
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiRow<EiObject<Scalar, Derived> >
|
||||
EiRow<Derived>
|
||||
EiObject<Scalar, Derived>::row(int i)
|
||||
{
|
||||
return EiRow<EiObject>(ref(), i);
|
||||
return EiRow<Derived>(static_cast<Derived*>(this)->ref(), i);
|
||||
}
|
||||
|
||||
template<typename Scalar, typename Derived>
|
||||
EiColumn<EiObject<Scalar, Derived> >
|
||||
EiColumn<Derived>
|
||||
EiObject<Scalar, Derived>::col(int i)
|
||||
{
|
||||
return EiColumn<EiObject>(ref(), i);
|
||||
return EiColumn<Derived>(static_cast<Derived*>(this)->ref(), i);
|
||||
}
|
||||
|
||||
#endif // EI_ROWANDCOL_H
|
||||
|
Loading…
Reference in New Issue
Block a user