* ReturnByValue:

-- simpplify by removing the 2nd template parameter
  -- rename Functor to Derived, as now it's a usual CRTP
* Homogeneous:
  -- in products, honor the Max sizes etc.
This commit is contained in:
Benoit Jacob 2009-09-22 12:20:45 -04:00
parent 1df54e3ac2
commit c1c780a94f
7 changed files with 51 additions and 41 deletions

View File

@ -399,8 +399,8 @@ class Matrix
return Base::lazyAssign(other.derived());
}
template<typename OtherDerived,typename OtherEvalType>
EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived,OtherEvalType>& func)
template<typename OtherDerived>
EIGEN_STRONG_INLINE Matrix& operator=(const ReturnByValue<OtherDerived>& func)
{
resize(func.rows(), func.cols());
return Base::operator=(func);
@ -504,8 +504,8 @@ class Matrix
_set_noalias(other);
}
/** Copy constructor with in-place evaluation */
template<typename OtherDerived,typename OtherEvalType>
EIGEN_STRONG_INLINE Matrix(const ReturnByValue<OtherDerived,OtherEvalType>& other)
template<typename OtherDerived>
EIGEN_STRONG_INLINE Matrix(const ReturnByValue<OtherDerived>& other)
{
_check_template_params();
resize(other.rows(), other.cols());

View File

@ -271,8 +271,8 @@ template<typename Derived> class MatrixBase
template<typename OtherDerived>
Derived& operator-=(const AnyMatrixBase<OtherDerived> &other);
template<typename OtherDerived,typename OtherEvalType>
Derived& operator=(const ReturnByValue<OtherDerived,OtherEvalType>& func);
template<typename OtherDerived>
Derived& operator=(const ReturnByValue<OtherDerived>& func);
#ifndef EIGEN_PARSED_BY_DOXYGEN
/** Copies \a other into *this without evaluating other. \returns a reference to *this. */

View File

@ -28,45 +28,37 @@
/** \class ReturnByValue
*
*/
template<typename Functor, typename _Scalar,int _Rows,int _Cols,int _Options,int _MaxRows,int _MaxCols>
struct ei_traits<ReturnByValue<Functor,Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> > >
: public ei_traits<Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> >
template<typename Derived>
struct ei_traits<ReturnByValue<Derived> >
: public ei_traits<typename ei_traits<Derived>::ReturnMatrixType>
{
enum {
Flags = ei_traits<Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> >::Flags | EvalBeforeNestingBit
Flags = ei_traits<typename ei_traits<Derived>::ReturnMatrixType>::Flags | EvalBeforeNestingBit
};
};
template<typename Functor,typename EvalTypeDerived,int n>
struct ei_nested<ReturnByValue<Functor,MatrixBase<EvalTypeDerived> >, n, EvalTypeDerived>
template<typename Derived,int n,typename PlainMatrixType>
struct ei_nested<ReturnByValue<Derived>, n, PlainMatrixType>
{
typedef EvalTypeDerived type;
typedef typename ei_traits<Derived>::ReturnMatrixType type;
};
template<typename Functor, typename EvalType> class ReturnByValue
template<typename Derived>
class ReturnByValue : public MatrixBase<ReturnByValue<Derived> >
{
public:
template<typename Dest> inline void evalTo(Dest& dst) const
{ static_cast<const Functor*>(this)->evalTo(dst); }
};
template<typename Functor, typename _Scalar,int _Rows,int _Cols,int _Options,int _MaxRows,int _MaxCols>
class ReturnByValue<Functor,Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> >
: public MatrixBase<ReturnByValue<Functor,Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> > >
{
typedef Matrix<_Scalar,_Rows,_Cols,_Options,_MaxRows,_MaxCols> EvalType;
typedef typename ei_traits<Derived>::ReturnMatrixType ReturnMatrixType;
public:
EIGEN_GENERIC_PUBLIC_INTERFACE(ReturnByValue)
template<typename Dest>
inline void evalTo(Dest& dst) const
{ static_cast<const Functor* const>(this)->evalTo(dst); }
inline int rows() const { return static_cast<const Functor* const>(this)->rows(); }
inline int cols() const { return static_cast<const Functor* const>(this)->cols(); }
{ static_cast<const Derived* const>(this)->evalTo(dst); }
inline int rows() const { return static_cast<const Derived* const>(this)->rows(); }
inline int cols() const { return static_cast<const Derived* const>(this)->cols(); }
};
template<typename Derived>
template<typename OtherDerived,typename OtherEvalType>
Derived& MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived,OtherEvalType>& other)
template<typename OtherDerived>
Derived& MatrixBase<Derived>::operator=(const ReturnByValue<OtherDerived>& other)
{
other.evalTo(derived());
return derived();

View File

@ -64,7 +64,7 @@ template<typename MatrixType, unsigned int Mode> class SelfAdjointView;
template<typename ExpressionType> class Cwise;
template<typename ExpressionType> class WithFormat;
template<typename MatrixType> struct CommaInitializer;
template<typename Functor, typename EvalType> class ReturnByValue;
template<typename Derived> class ReturnByValue;
template<typename _Scalar, int Rows=Dynamic, int Cols=Dynamic, int Supers=Dynamic, int Subs=Dynamic, int Options=0> class BandMatrix;

View File

@ -206,11 +206,20 @@ VectorwiseOp<ExpressionType,Direction>::hnormalized() const
Direction==Horizontal ? _expression().cols()-1 : 1).nestByValue();
}
template<typename MatrixType,typename Lhs>
struct ei_traits<ei_homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
{
typedef Matrix<typename ei_traits<MatrixType>::Scalar,
Lhs::RowsAtCompileTime,
MatrixType::ColsAtCompileTime,
MatrixType::PlainMatrixType::Options,
Lhs::MaxRowsAtCompileTime,
MatrixType::MaxColsAtCompileTime> ReturnMatrixType;
};
template<typename MatrixType,typename Lhs>
struct ei_homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs>
: public ReturnByValue<ei_homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs>,
Matrix<typename ei_traits<MatrixType>::Scalar,
Lhs::RowsAtCompileTime,MatrixType::ColsAtCompileTime> >
: public ReturnByValue<ei_homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs> >
{
typedef typename ei_cleantype<typename Lhs::Nested>::type LhsNested;
ei_homogeneous_left_product_impl(const Lhs& lhs, const MatrixType& rhs)
@ -235,11 +244,20 @@ struct ei_homogeneous_left_product_impl<Homogeneous<MatrixType,Vertical>,Lhs>
const typename MatrixType::Nested m_rhs;
};
template<typename MatrixType,typename Rhs>
struct ei_traits<ei_homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
{
typedef Matrix<typename ei_traits<MatrixType>::Scalar,
MatrixType::RowsAtCompileTime,
Rhs::ColsAtCompileTime,
MatrixType::PlainMatrixType::Options,
MatrixType::MaxRowsAtCompileTime,
Rhs::MaxColsAtCompileTime> ReturnMatrixType;
};
template<typename MatrixType,typename Rhs>
struct ei_homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs>
: public ReturnByValue<ei_homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs>,
Matrix<typename ei_traits<MatrixType>::Scalar,
MatrixType::RowsAtCompileTime, Rhs::ColsAtCompileTime> >
: public ReturnByValue<ei_homogeneous_right_product_impl<Homogeneous<MatrixType,Horizontal>,Rhs> >
{
typedef typename ei_cleantype<typename Rhs::Nested>::type RhsNested;
ei_homogeneous_right_product_impl(const MatrixType& lhs, const Rhs& rhs)

View File

@ -247,14 +247,14 @@ public:
ei_transform_construct_from_matrix<OtherMatrixType,Mode,Dim,HDim>::run(this, other.matrix());
}
template<typename OtherDerived,typename OtherEvalType>
Transform(const ReturnByValue<OtherDerived,OtherEvalType>& other)
template<typename OtherDerived>
Transform(const ReturnByValue<OtherDerived>& other)
{
other.evalTo(*this);
}
template<typename OtherDerived,typename OtherEvalType>
Transform& operator=(const ReturnByValue<OtherDerived,OtherEvalType>& other)
template<typename OtherDerived>
Transform& operator=(const ReturnByValue<OtherDerived>& other)
{
other.evalTo(*this);
return *this;

View File

@ -97,7 +97,7 @@ template<typename Scalar,int Size> void homogeneous(void)
pts.setRandom(Size,5);
Rt_pts1 = Rt * pts.colwise().homogeneous();
std::cerr << (Rt_pts1 - pts).sum() << "\n";
// std::cerr << (Rt_pts1 - pts).sum() << "\n";
VERIFY_IS_MUCH_SMALLER_THAN( (Rt_pts1 - pts).sum(), Scalar(1));
}