<p dir="auto">If I try to calculate a noncentral chi-square cdf with a noncentrality parameter of zero, I get a nan returned. A non-centrality parameter of zero yields a perfectly well-defined (central) chi-squared distribution, so why not just return a value? I.e., implement internally the test that I currently have to perform:</p>
<p dir="auto">c = ncx2.cdf(x, df, nonCent) if nonCent &gt; 0 else chi2.cdf(x, df)</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/993" rel="nofollow">http://projects.scipy.org/scipy/ticket/993</a> on 2009-09-04 by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/lebigot/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/lebigot">@lebigot</a>, assigned to unknown.</em></p>
<p dir="auto">scipy.optimize.leastsq() behaves very differently depending on the type of data points: in the examples below, the first result, which has float32 data points, is vastly incorrect (even though the error code says it is OK).  The second result is correct, because it uses float64 data points.</p>
<p dir="auto">This does not look normal to me. :)</p>
<p dir="auto">Here is a simple example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# fit_func() is an example fitting function (linear...):
fit_func = lambda p, x: p[0] + p[1]*x

# Basic error_func():
error_func = lambda p, x, y: return y - fit_func(p, x)

In [96]: x = np.arange(3, dtype = 'f4'); optimize.leastsq(error_func, (10, 3), args = (x, fit_func([1000, 2], x)))

Out[96]: (array([ 10.,   3.]), 4)  # Very wrong (initial x0)

In [97]: x = np.arange(3, dtype = 'f8'); optimize.leastsq(error_func, (10, 3), args = (x, fit_func([1000, 2], x)))

Out[97]: (array([ 1000.,     2.]), 2)  # Perfect!"><pre class="notranslate"><code class="notranslate"># fit_func() is an example fitting function (linear...):
fit_func = lambda p, x: p[0] + p[1]*x

# Basic error_func():
error_func = lambda p, x, y: return y - fit_func(p, x)

In [96]: x = np.arange(3, dtype = 'f4'); optimize.leastsq(error_func, (10, 3), args = (x, fit_func([1000, 2], x)))

Out[96]: (array([ 10.,   3.]), 4)  # Very wrong (initial x0)

In [97]: x = np.arange(3, dtype = 'f8'); optimize.leastsq(error_func, (10, 3), args = (x, fit_func([1000, 2], x)))

Out[97]: (array([ 1000.,     2.]), 2)  # Perfect!
</code></pre></div>