nan from scipy.special.struve
See original GitHub issueWhen looking for the origin of a NaN in my program, I ended up discovering that scipy.special.struve
can output NaN if the expected value is close to zero.
Is there anything that can be done to avoid this ?
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy.special
>>> scipy.special.struve(0,25.76534)
-3.9070380020700526e-06
>>> scipy.special.struve(0,25.76538)
2.2841077550668455e-06
>>> scipy.special.struve(0,25.76536)
nan
[Perhaps related to https://github.com/scipy/scipy/issues/4446]
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Special functions (scipy.special) — SciPy v1.9.3 Manual
Compute Ricatti-Bessel function of the second kind and its derivative. Struve functions#. struve (v, x[, out]).
Read more >scipy.special.struve — SciPy v1.9.3 Manual
scipy.special.struve(v, x, out=None) = <ufunc 'struve'>#. Struve function. Return the value of the Struve function of order v at x. The Struve function...
Read more >Cython API for special functions — SciPy v1.9.3 Manual
Functions can indicate an error by returning nan ; however they cannot emit warnings like their counterparts in scipy.special .
Read more >Cython API for special functions — SciPy v1.7.1 Manual
Functions can indicate an error by returning nan ; however they cannot emit warnings like their counterparts in scipy.special .
Read more >scipy.special.modstruve — SciPy v1.9.3 Manual
scipy.special.modstruve# ... Modified Struve function. Return the value of the modified Struve function of order v at x. The modified Struve function is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
gh-4446 is unrelated, the implementations are separate.
The nan comes around the zero of the function — it is due to the code noticing it cannot achieve the desired relative precision of the function value, nor the desired absolute precision which is fairly strict.
So the issue likely is just in the precision check and not a problem in the evaluation algorithm. In principle, the precision check should also use information based on the derivative of the function, but it does not.
Ok. Maybe the following suggestion would be OK: add at the end of struve_hl, to be done if none of the standard accuracy estimates is accepted:
where
value
anderr
correspond to the best of the estimates found by the three methods.