Fix evaluators unit test (i.e., when only EIGEN_ENABLE_EVALUATORS is defined

This commit is contained in:
Gael Guennebaud 2014-03-10 09:28:00 +01:00
parent cbc572caf7
commit 5c0f294098
6 changed files with 67 additions and 52 deletions

View File

@ -353,10 +353,13 @@ template<typename Lhs, typename Rhs>
struct traits<GeneralProduct<Lhs,Rhs,GemvProduct> >
: traits<ProductBase<GeneralProduct<Lhs,Rhs,GemvProduct>, Lhs, Rhs> >
{};
#endif
template<int Side, int StorageOrder, bool BlasCompatible>
struct gemv_selector;
#endif
#ifdef EIGEN_ENABLE_EVALUATORS
template<int Side, int StorageOrder, bool BlasCompatible>
struct gemv_dense_sense_selector;
#endif
} // end namespace internal
@ -594,23 +597,25 @@ template<> struct gemv_selector<OnTheRight,RowMajor,false>
}
};
#else // EIGEN_TEST_EVALUATORS
#endif // EIGEN_TEST_EVALUATORS
#ifdef EIGEN_ENABLE_EVALUATORS
// The vector is on the left => transposition
template<int StorageOrder, bool BlasCompatible>
struct gemv_selector<OnTheLeft,StorageOrder,BlasCompatible>
struct gemv_dense_sense_selector<OnTheLeft,StorageOrder,BlasCompatible>
{
template<typename Lhs, typename Rhs, typename Dest>
static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
{
Transpose<Dest> destT(dest);
enum { OtherStorageOrder = StorageOrder == RowMajor ? ColMajor : RowMajor };
gemv_selector<OnTheRight,OtherStorageOrder,BlasCompatible>
gemv_dense_sense_selector<OnTheRight,OtherStorageOrder,BlasCompatible>
::run(rhs.transpose(), lhs.transpose(), destT, alpha);
}
};
template<> struct gemv_selector<OnTheRight,ColMajor,true>
template<> struct gemv_dense_sense_selector<OnTheRight,ColMajor,true>
{
template<typename Lhs, typename Rhs, typename Dest>
static inline void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
@ -685,7 +690,7 @@ template<> struct gemv_selector<OnTheRight,ColMajor,true>
}
};
template<> struct gemv_selector<OnTheRight,RowMajor,true>
template<> struct gemv_dense_sense_selector<OnTheRight,RowMajor,true>
{
template<typename Lhs, typename Rhs, typename Dest>
static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
@ -737,7 +742,7 @@ template<> struct gemv_selector<OnTheRight,RowMajor,true>
}
};
template<> struct gemv_selector<OnTheRight,ColMajor,false>
template<> struct gemv_dense_sense_selector<OnTheRight,ColMajor,false>
{
template<typename Lhs, typename Rhs, typename Dest>
static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
@ -750,7 +755,7 @@ template<> struct gemv_selector<OnTheRight,ColMajor,false>
}
};
template<> struct gemv_selector<OnTheRight,RowMajor,false>
template<> struct gemv_dense_sense_selector<OnTheRight,RowMajor,false>
{
template<typename Lhs, typename Rhs, typename Dest>
static void run(const Lhs &lhs, const Rhs &rhs, Dest& dest, const typename Dest::Scalar& alpha)
@ -763,7 +768,7 @@ template<> struct gemv_selector<OnTheRight,RowMajor,false>
}
};
#endif // EIGEN_TEST_EVALUATORS
#endif // EIGEN_ENABLE_EVALUATORS
} // end namespace internal

View File

@ -304,7 +304,7 @@ struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemvProduct>
template<typename Dest>
static void scaleAndAddTo(Dest& dst, const Lhs& lhs, const Rhs& rhs, const Scalar& alpha)
{
internal::gemv_selector<Side,
internal::gemv_dense_sense_selector<Side,
(int(MatrixType::Flags)&RowMajorBit) ? RowMajor : ColMajor,
bool(internal::blas_traits<MatrixType>::HasUsableDirectAccess)
>::run(lhs, rhs, dst, alpha);

View File

@ -422,7 +422,9 @@ class GeneralProduct<Lhs, Rhs, GemmProduct>
internal::parallelize_gemm<(Dest::MaxRowsAtCompileTime>32 || Dest::MaxRowsAtCompileTime==Dynamic)>(GemmFunctor(lhs, rhs, dst, actualAlpha, blocking), this->rows(), this->cols(), Dest::Flags&RowMajorBit);
}
};
#else // EIGEN_TEST_EVALUATORS
#endif // EIGEN_TEST_EVALUATORS
#ifdef EIGEN_ENABLE_EVALUATORS
namespace internal {
template<typename Lhs, typename Rhs>
@ -477,7 +479,7 @@ struct generic_product_impl<Lhs,Rhs,DenseShape,DenseShape,GemmProduct>
};
} // end namespace internal
#endif // EIGEN_TEST_EVALUATORS
#endif // EIGEN_ENABLE_EVALUATORS
} // end namespace Eigen

View File

@ -431,7 +431,8 @@ struct SelfadjointProductMatrix<Lhs,LhsMode,false,Rhs,RhsMode,false>
);
}
};
#else // EIGEN_TEST_EVALUATORS
#endif // EIGEN_TEST_EVALUATORS
#ifdef EIGEN_ENABLE_EVALUATORS
namespace internal {
template<typename Lhs, int LhsMode, typename Rhs, int RhsMode>
@ -481,7 +482,7 @@ struct selfadjoint_product_impl<Lhs,LhsMode,false,Rhs,RhsMode,false>
} // end namespace internal
#endif
#endif // EIGEN_ENABLE_EVALUATORS
} // end namespace Eigen

View File

@ -421,7 +421,8 @@ struct TriangularProduct<Mode,LhsIsTriangular,Lhs,false,Rhs,false>
);
}
};
#else // EIGEN_TEST_EVALUATORS
#endif // EIGEN_TEST_EVALUATORS
#ifdef EIGEN_ENABLE_EVALUATORS
namespace internal {
template<int Mode, bool LhsIsTriangular, typename Lhs, typename Rhs>
struct triangular_product_impl<Mode,LhsIsTriangular,Lhs,false,Rhs,false>
@ -471,7 +472,7 @@ struct triangular_product_impl<Mode,LhsIsTriangular,Lhs,false,Rhs,false>
};
} // end namespace internal
#endif // EIGEN_TEST_EVALUATORS
#endif // EIGEN_ENABLE_EVALUATORS
} // end namespace Eigen

View File

@ -293,44 +293,10 @@ struct transfer_constness
>::type type;
};
#ifdef EIGEN_TEST_EVALUATORS
// When using evaluators, we never evaluate when assembling the expression!!
// TODO: get rid of this nested class since it's just an alias for ref_selector.
template<typename T, int n=1, typename PlainObject = typename eval<T>::type> struct nested
{
typedef typename ref_selector<T>::type type;
};
// However, we still need a mechanism to detect whether an expression which is evaluated multiple time
// has to be evaluated into a temporary.
// That's the purpose of this new nested_eval helper:
template<typename T, int n, typename PlainObject = typename eval<T>::type> struct nested_eval
{
enum {
// For the purpose of this test, to keep it reasonably simple, we arbitrarily choose a value of Dynamic values.
// the choice of 10000 makes it larger than any practical fixed value and even most dynamic values.
// in extreme cases where these assumptions would be wrong, we would still at worst suffer performance issues
// (poor choice of temporaries).
// It's important that this value can still be squared without integer overflowing.
DynamicAsInteger = 10000,
ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
ScalarReadCostAsInteger = ScalarReadCost == Dynamic ? int(DynamicAsInteger) : int(ScalarReadCost),
CoeffReadCost = traits<T>::CoeffReadCost,
CoeffReadCostAsInteger = CoeffReadCost == Dynamic ? int(DynamicAsInteger) : int(CoeffReadCost),
NAsInteger = n == Dynamic ? int(DynamicAsInteger) : n,
CostEvalAsInteger = (NAsInteger+1) * ScalarReadCostAsInteger + CoeffReadCostAsInteger,
CostNoEvalAsInteger = NAsInteger * CoeffReadCostAsInteger
};
#ifndef EIGEN_TEST_EVALUATORS
typedef typename conditional<
int(CostEvalAsInteger) < int(CostNoEvalAsInteger),
PlainObject,
typename ref_selector<T>::type
>::type type;
};
#else
/** \internal Determines how a given expression should be nested into another one.
* For example, when you do a * (b+c), Eigen will determine how the expression b+c should be
* nested into the bigger product expression. The choice is between nesting the expression b+c as-is, or
@ -377,8 +343,48 @@ template<typename T, int n=1, typename PlainObject = typename eval<T>::type> str
typename ref_selector<T>::type
>::type type;
};
#else
// When using evaluators, we never evaluate when assembling the expression!!
// TODO: get rid of this nested class since it's just an alias for ref_selector.
template<typename T, int n=1, typename PlainObject = typename eval<T>::type> struct nested
{
typedef typename ref_selector<T>::type type;
};
#endif // EIGEN_TEST_EVALUATORS
#ifdef EIGEN_ENABLE_EVALUATORS
// However, we still need a mechanism to detect whether an expression which is evaluated multiple time
// has to be evaluated into a temporary.
// That's the purpose of this new nested_eval helper:
template<typename T, int n, typename PlainObject = typename eval<T>::type> struct nested_eval
{
enum {
// For the purpose of this test, to keep it reasonably simple, we arbitrarily choose a value of Dynamic values.
// the choice of 10000 makes it larger than any practical fixed value and even most dynamic values.
// in extreme cases where these assumptions would be wrong, we would still at worst suffer performance issues
// (poor choice of temporaries).
// It's important that this value can still be squared without integer overflowing.
DynamicAsInteger = 10000,
ScalarReadCost = NumTraits<typename traits<T>::Scalar>::ReadCost,
ScalarReadCostAsInteger = ScalarReadCost == Dynamic ? int(DynamicAsInteger) : int(ScalarReadCost),
CoeffReadCost = traits<T>::CoeffReadCost,
CoeffReadCostAsInteger = CoeffReadCost == Dynamic ? int(DynamicAsInteger) : int(CoeffReadCost),
NAsInteger = n == Dynamic ? int(DynamicAsInteger) : n,
CostEvalAsInteger = (NAsInteger+1) * ScalarReadCostAsInteger + CoeffReadCostAsInteger,
CostNoEvalAsInteger = NAsInteger * CoeffReadCostAsInteger
};
typedef typename conditional<
int(CostEvalAsInteger) < int(CostNoEvalAsInteger),
PlainObject,
typename ref_selector<T>::type
>::type type;
};
#endif
template<typename T>
EIGEN_DEVICE_FUNC
T* const_cast_ptr(const T* ptr)