Bugzilla – Attachment 165 Details for
Bug 99
Expression evaluator
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Forgot Password
Login:
[x]
This bugzilla service is closed. All entries have been migrated to
https://gitlab.com/libeigen/eigen
[patch]
Use evaluators in assignments and VERIFY_IS_APPROX
turn-evaluators-on (text/plain), 6.97 KB, created by
Jitse Niesen
on 2011-04-29 00:11:50 UTC
(
hide
)
Description:
Use evaluators in assignments and VERIFY_IS_APPROX
Filename:
MIME Type:
Creator:
Jitse Niesen
Created:
2011-04-29 00:11:50 UTC
Size:
6.97 KB
patch
obsolete
>diff --git a/Eigen/Core b/Eigen/Core >--- a/Eigen/Core >+++ b/Eigen/Core >@@ -277,16 +277,21 @@ using std::size_t; > #include "src/Core/arch/Default/Settings.h" > > #include "src/Core/Functors.h" > #include "src/Core/DenseCoeffsBase.h" > #include "src/Core/DenseBase.h" > #include "src/Core/MatrixBase.h" > #include "src/Core/EigenBase.h" > >+#define EIGEN_ENABLE_EVALUATORS >+#include "src/Core/Product.h" >+#include "src/Core/CoreEvaluators.h" >+#include "src/Core/AssignEvaluator.h" >+ > #ifndef EIGEN_PARSED_BY_DOXYGEN // work around Doxygen bug triggered by Assign.h r814874 > // at least confirmed with Doxygen 1.5.5 and 1.5.6 > #include "src/Core/Assign.h" > #endif > > #include "src/Core/util/BlasUtil.h" > #include "src/Core/DenseStorage.h" > #include "src/Core/NestByValue.h" >@@ -346,22 +351,16 @@ using std::size_t; > #include "src/Core/Select.h" > #include "src/Core/VectorwiseOp.h" > #include "src/Core/Random.h" > #include "src/Core/Replicate.h" > #include "src/Core/Reverse.h" > #include "src/Core/ArrayBase.h" > #include "src/Core/ArrayWrapper.h" > >-#ifdef EIGEN_ENABLE_EVALUATORS >-#include "src/Core/Product.h" >-#include "src/Core/CoreEvaluators.h" >-#include "src/Core/AssignEvaluator.h" >-#endif >- > } // namespace Eigen > > #include "src/Core/GlobalFunctions.h" > > #include "src/Core/util/ReenableStupidWarnings.h" > > #ifdef EIGEN2_SUPPORT > #include "Eigen2Support" >diff --git a/Eigen/src/Core/Assign.h b/Eigen/src/Core/Assign.h >--- a/Eigen/src/Core/Assign.h >+++ b/Eigen/src/Core/Assign.h >@@ -500,20 +500,20 @@ EIGEN_STRONG_INLINE Derived& DenseBase<D > SameType = internal::is_same<typename Derived::Scalar,typename OtherDerived::Scalar>::value > }; > > EIGEN_STATIC_ASSERT_LVALUE(Derived) > EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Derived,OtherDerived) > EIGEN_STATIC_ASSERT(SameType,YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY) > > #ifdef EIGEN_DEBUG_ASSIGN >- internal::assign_traits<Derived, OtherDerived>::debug(); >+ internal::copy_using_evaluator_traits<Derived, OtherDerived>::debug(); > #endif > eigen_assert(rows() == other.rows() && cols() == other.cols()); >- internal::assign_impl<Derived, OtherDerived, int(SameType) ? int(internal::assign_traits<Derived, OtherDerived>::Traversal) >+ internal::copy_using_evaluator_impl<Derived, OtherDerived, int(SameType) ? int(internal::copy_using_evaluator_traits<Derived, OtherDerived>::Traversal) > : int(InvalidTraversal)>::run(derived(),other.derived()); > #ifndef EIGEN_NO_DEBUG > checkTransposeAliasing(other.derived()); > #endif > return derived(); > } > > namespace internal { >diff --git a/Eigen/src/Core/SelfCwiseBinaryOp.h b/Eigen/src/Core/SelfCwiseBinaryOp.h >--- a/Eigen/src/Core/SelfCwiseBinaryOp.h >+++ b/Eigen/src/Core/SelfCwiseBinaryOp.h >@@ -139,20 +139,20 @@ template<typename BinaryOp, typename Lhs > // see CwiseBinaryOp ctor for details > template<typename RhsDerived> > EIGEN_STRONG_INLINE SelfCwiseBinaryOp& lazyAssign(const DenseBase<RhsDerived>& rhs) > { > EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs,RhsDerived) > EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename RhsDerived::Scalar); > > #ifdef EIGEN_DEBUG_ASSIGN >- internal::assign_traits<SelfCwiseBinaryOp, RhsDerived>::debug(); >+ internal::copy_using_evaluator_traits<SelfCwiseBinaryOp, RhsDerived>::debug(); > #endif > eigen_assert(rows() == rhs.rows() && cols() == rhs.cols()); >- internal::assign_impl<SelfCwiseBinaryOp, RhsDerived>::run(*this,rhs.derived()); >+ internal::copy_using_evaluator_impl<SelfCwiseBinaryOp, RhsDerived>::run(*this,rhs.derived()); > #ifndef EIGEN_NO_DEBUG > this->checkTransposeAliasing(rhs.derived()); > #endif > return *this; > } > > // overloaded to honor evaluation of special matrices > // maybe another solution would be to not use SelfCwiseBinaryOp >diff --git a/test/evaluators.cpp b/test/evaluators.cpp >--- a/test/evaluators.cpp >+++ b/test/evaluators.cpp >@@ -44,31 +44,34 @@ void test_evaluators() > > VERIFY_IS_APPROX_EVALUATOR(w, RowVector2d::Zero()); > > VERIFY_IS_APPROX_EVALUATOR(w, RowVector2d::Constant(3)); > > // mix CwiseNullaryOp and transpose > VERIFY_IS_APPROX_EVALUATOR(w, Vector2d::Zero().transpose()); > >- { >- int s = internal::random<int>(1,100); >- MatrixXf a(s,s), b(s,s), c(s,s), d(s,s); >- a.setRandom(); >- b.setRandom(); >- c.setRandom(); >- d.setRandom(); >- VERIFY_IS_APPROX_EVALUATOR(d, (a + b)); >- VERIFY_IS_APPROX_EVALUATOR(d, (a + b).transpose()); >- VERIFY_IS_APPROX_EVALUATOR2(d, prod(a,b).transpose(), (a*b).transpose()); >- 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))); >-// cout << d << endl; >- } >+ // This fails because there is no evaluator for GeneralProduct, which is the expression >+ // type produced by operator* acting on matrices. >+ // >+ // { >+ // int s = internal::random<int>(1,100); >+ // MatrixXf a(s,s), b(s,s), c(s,s), d(s,s); >+ // a.setRandom(); >+ // b.setRandom(); >+ // c.setRandom(); >+ // d.setRandom(); >+ // VERIFY_IS_APPROX_EVALUATOR(d, (a + b)); >+ // VERIFY_IS_APPROX_EVALUATOR(d, (a + b).transpose()); >+ // VERIFY_IS_APPROX_EVALUATOR2(d, prod(a,b).transpose(), (a*b).transpose()); >+ // 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))); >+ // cout << d << endl; >+ // } > > // this does not work because Random is eval-before-nested: > // copy_using_evaluator(w, Vector2d::Random().transpose()); > > // test CwiseUnaryOp > VERIFY_IS_APPROX_EVALUATOR(v2, 3 * v); > VERIFY_IS_APPROX_EVALUATOR(w, (3 * v).transpose()); > VERIFY_IS_APPROX_EVALUATOR(b, (a + 3).transpose()); >diff --git a/test/main.h b/test/main.h >--- a/test/main.h >+++ b/test/main.h >@@ -251,17 +251,19 @@ inline bool test_isApprox(const long dou > inline bool test_isMuchSmallerThan(const long double& a, const long double& b) > { return internal::isMuchSmallerThan(a, b, test_precision<long double>()); } > inline bool test_isApproxOrLessThan(const long double& a, const long double& b) > { return internal::isApproxOrLessThan(a, b, test_precision<long double>()); } > > template<typename Type1, typename Type2> > inline bool test_isApprox(const Type1& a, const Type2& b) > { >- return a.isApprox(b, test_precision<typename Type1::Scalar>()); >+ typename internal::eval<Type1>::type a_eval(a); >+ typename internal::eval<Type2>::type b_eval(b); >+ return a_eval.isApprox(b_eval, test_precision<typename Type1::Scalar>()); > } > > // The idea behind this function is to compare the two scalars a and b where > // the scalar ref is a hint about the expected order of magnitude of a and b. > // Therefore, if for some reason a and b are very small compared to ref, > // we won't issue a false negative. > // This test could be: abs(a-b) <= eps * ref > // However, it seems that simply comparing a+ref and b+ref is more sensitive to true error.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 99
:
28
|
30
|
143
|
156
| 165 |
295
|
400