mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-25 18:50:40 +08:00
finish making use of CoeffReadCost and the new XprCopy everywhere
seems appropriate to me.
This commit is contained in:
parent
371d302efb
commit
4920f2011e
@ -72,18 +72,25 @@ template<typename OtherDerived>
|
||||
typename ei_traits<Derived>::Scalar
|
||||
MatrixBase<Derived>::dot(const MatrixBase<OtherDerived>& other) const
|
||||
{
|
||||
typename Derived::XprCopy xprCopy(derived());
|
||||
typename OtherDerived::XprCopy otherXprCopy(other.derived());
|
||||
typedef typename Derived::XprCopy XprCopy;
|
||||
typedef typename OtherDerived::XprCopy OtherXprCopy;
|
||||
typedef typename ei_unref<XprCopy>::type _XprCopy;
|
||||
typedef typename ei_unref<OtherXprCopy>::type _OtherXprCopy;
|
||||
XprCopy xprCopy(derived());
|
||||
OtherXprCopy otherXprCopy(other.derived());
|
||||
|
||||
ei_assert(IsVectorAtCompileTime
|
||||
&& OtherDerived::IsVectorAtCompileTime
|
||||
&& xprCopy.size() == otherXprCopy.size());
|
||||
ei_assert(_XprCopy::IsVectorAtCompileTime
|
||||
&& _OtherXprCopy::IsVectorAtCompileTime
|
||||
&& xprCopy.size() == otherXprCopy.size());
|
||||
Scalar res;
|
||||
if(SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
|
||||
const bool unroll = SizeAtCompileTime
|
||||
* (_XprCopy::CoeffReadCost + _OtherXprCopy::CoeffReadCost + NumTraits<Scalar>::MulCost)
|
||||
+ (SizeAtCompileTime - 1) * NumTraits<Scalar>::AddCost
|
||||
<= EIGEN_UNROLLING_LIMIT;
|
||||
if(unroll)
|
||||
ei_dot_unroller<SizeAtCompileTime-1,
|
||||
SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT ? SizeAtCompileTime : Dynamic,
|
||||
typename ei_unref<typename Derived::XprCopy>::type,
|
||||
typename ei_unref<typename OtherDerived::XprCopy>::type>
|
||||
unroll ? SizeAtCompileTime : Dynamic,
|
||||
_XprCopy, _OtherXprCopy>
|
||||
::run(xprCopy, otherXprCopy, res);
|
||||
else
|
||||
{
|
||||
@ -142,8 +149,8 @@ template<typename OtherDerived>
|
||||
bool MatrixBase<Derived>::isOrtho
|
||||
(const MatrixBase<OtherDerived>& other, RealScalar prec) const
|
||||
{
|
||||
typename Derived::XprCopy xprCopy(derived());
|
||||
typename OtherDerived::XprCopy otherXprCopy(other.derived());
|
||||
typename ei_xpr_copy<Derived,2>::type xprCopy(derived());
|
||||
typename ei_xpr_copy<OtherDerived,2>::type otherXprCopy(other.derived());
|
||||
return ei_abs2(xprCopy.dot(otherXprCopy)) <= prec * prec * xprCopy.norm2() * otherXprCopy.norm2();
|
||||
}
|
||||
|
||||
|
@ -86,13 +86,13 @@ struct ei_traits<Product<Lhs, Rhs, EvalMode> >
|
||||
typedef typename Lhs::Scalar Scalar;
|
||||
typedef typename ei_xpr_copy<Lhs,Rhs::ColsAtCompileTime>::type LhsXprCopy;
|
||||
typedef typename ei_xpr_copy<Rhs,Lhs::RowsAtCompileTime>::type RhsXprCopy;
|
||||
typedef typename ei_unref<LhsXprCopy>::type ActualLhs;
|
||||
typedef typename ei_unref<RhsXprCopy>::type ActualRhs;
|
||||
typedef typename ei_unref<LhsXprCopy>::type _LhsXprCopy;
|
||||
typedef typename ei_unref<RhsXprCopy>::type _RhsXprCopy;
|
||||
enum {
|
||||
LhsCoeffReadCost = ActualLhs::CoeffReadCost,
|
||||
RhsCoeffReadCost = ActualRhs::CoeffReadCost,
|
||||
LhsFlags = ActualLhs::Flags,
|
||||
RhsFlags = ActualRhs::Flags,
|
||||
LhsCoeffReadCost = _LhsXprCopy::CoeffReadCost,
|
||||
RhsCoeffReadCost = _RhsXprCopy::CoeffReadCost,
|
||||
LhsFlags = _LhsXprCopy::Flags,
|
||||
RhsFlags = _RhsXprCopy::Flags,
|
||||
RowsAtCompileTime = Lhs::RowsAtCompileTime,
|
||||
ColsAtCompileTime = Rhs::ColsAtCompileTime,
|
||||
MaxRowsAtCompileTime = Lhs::MaxRowsAtCompileTime,
|
||||
@ -117,9 +117,10 @@ template<typename Lhs, typename Rhs, int EvalMode> class Product : ei_no_assignm
|
||||
public:
|
||||
|
||||
EIGEN_GENERIC_PUBLIC_INTERFACE(Product)
|
||||
|
||||
typedef typename ei_traits<Product>::LhsXprCopy LhsXprCopy;
|
||||
typedef typename ei_traits<Product>::RhsXprCopy RhsXprCopy;
|
||||
typedef typename ei_traits<Product>::_LhsXprCopy _LhsXprCopy;
|
||||
typedef typename ei_traits<Product>::_RhsXprCopy _RhsXprCopy;
|
||||
|
||||
Product(const Lhs& lhs, const Rhs& rhs)
|
||||
: m_lhs(lhs), m_rhs(rhs)
|
||||
@ -144,8 +145,7 @@ template<typename Lhs, typename Rhs, int EvalMode> class Product : ei_no_assignm
|
||||
{
|
||||
ei_product_unroller<Lhs::ColsAtCompileTime-1,
|
||||
unroll ? Lhs::ColsAtCompileTime : Dynamic,
|
||||
typename ei_unref<LhsXprCopy>::type,
|
||||
typename ei_unref<RhsXprCopy>::type>
|
||||
_LhsXprCopy, _RhsXprCopy>
|
||||
::run(row, col, m_lhs, m_rhs, res);
|
||||
}
|
||||
else
|
||||
|
@ -87,15 +87,19 @@ struct ei_traits<PartialRedux<Direction, BinaryOp, MatrixType> >
|
||||
typedef typename ei_result_of<
|
||||
BinaryOp(typename MatrixType::Scalar)
|
||||
>::type Scalar;
|
||||
typedef typename ei_xpr_copy<MatrixType>::type MatrixTypeXprCopy;
|
||||
typedef typename ei_unref<MatrixTypeXprCopy>::type _MatrixTypeXprCopy;
|
||||
enum {
|
||||
RowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::RowsAtCompileTime,
|
||||
ColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::ColsAtCompileTime,
|
||||
MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime,
|
||||
MaxRowsAtCompileTime = Direction==Vertical ? 1 : MatrixType::MaxRowsAtCompileTime,
|
||||
MaxColsAtCompileTime = Direction==Horizontal ? 1 : MatrixType::MaxColsAtCompileTime,
|
||||
Flags = (RowsAtCompileTime == Dynamic || ColsAtCompileTime == Dynamic)
|
||||
? (unsigned int)MatrixType::Flags
|
||||
: (unsigned int)MatrixType::Flags & ~LargeBit,
|
||||
CoeffReadCost = 1 //FIXME -- unimplemented!
|
||||
? (unsigned int)_MatrixTypeXprCopy::Flags
|
||||
: (unsigned int)_MatrixTypeXprCopy::Flags & ~LargeBit,
|
||||
TraversalSize = Direction==Vertical ? RowsAtCompileTime : ColsAtCompileTime,
|
||||
CoeffReadCost = TraversalSize * _MatrixTypeXprCopy::CoeffReadCost
|
||||
+ (TraversalSize - 1) * ei_functor_traits<BinaryOp>::Cost
|
||||
};
|
||||
};
|
||||
|
||||
@ -106,6 +110,8 @@ class PartialRedux : ei_no_assignment_operator,
|
||||
public:
|
||||
|
||||
EIGEN_GENERIC_PUBLIC_INTERFACE(PartialRedux)
|
||||
typedef typename ei_traits<PartialRedux>::MatrixTypeXprCopy MatrixTypeXprCopy;
|
||||
typedef typename ei_traits<PartialRedux>::_MatrixTypeXprCopy _MatrixTypeXprCopy;
|
||||
|
||||
PartialRedux(const MatrixType& mat, const BinaryOp& func = BinaryOp())
|
||||
: m_matrix(mat), m_functor(func) {}
|
||||
@ -124,7 +130,7 @@ class PartialRedux : ei_no_assignment_operator,
|
||||
}
|
||||
|
||||
protected:
|
||||
const typename MatrixType::XprCopy m_matrix;
|
||||
const MatrixTypeXprCopy m_matrix;
|
||||
const BinaryOp m_functor;
|
||||
};
|
||||
|
||||
@ -171,10 +177,13 @@ template<typename BinaryOp>
|
||||
typename ei_result_of<BinaryOp(typename ei_traits<Derived>::Scalar)>::type
|
||||
MatrixBase<Derived>::redux(const BinaryOp& func) const
|
||||
{
|
||||
if(SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
|
||||
const bool unroll = SizeAtCompileTime * CoeffReadCost
|
||||
+ (SizeAtCompileTime-1) * ei_functor_traits<BinaryOp>::Cost
|
||||
<= EIGEN_UNROLLING_LIMIT;
|
||||
if(unroll)
|
||||
return ei_redux_unroller<BinaryOp, Derived, 0,
|
||||
(SizeAtCompileTime>0 && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) ?
|
||||
SizeAtCompileTime : Dynamic>::run(derived(), func);
|
||||
unroll ? SizeAtCompileTime : Dynamic>
|
||||
::run(derived(), func);
|
||||
else
|
||||
{
|
||||
Scalar res;
|
||||
@ -291,10 +300,12 @@ struct ei_any_unroller<Derived, Dynamic>
|
||||
template<typename Derived>
|
||||
bool MatrixBase<Derived>::all(void) const
|
||||
{
|
||||
if(SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
|
||||
const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost)
|
||||
<= EIGEN_UNROLLING_LIMIT;
|
||||
if(unroll)
|
||||
return ei_all_unroller<Derived,
|
||||
(SizeAtCompileTime>0 && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) ?
|
||||
SizeAtCompileTime : Dynamic>::run(derived());
|
||||
unroll ? SizeAtCompileTime : Dynamic
|
||||
>::run(derived());
|
||||
else
|
||||
{
|
||||
for(int j = 0; j < cols(); j++)
|
||||
@ -311,10 +322,12 @@ bool MatrixBase<Derived>::all(void) const
|
||||
template<typename Derived>
|
||||
bool MatrixBase<Derived>::any(void) const
|
||||
{
|
||||
if(SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
|
||||
const bool unroll = SizeAtCompileTime * (CoeffReadCost + NumTraits<Scalar>::AddCost)
|
||||
<= EIGEN_UNROLLING_LIMIT;
|
||||
if(unroll)
|
||||
return ei_any_unroller<Derived,
|
||||
(SizeAtCompileTime>0 && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) ?
|
||||
SizeAtCompileTime : Dynamic>::run(derived());
|
||||
unroll ? SizeAtCompileTime : Dynamic
|
||||
>::run(derived());
|
||||
else
|
||||
{
|
||||
for(int j = 0; j < cols(); j++)
|
||||
|
@ -74,10 +74,13 @@ template<typename Derived>
|
||||
template<typename Visitor>
|
||||
void MatrixBase<Derived>::visit(Visitor& visitor) const
|
||||
{
|
||||
if(SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT)
|
||||
const bool unroll = SizeAtCompileTime * CoeffReadCost
|
||||
+ (SizeAtCompileTime-1) * ei_functor_traits<Visitor>::Cost
|
||||
<= EIGEN_UNROLLING_LIMIT;
|
||||
if(unroll)
|
||||
return ei_visitor_unroller<Visitor, Derived,
|
||||
(SizeAtCompileTime>0 && SizeAtCompileTime <= EIGEN_UNROLLING_LIMIT) ?
|
||||
SizeAtCompileTime : Dynamic>::run(derived(), visitor);
|
||||
unroll ? SizeAtCompileTime : Dynamic
|
||||
>::run(derived(), visitor);
|
||||
else
|
||||
{
|
||||
visitor.init(coeff(0,0), 0, 0);
|
||||
@ -124,6 +127,13 @@ struct ei_min_coeff_visitor : ei_coeff_visitor<Scalar>
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_functor_traits<ei_min_coeff_visitor<Scalar> > {
|
||||
enum {
|
||||
Cost = NumTraits<Scalar>::AddCost
|
||||
};
|
||||
};
|
||||
|
||||
/** \internal
|
||||
* \brief Visitor computing the max coefficient with its value and coordinates
|
||||
*
|
||||
@ -143,6 +153,13 @@ struct ei_max_coeff_visitor : ei_coeff_visitor<Scalar>
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Scalar>
|
||||
struct ei_functor_traits<ei_max_coeff_visitor<Scalar> > {
|
||||
enum {
|
||||
Cost = NumTraits<Scalar>::AddCost
|
||||
};
|
||||
};
|
||||
|
||||
/** \returns the minimum of all coefficients of *this
|
||||
* and puts in *row and *col its location.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user