Make swap unit test work with evaluators

This commit is contained in:
Gael Guennebaud 2013-12-02 15:07:45 +01:00
parent c6f7337032
commit 8af1ba5346
4 changed files with 23 additions and 18 deletions

View File

@ -305,6 +305,7 @@ using std::ptrdiff_t;
#include "src/Core/functors/UnaryFunctors.h"
#include "src/Core/functors/NullaryFunctors.h"
#include "src/Core/functors/StlFunctors.h"
#include "src/Core/functors/AssignmentFunctors.h"
#include "src/Core/DenseCoeffsBase.h"
#include "src/Core/DenseBase.h"
@ -312,7 +313,6 @@ using std::ptrdiff_t;
#include "src/Core/EigenBase.h"
#ifdef EIGEN_ENABLE_EVALUATORS
#include "src/Core/functors/AssignmentFunctors.h"
#include "src/Core/Product.h"
#include "src/Core/CoreEvaluators.h"
#include "src/Core/AssignEvaluator.h"

View File

@ -397,7 +397,7 @@ template<typename Derived> class DenseBase
void swap(const DenseBase<OtherDerived>& other,
int = OtherDerived::ThisConstantIsPrivateInPlainObjectBase)
{
swap_using_evaluator(derived(), other.derived());
call_assignment(derived(), other.const_cast_derived(), internal::swap_assign_op<Scalar>());
}
/** swaps *this with the matrix or array \a other.
@ -407,7 +407,7 @@ template<typename Derived> class DenseBase
EIGEN_DEVICE_FUNC
void swap(PlainObjectBase<OtherDerived>& other)
{
swap_using_evaluator(derived(), other.derived());
call_assignment(derived(), other.derived(), internal::swap_assign_op<Scalar>());
}
#else // EIGEN_TEST_EVALUATORS
/** swaps *this with the expression \a other.

View File

@ -414,11 +414,11 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
EIGEN_DEVICE_FUNC
void swap(TriangularBase<OtherDerived> const & other)
{
// #ifdef EIGEN_TEST_EVALUATORS
// swap_using_evaluator(this->derived(), other.derived());
// #else
TriangularView<SwapWrapper<MatrixType>,Mode>(const_cast<MatrixType&>(m_matrix)).lazyAssign(other.derived());
// #endif
#ifdef EIGEN_TEST_EVALUATORS
call_assignment(*this, other.const_cast_derived(), internal::swap_assign_op<Scalar>());
#else
TriangularView<SwapWrapper<MatrixType>,Mode>(const_cast<MatrixType&>(m_matrix)).lazyAssign(other.const_cast_derived().nestedExpression());
#endif
}
// TODO: this overload is ambiguous and it should be deprecated (Gael)
@ -426,12 +426,12 @@ template<typename _MatrixType, unsigned int _Mode> class TriangularView
EIGEN_DEVICE_FUNC
void swap(MatrixBase<OtherDerived> const & other)
{
// #ifdef EIGEN_TEST_EVALUATORS
// swap_using_evaluator(this->derived(), other.derived());
// #else
#ifdef EIGEN_TEST_EVALUATORS
call_assignment(*this, other.const_cast_derived(), internal::swap_assign_op<Scalar>());
#else
SwapWrapper<MatrixType> swaper(const_cast<MatrixType&>(m_matrix));
TriangularView<SwapWrapper<MatrixType>,Mode>(swaper).lazyAssign(other.derived());
// #endif
#endif
}
EIGEN_DEVICE_FUNC
@ -988,7 +988,6 @@ void call_triangular_assignment_loop(const DstXprType& dst, const SrcXprType& sr
call_triangular_assignment_loop<Mode,ClearOpposite>(dst, src, internal::assign_op<typename DstXprType::Scalar>());
}
template<> struct AssignmentKind<TriangularShape,TriangularShape> { typedef Triangular2Triangular Kind; };
template<> struct AssignmentKind<DenseShape,TriangularShape> { typedef Triangular2Dense Kind; };
template<> struct AssignmentKind<TriangularShape,DenseShape> { typedef Dense2Triangular Kind; };
@ -1028,8 +1027,8 @@ template<typename Kernel, unsigned int Mode, int UnrollCount, bool ClearOpposite
struct triangular_assignment_loop
{
enum {
col = (UnrollCount-1) / Kernel::RowsAtCompileTime,
row = (UnrollCount-1) % Kernel::RowsAtCompileTime
col = (UnrollCount-1) / Kernel::DstEvaluatorType::RowsAtCompileTime,
row = (UnrollCount-1) % Kernel::DstEvaluatorType::RowsAtCompileTime
};
typedef typename Kernel::Scalar Scalar;

View File

@ -106,7 +106,7 @@ void test_evaluators()
copy_using_evaluator(w.transpose(), v_const);
VERIFY_IS_APPROX(w,v_const.transpose().eval());
#if 0
// Testing Array evaluator
{
ArrayXXf a(2,3);
@ -194,7 +194,7 @@ void test_evaluators()
VERIFY_IS_APPROX_EVALUATOR2(resXX, prod(mX4,m4X), mX4*m4X);
VERIFY_IS_APPROX_EVALUATOR2(resXX, prod(mXX,mXX), mXX*mXX);
}
#endif
{
ArrayXXf a(2,3);
ArrayXXf b(3,2);
@ -409,7 +409,7 @@ void test_evaluators()
{
// test triangular shapes
MatrixXd A = MatrixXd::Random(6,6), B(6,6), C(6,6);
MatrixXd A = MatrixXd::Random(6,6), B(6,6), C(6,6), D(6,6);
A.setRandom();B.setRandom();
VERIFY_IS_APPROX_EVALUATOR2(B, A.triangularView<Upper>(), MatrixXd(A.triangularView<Upper>()));
@ -434,5 +434,11 @@ void test_evaluators()
C = B; C.triangularView<Lower>() = A.triangularView<Upper>().transpose();
copy_using_evaluator(B.triangularView<Lower>(), A.triangularView<Upper>().transpose());
VERIFY(B.isApprox(C) && "copy_using_evaluator(B.triangularView<Lower>(), A.triangularView<Lower>().transpose())");
A.setRandom();B.setRandom(); C = B; D = A;
C.triangularView<Upper>().swap(D.triangularView<Upper>());
swap_using_evaluator(B.triangularView<Upper>(), A.triangularView<Upper>());
VERIFY(B.isApprox(C) && "swap_using_evaluator(B.triangularView<Upper>(), A.triangularView<Upper>())");
}
}