mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-19 19:34:29 +08:00
makes evaluator test use VERIFY_IS_APPROX
This commit is contained in:
parent
4ada45bc76
commit
abc8c0821c
@ -170,9 +170,10 @@ struct copy_using_evaluator_impl<LhsXprType, RhsXprType, DefaultTraversal, NoUnr
|
|||||||
// Based on DenseBase::LazyAssign()
|
// Based on DenseBase::LazyAssign()
|
||||||
|
|
||||||
template<typename LhsXprType, typename RhsXprType>
|
template<typename LhsXprType, typename RhsXprType>
|
||||||
void copy_using_evaluator(const LhsXprType& lhs, const RhsXprType& rhs)
|
const LhsXprType& copy_using_evaluator(const LhsXprType& lhs, const RhsXprType& rhs)
|
||||||
{
|
{
|
||||||
copy_using_evaluator_impl<LhsXprType, RhsXprType>::run(lhs, rhs);
|
copy_using_evaluator_impl<LhsXprType, RhsXprType>::run(lhs, rhs);
|
||||||
|
return lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
@ -5,32 +5,29 @@
|
|||||||
using internal::copy_using_evaluator;
|
using internal::copy_using_evaluator;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
#define VERIFY_IS_APPROX_EVALUATOR(DEST,EXPR) VERIFY_IS_APPROX(copy_using_evaluator(DEST,(EXPR)), (EXPR).eval());
|
||||||
|
#define VERIFY_IS_APPROX_EVALUATOR2(DEST,EXPR,REF) VERIFY_IS_APPROX(copy_using_evaluator(DEST,(EXPR)), (REF).eval());
|
||||||
|
|
||||||
void test_evaluators()
|
void test_evaluators()
|
||||||
{
|
{
|
||||||
// Testing Matrix evaluator and Transpose
|
// Testing Matrix evaluator and Transpose
|
||||||
Vector2d v(1,2);
|
Vector2d v = Vector2d::Random();
|
||||||
const Vector2d v_const(v);
|
const Vector2d v_const(v);
|
||||||
Vector2d v2;
|
Vector2d v2;
|
||||||
RowVector2d w;
|
RowVector2d w;
|
||||||
|
|
||||||
copy_using_evaluator(v2, v);
|
VERIFY_IS_APPROX_EVALUATOR(v2, v);
|
||||||
assert(v2.isApprox((Vector2d() << 1,2).finished()));
|
VERIFY_IS_APPROX_EVALUATOR(v2, v_const);
|
||||||
|
|
||||||
copy_using_evaluator(v2, v_const);
|
|
||||||
assert(v2.isApprox((Vector2d() << 1,2).finished()));
|
|
||||||
|
|
||||||
// Testing Transpose
|
// Testing Transpose
|
||||||
copy_using_evaluator(w, v.transpose()); // Transpose as rvalue
|
VERIFY_IS_APPROX_EVALUATOR(w, v.transpose()); // Transpose as rvalue
|
||||||
assert(w.isApprox((RowVector2d() << 1,2).finished()));
|
VERIFY_IS_APPROX_EVALUATOR(w, v_const.transpose());
|
||||||
|
|
||||||
copy_using_evaluator(w, v_const.transpose());
|
|
||||||
assert(w.isApprox((RowVector2d() << 1,2).finished()));
|
|
||||||
|
|
||||||
copy_using_evaluator(w.transpose(), v); // Transpose as lvalue
|
copy_using_evaluator(w.transpose(), v); // Transpose as lvalue
|
||||||
assert(w.isApprox((RowVector2d() << 1,2).finished()));
|
VERIFY_IS_APPROX(w,v.transpose().eval());
|
||||||
|
|
||||||
copy_using_evaluator(w.transpose(), v_const);
|
copy_using_evaluator(w.transpose(), v_const);
|
||||||
assert(w.isApprox((RowVector2d() << 1,2).finished()));
|
VERIFY_IS_APPROX(w,v_const.transpose().eval());
|
||||||
|
|
||||||
// Testing Array evaluator
|
// Testing Array evaluator
|
||||||
ArrayXXf a(2,3);
|
ArrayXXf a(2,3);
|
||||||
@ -38,39 +35,32 @@ void test_evaluators()
|
|||||||
a << 1,2,3, 4,5,6;
|
a << 1,2,3, 4,5,6;
|
||||||
const ArrayXXf a_const(a);
|
const ArrayXXf a_const(a);
|
||||||
|
|
||||||
ArrayXXf b_expected(3,2);
|
VERIFY_IS_APPROX_EVALUATOR(b, a.transpose());
|
||||||
b_expected << 1,4, 2,5, 3,6;
|
|
||||||
copy_using_evaluator(b, a.transpose());
|
|
||||||
assert(b.isApprox(b_expected));
|
|
||||||
|
|
||||||
copy_using_evaluator(b, a_const.transpose());
|
VERIFY_IS_APPROX_EVALUATOR(b, a_const.transpose());
|
||||||
assert(b.isApprox(b_expected));
|
|
||||||
|
|
||||||
// Testing CwiseNullaryOp evaluator
|
// Testing CwiseNullaryOp evaluator
|
||||||
copy_using_evaluator(w, RowVector2d::Random());
|
copy_using_evaluator(w, RowVector2d::Random());
|
||||||
assert((w.array() >= -1).all() && (w.array() <= 1).all()); // not easy to test ...
|
VERIFY((w.array() >= -1).all() && (w.array() <= 1).all()); // not easy to test ...
|
||||||
|
|
||||||
copy_using_evaluator(w, RowVector2d::Zero());
|
VERIFY_IS_APPROX_EVALUATOR(w, RowVector2d::Zero());
|
||||||
assert(w.isApprox((RowVector2d() << 0,0).finished()));
|
|
||||||
|
|
||||||
copy_using_evaluator(w, RowVector2d::Constant(3));
|
VERIFY_IS_APPROX_EVALUATOR(w, RowVector2d::Constant(3));
|
||||||
assert(w.isApprox((RowVector2d() << 3,3).finished()));
|
|
||||||
|
|
||||||
// mix CwiseNullaryOp and transpose
|
// mix CwiseNullaryOp and transpose
|
||||||
copy_using_evaluator(w, Vector2d::Zero().transpose());
|
VERIFY_IS_APPROX_EVALUATOR(w, Vector2d::Zero().transpose());
|
||||||
assert(w.isApprox((RowVector2d() << 0,0).finished()));
|
|
||||||
|
|
||||||
{
|
{
|
||||||
MatrixXf a(2,2), b(2,2), c(2,2), d(2,2);
|
int s = internal::random<int>(1,100);
|
||||||
a << 1, 2, 3, 4; b << 5, 6, 7, 8; c << 9, 10, 11, 12;
|
MatrixXf a(s,s), b(s,s), c(s,s), d(s,s);
|
||||||
copy_using_evaluator(d, (a + b));
|
a.setRandom();
|
||||||
cout << d << endl;
|
b.setRandom();
|
||||||
|
c.setRandom();
|
||||||
copy_using_evaluator(d, (a + b).transpose());
|
d.setRandom();
|
||||||
cout << d << endl;
|
VERIFY_IS_APPROX_EVALUATOR(d, (a + b));
|
||||||
|
VERIFY_IS_APPROX_EVALUATOR(d, (a + b).transpose());
|
||||||
copy_using_evaluator(d, prod(a,b).transpose());
|
VERIFY_IS_APPROX_EVALUATOR2(d, prod(a,b).transpose(), (a*b).transpose());
|
||||||
cout << d << endl;
|
VERIFY_IS_APPROX_EVALUATOR2(d, prod(a,b) + prod(b,c), a*b + b*c);
|
||||||
|
|
||||||
// copy_using_evaluator(d, a.transpose() + (a.transpose() * (b+b)));
|
// copy_using_evaluator(d, a.transpose() + (a.transpose() * (b+b)));
|
||||||
// cout << d << endl;
|
// cout << d << endl;
|
||||||
@ -80,24 +70,12 @@ void test_evaluators()
|
|||||||
// copy_using_evaluator(w, Vector2d::Random().transpose());
|
// copy_using_evaluator(w, Vector2d::Random().transpose());
|
||||||
|
|
||||||
// test CwiseUnaryOp
|
// test CwiseUnaryOp
|
||||||
copy_using_evaluator(v2, 3 * v);
|
VERIFY_IS_APPROX_EVALUATOR(v2, 3 * v);
|
||||||
assert(v2.isApprox((Vector2d() << 3,6).finished()));
|
VERIFY_IS_APPROX_EVALUATOR(w, (3 * v).transpose());
|
||||||
|
VERIFY_IS_APPROX_EVALUATOR(b, (a + 3).transpose());
|
||||||
copy_using_evaluator(w, (3 * v).transpose());
|
VERIFY_IS_APPROX_EVALUATOR(b, (2 * a_const + 3).transpose());
|
||||||
assert(w.isApprox((RowVector2d() << 3,6).finished()));
|
|
||||||
|
|
||||||
copy_using_evaluator(b, (a + 3).transpose());
|
|
||||||
b_expected << 4,7, 5,8, 6,9;
|
|
||||||
assert(b.isApprox(b_expected));
|
|
||||||
|
|
||||||
copy_using_evaluator(b, (2 * a_const + 3).transpose());
|
|
||||||
b_expected << 5,11, 7,13, 9,15;
|
|
||||||
assert(b.isApprox(b_expected));
|
|
||||||
|
|
||||||
// test CwiseBinaryOp
|
// test CwiseBinaryOp
|
||||||
copy_using_evaluator(v2, v + Vector2d::Ones());
|
VERIFY_IS_APPROX_EVALUATOR(v2, v + Vector2d::Ones());
|
||||||
assert(v2.isApprox((Vector2d() << 2,3).finished()));
|
VERIFY_IS_APPROX_EVALUATOR(w, (v + Vector2d::Ones()).transpose().cwiseProduct(RowVector2d::Constant(3)));
|
||||||
|
|
||||||
copy_using_evaluator(w, (v + Vector2d::Ones()).transpose().cwiseProduct(RowVector2d::Constant(3)));
|
|
||||||
assert(w.isApprox((RowVector2d() << 6,9).finished()));
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user