diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-06-12 12:31:56 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2016-06-12 12:48:48 -0600 |
commit | e25f7c9e314e79de6be5f17dc4c2c2be8ee9b753 (patch) | |
tree | 782290308545dda46b931ebcdc4ff266f255ef8f /numpy/polynomial/polynomial.py | |
parent | 76e2d4751294077cc4cafe155571ead8213133a8 (diff) | |
download | numpy-e25f7c9e314e79de6be5f17dc4c2c2be8ee9b753.tar.gz |
MAINT: refactor and small fixes to polyvalfromroots.
Simplify the logic a bit and make behavior consistent with polyval.
Note that this adds a check that the number of dimensions of the
array of the evaluation points is less than the number of dimensions of
the array of roots when tensor=False. That check is missing from polyval
and needs to be added.
Diffstat (limited to 'numpy/polynomial/polynomial.py')
-rw-r--r-- | numpy/polynomial/polynomial.py | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py index 23f1f6a36..c310d659d 100644 --- a/numpy/polynomial/polynomial.py +++ b/numpy/polynomial/polynomial.py @@ -856,15 +856,16 @@ def polyvalfromroots(x, r, tensor=True): >>> polyvalfromroots(b, r, tensor=False) array([-0., 0.]) """ - r = np.array(r, ndmin=1, copy=0) + 0.0 - if r.size == 0: - return np.ones_like(x) - if np.isscalar(x) or isinstance(x, (tuple, list)): - x = np.array(x, ndmin=1, copy=0) + 0.0 - if isinstance(x, np.ndarray) and tensor: - if x.size == 0: - return x.reshape(r.shape[1:]+x.shape) - r = r.reshape(r.shape + (1,)*x.ndim) + r = np.array(r, ndmin=1, copy=0) + if r.dtype.char in '?bBhHiIlLqQpP': + r = r.astype(np.double) + if isinstance(x, (tuple, list)): + x = np.asarray(x) + if isinstance(x, np.ndarray): + if tensor: + r = r.reshape(r.shape + (1,)*x.ndim) + elif x.ndim >= r.ndim: + raise ValueError("x.ndim must be < r.ndim when tensor == False") return np.prod(x - r, axis=0) |