question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nan from scipy.special.struve

See original GitHub issue

When 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:open
  • Created 8 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pvcommented, Mar 17, 2016

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.

0reactions
pvcommented, Apr 4, 2016

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:

envelope_value = some non-oscillating order of magnitude estimate, eg. 
from DLMF 11.6.5, maybe combined with something else for small v
;
if (fabs(value) < ZERO_EPS * envelope_value && fabs(err) < 
ACCEPTABLE_EPS * envelope_value) {
    return value;
}

where value and err correspond to the best of the estimates found by the three methods.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found