Skip to content

Commit

Permalink
Fixing rcond=None problem for old NumPy
Browse files Browse the repository at this point in the history
  • Loading branch information
sigvaldm committed May 20, 2019
1 parent 65da1c8 commit de6c167
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion localreg/localreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ def polyfit(x, y, x0, weights=None, degree=2):
X = x[:, None]**np.arange(degree + 1)
X0 = x0[:, None]**np.arange(degree + 1)

beta = np.linalg.lstsq(X*s[:, None], y*s, rcond=None)[0]
lhs = X*s[:, None]
rhs = y*s

# This is what NumPy uses for default from version 1.15 onwards,
# and what 1.14 uses when rcond=None. Computing it here ensures
# support for older versions of NumPy.
rcond = np.finfo(lhs.dtype).eps * max(*lhs.shape)

beta = np.linalg.lstsq(lhs, rhs, rcond=rcond)[0]

return X0.dot(beta)

Expand Down

0 comments on commit de6c167

Please sign in to comment.