mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-23 01:59:38 +08:00
Fix adjoint unit test: test_isApproxWithRef works for positive quantities only.
This commit is contained in:
parent
c76990664b
commit
d02e329218
@ -28,6 +28,7 @@ template<> struct adjoint_specific<false> {
|
|||||||
template<typename Vec, typename Mat, typename Scalar>
|
template<typename Vec, typename Mat, typename Scalar>
|
||||||
static void run(const Vec& v1, const Vec& v2, Vec& v3, const Mat& square, Scalar s1, Scalar s2) {
|
static void run(const Vec& v1, const Vec& v2, Vec& v3, const Mat& square, Scalar s1, Scalar s2) {
|
||||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||||
|
using std::abs;
|
||||||
|
|
||||||
RealScalar ref = NumTraits<Scalar>::IsInteger ? RealScalar(0) : (std::max)((s1 * v1 + s2 * v2).norm(),v3.norm());
|
RealScalar ref = NumTraits<Scalar>::IsInteger ? RealScalar(0) : (std::max)((s1 * v1 + s2 * v2).norm(),v3.norm());
|
||||||
VERIFY(test_isApproxWithRef((s1 * v1 + s2 * v2).dot(v3), numext::conj(s1) * v1.dot(v3) + numext::conj(s2) * v2.dot(v3), ref));
|
VERIFY(test_isApproxWithRef((s1 * v1 + s2 * v2).dot(v3), numext::conj(s1) * v1.dot(v3) + numext::conj(s2) * v2.dot(v3), ref));
|
||||||
@ -44,7 +45,7 @@ template<> struct adjoint_specific<false> {
|
|||||||
|
|
||||||
// check compatibility of dot and adjoint
|
// check compatibility of dot and adjoint
|
||||||
ref = NumTraits<Scalar>::IsInteger ? 0 : (std::max)((std::max)(v1.norm(),v2.norm()),(std::max)((square * v2).norm(),(square.adjoint() * v1).norm()));
|
ref = NumTraits<Scalar>::IsInteger ? 0 : (std::max)((std::max)(v1.norm(),v2.norm()),(std::max)((square * v2).norm(),(square.adjoint() * v1).norm()));
|
||||||
VERIFY(test_isApproxWithRef(v1.dot(square * v2), (square.adjoint() * v1).dot(v2), ref));
|
VERIFY(internal::isMuchSmallerThan(abs(v1.dot(square * v2) - (square.adjoint() * v1).dot(v2)), ref, test_precision<Scalar>()));
|
||||||
|
|
||||||
// check that Random().normalized() works: tricky as the random xpr must be evaluated by
|
// check that Random().normalized() works: tricky as the random xpr must be evaluated by
|
||||||
// normalized() in order to produce a consistent result.
|
// normalized() in order to produce a consistent result.
|
||||||
|
@ -270,6 +270,7 @@ inline bool test_isApprox(const Type1& a, const Type2& b)
|
|||||||
|
|
||||||
// The idea behind this function is to compare the two scalars a and b where
|
// 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.
|
// the scalar ref is a hint about the expected order of magnitude of a and b.
|
||||||
|
// WARNING: the scalar a and b must be positive
|
||||||
// Therefore, if for some reason a and b are very small compared to ref,
|
// Therefore, if for some reason a and b are very small compared to ref,
|
||||||
// we won't issue a false negative.
|
// we won't issue a false negative.
|
||||||
// This test could be: abs(a-b) <= eps * ref
|
// This test could be: abs(a-b) <= eps * ref
|
||||||
|
Loading…
x
Reference in New Issue
Block a user