Skip to content

Commit f0f35ad

Browse files
Merge pull request #431 from matthew-brett/fix-numpy-1.13-breakage
MRG: new numpy protects polynomial coefficients New numpy returns a copy of the polynomial coefficients from poly.c, rather than the actual coefficent array, so when we were modifying the polynomial coefficients, the polynomial object wasn't seeing our changes, leading to errors in the RFT module - see e.g. https://nipy.bic.berkeley.edu/builders/nipy-py2.7-osx-10.10/builds/52/steps/shell_9/logs/stdio Numpy issue raised on numpy-discussion mailing list.
2 parents 8edb186 + c35c0d9 commit f0f35ad

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

nipy/algorithms/statistics/rft.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ def Q(dim, dfd=np.inf):
8787
j = dim
8888
if j <= 0:
8989
raise ValueError('Q defined only for dim > 0')
90-
poly = hermitenorm(j-1)
91-
poly = np.poly1d(np.around(poly.c))
90+
coeffs = np.around(hermitenorm(j - 1).c)
9291
if np.isfinite(m):
93-
for l in range((j-1)//2+1):
94-
f = np.exp(gammaln((m+1)/2.) - gammaln((m+2-j+2*l)/2.)
95-
- 0.5*(j-1-2*l)*(np.log(m/2.)))
96-
poly.c[2*l] *= f
97-
return np.poly1d(poly.c)
92+
for L in range((j - 1) // 2 + 1):
93+
f = np.exp(gammaln((m + 1) / 2.)
94+
- gammaln((m + 2 - j + 2 * L) / 2.)
95+
- 0.5 * (j - 1 - 2 * L) * (np.log(m / 2.)))
96+
coeffs[2 * L] *= f
97+
return np.poly1d(coeffs)
9898

9999

100100
class ECquasi(np.poly1d):

nipy/algorithms/statistics/tests/test_rft.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,16 @@ def test_hotelling2():
400400
chi = rft.ChiSquared(dfn=dfn)(x)
401401
assert_almost_equal(h, chi)
402402
chi2 = scipy.stats.chi2.sf(x, dfn)
403-
yield assert_almost_equal, h, chi2
403+
assert_almost_equal(h, chi2)
404404
# XXX - p appears to be unused
405405
p = rft.spherical_search(dfn)
406406
for dfd in [40,50]:
407407
fac = (dfd-dfn+1.)/(dfd*dfn)
408408
h = rft.Hotelling(dfd=dfd,k=dfn)(x)
409409
f = scipy.stats.f.sf(x*fac, dfn, dfd-dfn+1)
410410
f2 = rft.FStat(dfd=dfd-dfn+1,dfn=dfn)(x*fac)
411-
yield assert_almost_equal, f2, f
412-
yield assert_almost_equal, h, f
411+
assert_almost_equal(f2, f)
412+
assert_almost_equal(h, f)
413413

414414

415415
@dec.slow

0 commit comments

Comments
 (0)