summaryrefslogtreecommitdiff
path: root/numpy/polynomial/hermite_e.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-10-04 12:37:11 -0600
committerCharles Harris <charlesr.harris@gmail.com>2014-10-04 12:37:11 -0600
commit0650d04078666997c3dac3beec6fe872dca797dd (patch)
treecce267dbba6b88798ad9125d9c7669b493271504 /numpy/polynomial/hermite_e.py
parent58350f4608a22f4b4b66795f51eaefc206bd02b8 (diff)
downloadnumpy-0650d04078666997c3dac3beec6fe872dca797dd.tar.gz
MAINT: Improve computation of scaled companion matrices.
The previous method used for hermite and hermite_e polynomials suffered from double overflow for polynomials of large degree. Those numbers were later scaled down by equally large numbers, but the result was NaN. The wanted values are now computed in such a way that overflow in some entries is replaced by underflow in others. The resulting zeros are a negligible perturbation of the companion matrix.
Diffstat (limited to 'numpy/polynomial/hermite_e.py')
-rw-r--r--numpy/polynomial/hermite_e.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py
index 6e33dc0bc..d8617ddac 100644
--- a/numpy/polynomial/hermite_e.py
+++ b/numpy/polynomial/hermite_e.py
@@ -1575,13 +1575,13 @@ def hermecompanion(c):
n = len(c) - 1
mat = np.zeros((n, n), dtype=c.dtype)
- scl = np.hstack((1., np.sqrt(np.arange(1, n))))
- scl = np.multiply.accumulate(scl)
+ scl = np.hstack((1., 1./np.sqrt(np.arange(n - 1, 0, -1))))
+ scl = np.multiply.accumulate(scl)[::-1]
top = mat.reshape(-1)[1::n+1]
bot = mat.reshape(-1)[n::n+1]
top[...] = np.sqrt(np.arange(1, n))
bot[...] = top
- mat[:, -1] -= (c[:-1]/c[-1])*(scl/scl[-1])
+ mat[:, -1] -= scl*c[:-1]/c[-1]
return mat