mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-30 16:52:01 +08:00
Proper handling of domain errors.
This commit is contained in:
parent
7f4826890c
commit
643b697649
@ -970,9 +970,14 @@ struct polygamma_impl {
|
|||||||
static Scalar run(Scalar n, Scalar x) {
|
static Scalar run(Scalar n, Scalar x) {
|
||||||
Scalar zero = 0.0, one = 1.0;
|
Scalar zero = 0.0, one = 1.0;
|
||||||
Scalar nplus = n + one;
|
Scalar nplus = n + one;
|
||||||
|
const Scalar nan = NumTraits<Scalar>::quiet_NaN();
|
||||||
|
|
||||||
|
// Check that n is an integer
|
||||||
|
if (numext::floor(n) != n) {
|
||||||
|
return nan;
|
||||||
|
}
|
||||||
// Just return the digamma function for n = 1
|
// Just return the digamma function for n = 1
|
||||||
if (n == zero) {
|
else if (n == zero) {
|
||||||
return digamma_impl<Scalar>::run(x);
|
return digamma_impl<Scalar>::run(x);
|
||||||
}
|
}
|
||||||
// Use the same implementation as scipy
|
// Use the same implementation as scipy
|
||||||
|
@ -331,11 +331,13 @@ template<typename ArrayType> void array_real(const ArrayType& m)
|
|||||||
VERIFY_IS_APPROX(numext::zeta(Scalar(3), Scalar(-2.5)), RealScalar(0.054102025820864097));
|
VERIFY_IS_APPROX(numext::zeta(Scalar(3), Scalar(-2.5)), RealScalar(0.054102025820864097));
|
||||||
VERIFY_IS_EQUAL(numext::zeta(Scalar(1), Scalar(1.2345)), // The second scalar does not matter
|
VERIFY_IS_EQUAL(numext::zeta(Scalar(1), Scalar(1.2345)), // The second scalar does not matter
|
||||||
std::numeric_limits<RealScalar>::infinity());
|
std::numeric_limits<RealScalar>::infinity());
|
||||||
|
VERIFY((numext::isnan)(numext::zeta(Scalar(0.9), Scalar(1.2345)))); // The second scalar does not matter
|
||||||
|
|
||||||
// Check the polygamma against scipy.special.polygamma examples
|
// Check the polygamma against scipy.special.polygamma examples
|
||||||
VERIFY_IS_APPROX(numext::polygamma(Scalar(1), Scalar(2)), RealScalar(0.644934066848));
|
VERIFY_IS_APPROX(numext::polygamma(Scalar(1), Scalar(2)), RealScalar(0.644934066848));
|
||||||
VERIFY_IS_APPROX(numext::polygamma(Scalar(1), Scalar(3)), RealScalar(0.394934066848));
|
VERIFY_IS_APPROX(numext::polygamma(Scalar(1), Scalar(3)), RealScalar(0.394934066848));
|
||||||
VERIFY_IS_APPROX(numext::polygamma(Scalar(1), Scalar(25.5)), RealScalar(0.0399946696496));
|
VERIFY_IS_APPROX(numext::polygamma(Scalar(1), Scalar(25.5)), RealScalar(0.0399946696496));
|
||||||
|
VERIFY((numext::isnan)(numext::polygamma(Scalar(1.5), Scalar(1.2345)))); // The second scalar does not matter
|
||||||
|
|
||||||
// Check the polygamma function over a larger range of values
|
// Check the polygamma function over a larger range of values
|
||||||
VERIFY_IS_APPROX(numext::polygamma(Scalar(17), Scalar(4.7)), RealScalar(293.334565435));
|
VERIFY_IS_APPROX(numext::polygamma(Scalar(17), Scalar(4.7)), RealScalar(293.334565435));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user