Re: [eigen] Behavior of min/max if NaNs are involved, and fast-math behavior in general |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
Hi Christoph,
Am 01.07.19 um 13:41 schrieb Christoph Hertzberg:
> Essentially, the questions are
> * Do you need min/max-behavior which propagates NaNs or numbers?
> * Do you want to control that behavior per function or per compilation unit?
> * In the above-mentioned bug, I suggested adding an optional template parameter to each min/max function. Do you you see any drawbacks, or do you have alternative ideas?
Speaking for myself there's no need to act on this problem.
I'd like to remark that in my numeric NaNs always signals a problem
with my code and I'm setting traps to be on the safe side, at least during
development.
In case you are interested you can add the attached example to the documentation.
Note, setting the traps allows the debugger to reveal the problem.
> And then there is a more general question about Eigen's behavior regarding fast-math in general:
> http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1687
> i.e., EIGEN_FAST_MATH is currently enabled by default which is probably barely noticed since it mostly influences behavior of SIMD-math for calculating sine and cosine of arrays.
> Some more general questions regarding that:
> * Does anyone actually rely on being able to disable EIGEN_FAST_MATH?
I'm not relying on 'disable EIGEN_FAST_MATH?', however I do see tweaks of the FP-arithmetic in the final
result. E.g. FMA results in significantly better results.
> * Would anyone like to have more control over fast-math behavior? (setting ERRNO, always ignoring NaN/infinities/denormals, ...)
I set the appropriate traps myself and I hope that Eigen doesn't overwrite them.
Concerning the fast-math discussion, am I'm right in assuming that it Eigen does not
decrease the accuracy of interval arithmetic?
Best regards,
Peter
#include <iostream>
#include <Eigen/Core>
// g++ -O3 -DEIGEN_FAST_MATH -ffast-math -I ~/RG/Eigen/eigen-stable NaN.C -o NaN && ./NaN
// g++ -g -I ~/RG/Eigen/eigen-stable NaN.C -o NaN && ./NaN
// -------------------------------
#include <signal.h>
#include <fenv.h>
void trapfpe(void)
{
feenableexcept(FE_INVALID); // FE_INVALID needed to trap nan
//feenableexcept(FE_INVALID|FE_DIVBYZERO|FE_OVERFLOW);
}
// -------------------------------
int main()
{
/// setting NaN trap
trapfpe();
Eigen::ArrayXd arr(6);
arr << 2,2, 0.0/0.0, 0.0/0.0, 1, 1;
std::cout << arr.transpose() << "\nmaxCoeff() = " << arr.maxCoeff() << std::endl;
}