* make sum and redux honor EvalBeforeNestingBit too

* fix MSVC issues (hopefully)
This commit is contained in:
Gael Guennebaud 2009-01-28 21:09:08 +00:00
parent cc6159743d
commit 42b237b83a
3 changed files with 25 additions and 38 deletions

View File

@ -38,6 +38,27 @@ class DiagonalMatrixBase : ei_no_assignment_operator,
protected:
typedef typename ei_cleantype<CoeffsVectorType>::type _CoeffsVectorType;
template<typename OtherDerived,
bool IsVector = OtherDerived::IsVectorAtCompileTime,
bool IsDiagonal = (OtherDerived::Flags&Diagonal)==Diagonal>
struct construct_from_expression;
// = vector
template<typename OtherDerived>
struct construct_from_expression<OtherDerived,true,false>
{
static void run(Derived& dst, const OtherDerived& src)
{ dst.diagonal() = src; }
};
// = diagonal expression
template<typename OtherDerived, bool IsVector>
struct construct_from_expression<OtherDerived,IsVector,true>
{
static void run(Derived& dst, const OtherDerived& src)
{ dst.diagonal() = src.diagonal(); }
};
/** Default constructor without initialization */
inline DiagonalMatrixBase() {}
@ -50,27 +71,6 @@ class DiagonalMatrixBase : ei_no_assignment_operator,
construct_from_expression<OtherDerived>::run(derived(),other.derived());
}
template<typename OtherDerived,
bool IsVector = OtherDerived::IsVectorAtCompileTime,
bool IsDiagonal = (OtherDerived::Flags&Diagonal)==Diagonal>
struct construct_from_expression;
// = vector
template<typename OtherDerived>
struct construct_from_expression<OtherDerived,true,false>
{
static void run(Derived& dst, const OtherDerived& src)
{ dst.m_coeffs = src; }
};
// = diagonal
template<typename OtherDerived, bool IsVector>
struct construct_from_expression<OtherDerived,IsVector,true>
{
static void run(Derived& dst, const OtherDerived& src)
{ dst.m_coeffs = src.diagonal(); }
};
public:
inline DiagonalMatrixBase(const _CoeffsVectorType& coeffs) : m_coeffs(coeffs)
@ -79,21 +79,6 @@ class DiagonalMatrixBase : ei_no_assignment_operator,
ei_assert(coeffs.size() > 0);
}
template<typename OtherDerived, bool IsVector=OtherDerived::IsVectorAtCompileTime>
struct ei_diagonal_product_ctor {
static void run(DiagonalMatrixBase& dst, const OtherDerived& src)
{ dst.m_coeffs = src; }
};
template<typename OtherDerived>
struct ei_diagonal_product_ctor<OtherDerived,false> {
static void run(DiagonalMatrixBase& dst, const OtherDerived& src)
{
EIGEN_STATIC_ASSERT((OtherDerived::Flags&Diagonal)==Diagonal, THIS_METHOD_IS_ONLY_FOR_DIAGONAL_MATRIX);
dst.m_coeffs = src.diagonal();
}
};
template<typename NewType>
inline DiagonalMatrixWrapper<NestByValue<CwiseUnaryOp<ei_scalar_cast_op<Scalar, NewType>, _CoeffsVectorType> > > cast() const
{

View File

@ -92,7 +92,8 @@ MatrixBase<Derived>::redux(const BinaryOp& func) const
const bool unroll = SizeAtCompileTime * CoeffReadCost
+ (SizeAtCompileTime-1) * ei_functor_traits<BinaryOp>::Cost
<= EIGEN_UNROLLING_LIMIT;
return ei_redux_impl<BinaryOp, Derived, 0, unroll ? int(SizeAtCompileTime) : Dynamic>
typedef typename ei_cleantype<typename Derived::Nested>::type ThisNested;
return ei_redux_impl<BinaryOp, ThisNested, 0, unroll ? int(SizeAtCompileTime) : Dynamic>
::run(derived(), func);
}

View File

@ -252,7 +252,8 @@ template<typename Derived>
inline typename ei_traits<Derived>::Scalar
MatrixBase<Derived>::sum() const
{
return ei_sum_impl<Derived>::run(derived());
typedef typename ei_cleantype<typename Derived::Nested>::type ThisNested;
return ei_sum_impl<ThisNested>::run(derived());
}
/** \returns the trace of \c *this, i.e. the sum of the coefficients on the main diagonal.