-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What to do about infinity? #118
Comments
Can you give an example when this is needed? |
Looking at, for instance scipy source code, I found about a thousand references to np.inf, but I think most (if not all) are to signal the infinite value as stated by @nshaffer. I agree that is very convenient to signal quadrature limits, or step sizes, or similar. But in this case we only need start implementing the constant (for instance as in option 2) and a routine signaling if it is +inf, -inf, or a finite number.
Of course, we may just want a True/False result, or something different but with a minimal implementation we could keep advancing and later make additions/modifications as more use cases make it necessary. |
Aren't the infinities disabled in |
@certik you are right, at least gfortran (silently) disables the ieee infinities, in the sense that it compiles and run but, for instance, ieee_is_finite(x) will give the wrong result. Additionally, the question on when we need an infinite value could gives a good frame to decide if/what to implement. As said before, scipy has about 1000 references to np.inf. From these only about 400 are in the code (not in tests, or documentation) and, as far as I can tell it is mainly used to initialize a value that will be tested or signal that a result is infinite (if (s == 0) logs = -inf)
In GSL-2.5 there are about 50 references to GSL_POSINF and they are mostly used in continuum distributions. They use when they can C99X INFINITY, when not the equivalent of huge(x), and fallback to ieee by computing the value of 1.0/0.0. With all that, I am not sure that we need to define an infinite. I've found it handy for integration domains, but my implementation was rather simple and based in huge(x). |
@certik Defining quadrature domains was my motivating use-case for this issue. Another use would be constraining curve fitting parameters, e.g., SciPy's For now, maybe it makes sense to let individuals do whatever seems natural for the features they're implementing. Eventually, we will probably want to adopt a uniform approach, though. |
Sometimes an algorithm needs a way to refer to positive or negative infinity (e.g., integration bounds) or test if a number is infinite. How are we going to do that? I see three directions we could take
ieee_arithmetic
to set and test for infinities.inf_{kind}
which is IEEE positive infinity for supported kinds and is a special value (maybehuge(x) + 1.0
) for non-IEEE kinds. Likewise, testing for infinities either usesieee_arithmetic
or tests for equality with the defined magic number.Option 1 is simple but means that some stdlib functionality just can't be implemented for all a compiler's real kinds.
Option 2 is simple for IEEE-compliant kinds but introduces a lot of undefined behavior for non-IEEE kinds. (e.g.: If
k
is a non-IEEE real kind, we can't guarantee thatinf_k - 1.0_k
does the "right" thing semantically.)Option 3 is complicated and might be a pain to use in practice. However, it's the only way I know of to get close to IEEE infinity semantics with non-IEEE reals.
I'd like to hear opinions and alternatives, if people have them.
The text was updated successfully, but these errors were encountered: