This commit is contained in:
Gael Guennebaud 2014-08-29 15:31:54 +02:00
commit b4a709520d
3 changed files with 19 additions and 13 deletions

View File

@ -449,7 +449,7 @@ template<typename Derived>
EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
DenseBase<Derived>::minCoeff() const DenseBase<Derived>::minCoeff() const
{ {
return this->redux(Eigen::internal::scalar_min_op<Scalar>()); return derived().redux(Eigen::internal::scalar_min_op<Scalar>());
} }
/** \returns the maximum of all coefficients of \c *this. /** \returns the maximum of all coefficients of \c *this.
@ -459,7 +459,7 @@ template<typename Derived>
EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
DenseBase<Derived>::maxCoeff() const DenseBase<Derived>::maxCoeff() const
{ {
return this->redux(Eigen::internal::scalar_max_op<Scalar>()); return derived().redux(Eigen::internal::scalar_max_op<Scalar>());
} }
/** \returns the sum of all coefficients of *this /** \returns the sum of all coefficients of *this
@ -472,7 +472,7 @@ DenseBase<Derived>::sum() const
{ {
if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0)) if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0))
return Scalar(0); return Scalar(0);
return this->redux(Eigen::internal::scalar_sum_op<Scalar>()); return derived().redux(Eigen::internal::scalar_sum_op<Scalar>());
} }
/** \returns the mean of all coefficients of *this /** \returns the mean of all coefficients of *this
@ -483,7 +483,7 @@ template<typename Derived>
EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar EIGEN_STRONG_INLINE typename internal::traits<Derived>::Scalar
DenseBase<Derived>::mean() const DenseBase<Derived>::mean() const
{ {
return Scalar(this->redux(Eigen::internal::scalar_sum_op<Scalar>())) / Scalar(this->size()); return Scalar(derived().redux(Eigen::internal::scalar_sum_op<Scalar>())) / Scalar(this->size());
} }
/** \returns the product of all coefficients of *this /** \returns the product of all coefficients of *this
@ -499,7 +499,7 @@ DenseBase<Derived>::prod() const
{ {
if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0)) if(SizeAtCompileTime==0 || (SizeAtCompileTime==Dynamic && size()==0))
return Scalar(1); return Scalar(1);
return this->redux(Eigen::internal::scalar_product_op<Scalar>()); return derived().redux(Eigen::internal::scalar_product_op<Scalar>());
} }
/** \returns the trace of \c *this, i.e. the sum of the coefficients on the main diagonal. /** \returns the trace of \c *this, i.e. the sum of the coefficients on the main diagonal.

View File

@ -138,6 +138,13 @@ template<typename MatrixType,int _Direction> class Homogeneous
} }
#endif #endif
template<typename Func>
EIGEN_STRONG_INLINE typename internal::result_of<Func(Scalar)>::type
redux(const Func& func) const
{
return func(m_matrix.redux(func), Scalar(1));
}
protected: protected:
typename MatrixType::Nested m_matrix; typename MatrixType::Nested m_matrix;
}; };
@ -351,6 +358,9 @@ struct unary_evaluator<Homogeneous<ArgType,Direction>, IndexBased>
typedef Homogeneous<ArgType,Direction> XprType; typedef Homogeneous<ArgType,Direction> XprType;
typedef typename XprType::PlainObject PlainObject; typedef typename XprType::PlainObject PlainObject;
typedef typename evaluator<PlainObject>::type Base; typedef typename evaluator<PlainObject>::type Base;
typedef evaluator<XprType> type;
typedef evaluator<XprType> nestedType;
unary_evaluator(const XprType& op) unary_evaluator(const XprType& op)
: Base(), m_temp(op) : Base(), m_temp(op)
@ -367,10 +377,6 @@ template< typename DstXprType, typename ArgType, typename Scalar>
struct Assignment<DstXprType, Homogeneous<ArgType,Vertical>, internal::assign_op<Scalar>, Dense2Dense, Scalar> struct Assignment<DstXprType, Homogeneous<ArgType,Vertical>, internal::assign_op<Scalar>, Dense2Dense, Scalar>
{ {
typedef Homogeneous<ArgType,Vertical> SrcXprType; typedef Homogeneous<ArgType,Vertical> SrcXprType;
// TODO clang generates garbage if this function is inlined. no valgrind error though.
#ifdef __clang__
EIGEN_DONT_INLINE
#endif
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar> &) static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar> &)
{ {
dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression(); dst.template topRows<ArgType::RowsAtCompileTime>(src.nestedExpression().rows()) = src.nestedExpression();
@ -383,10 +389,6 @@ template< typename DstXprType, typename ArgType, typename Scalar>
struct Assignment<DstXprType, Homogeneous<ArgType,Horizontal>, internal::assign_op<Scalar>, Dense2Dense, Scalar> struct Assignment<DstXprType, Homogeneous<ArgType,Horizontal>, internal::assign_op<Scalar>, Dense2Dense, Scalar>
{ {
typedef Homogeneous<ArgType,Horizontal> SrcXprType; typedef Homogeneous<ArgType,Horizontal> SrcXprType;
// TODO clang generates garbage if this function is inlined. no valgrind error though.
#ifdef __clang__
EIGEN_DONT_INLINE
#endif
static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar> &) static void run(DstXprType &dst, const SrcXprType &src, const internal::assign_op<Scalar> &)
{ {
dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression(); dst.template leftCols<ArgType::ColsAtCompileTime>(src.nestedExpression().cols()) = src.nestedExpression();

View File

@ -38,6 +38,10 @@ template<typename Scalar,int Size> void homogeneous(void)
hv0 << v0, 1; hv0 << v0, 1;
VERIFY_IS_APPROX(v0.homogeneous(), hv0); VERIFY_IS_APPROX(v0.homogeneous(), hv0);
VERIFY_IS_APPROX(v0, hv0.hnormalized()); VERIFY_IS_APPROX(v0, hv0.hnormalized());
VERIFY_IS_APPROX(v0.homogeneous().sum(), hv0.sum());
VERIFY_IS_APPROX(v0.homogeneous().minCoeff(), hv0.minCoeff());
VERIFY_IS_APPROX(v0.homogeneous().maxCoeff(), hv0.maxCoeff());
hm0 << m0, ones.transpose(); hm0 << m0, ones.transpose();
VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0); VERIFY_IS_APPROX(m0.colwise().homogeneous(), hm0);