Bugfix: conjugate_gradient did not compile with lazy-evaluated RealScalar

The error generated by the compiler was:

    no matching function for call to 'maxi'
    RealScalar threshold = numext::maxi(tol*tol*rhsNorm2,considerAsZero);

The important part in the following notes was:

    candidate template ignored: deduced conflicting
    types for parameter 'T'"
    ('codi::Multiply11<...>' vs. 'codi::ActiveReal<...>')
    EIGEN_ALWAYS_INLINE T maxi(const T& x, const T& y)

I am using CoDiPack to provide the RealScalar type.
This bug was introduced in bc000deaa Fix conjugate-gradient for very small rhs
This commit is contained in:
Bernardo Bahia Monteiro 2020-03-29 18:53:18 -04:00
parent 4fd5d1477b
commit 54a0a9c9dd
No known key found for this signature in database
GPG Key ID: 4A2196705F4807BC

View File

@ -51,7 +51,7 @@ void conjugate_gradient(const MatrixType& mat, const Rhs& rhs, Dest& x,
return; return;
} }
const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)(); const RealScalar considerAsZero = (std::numeric_limits<RealScalar>::min)();
RealScalar threshold = numext::maxi(tol*tol*rhsNorm2,considerAsZero); RealScalar threshold = numext::maxi(RealScalar(tol*tol*rhsNorm2),considerAsZero);
RealScalar residualNorm2 = residual.squaredNorm(); RealScalar residualNorm2 = residual.squaredNorm();
if (residualNorm2 < threshold) if (residualNorm2 < threshold)
{ {