diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2011-12-20 18:00:39 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2012-01-09 10:45:13 -0700 |
commit | 266915b2d5480474f9eeb1cb7a11e6753e4fcf2e (patch) | |
tree | 050cc866d7f69b283e678f25f1d9a95eebd5e6ca /numpy/polynomial/polynomial.py | |
parent | 26e2ae4b8b55bc82cd46d5d309ac5eced4bc8fe4 (diff) | |
download | numpy-266915b2d5480474f9eeb1cb7a11e6753e4fcf2e.tar.gz |
BUG: Small fixes and additions
Where xxx is one of poly, cheb, leg, lag, herm, herme:
Refactor xxxval2d, xxxval3d, xxxgrid2d, and xxxgrid3d for clarity.
Check that coordinate arrays are compatible in xxxval2d, xxxval3d.
Work around einsum bug that affected xxxvander3d.
Diffstat (limited to 'numpy/polynomial/polynomial.py')
-rw-r--r-- | numpy/polynomial/polynomial.py | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py index 87acfa616..345d76233 100644 --- a/numpy/polynomial/polynomial.py +++ b/numpy/polynomial/polynomial.py @@ -786,7 +786,14 @@ def polyval2d(x, y, c): polyval, polygrid2d, polyval3d, polygrid3d """ - return polyval(y, polyval(x, c), False) + try: + x, y = np.array((x, y), copy=0) + except: + raise ValueError('x, y are incompatible') + + c = polyval(x, c) + c = polyval(y, c, tensor=False) + return c def polygrid2d(x, y, c): @@ -826,7 +833,9 @@ def polygrid2d(x, y, c): polyval, polyval2d, polyval3d, polygrid3d """ - return polyval(y, polyval(x, c)) + c = polyval(x, c) + c = polyval(y, c) + return c def polyval3d(x, y, z, c): @@ -863,7 +872,15 @@ def polyval3d(x, y, z, c): polyval, polyval2d, polygrid2d, polygrid3d """ - return polyval(z, polyval2d(x, y, c), False) + try: + x, y, z = np.array((x, y, z), copy=0) + except: + raise ValueError('x, y, z are incompatible') + + c = polyval(x, c) + c = polyval(y, c, tensor=False) + c = polyval(z, c, tensor=False) + return c def polygrid3d(x, y, z, c): @@ -904,7 +921,10 @@ def polygrid3d(x, y, z, c): polyval, polyval2d, polygrid2d, polyval3d """ - return polyval(z, polygrid2d(x, y, c)) + c = polyval(x, c) + c = polyval(y, c) + c = polyval(z, c) + return c def polyvander(x, deg) : @@ -986,12 +1006,14 @@ def polyvander2d(x, y, deg) : is_valid = [id == d and id >= 0 for id, d in zip(ideg, deg)] if is_valid != [1, 1]: raise ValueError("degrees must be non-negative integers") - degx, degy = deg + degx, degy = ideg x, y = np.array((x, y), copy=0) + 0.0 vx = polyvander(x, degx) vy = polyvander(y, degy) - v = np.einsum("...i,...j->...ij", vx, vy) + v = vx[..., None]*vy[..., None, :] + # einsum bug + #v = np.einsum("...i,...j->...ij", vx, vy) return v.reshape(v.shape[:-2] + (-1,)) @@ -1032,13 +1054,15 @@ def polyvander3d(x, y, z, deg) : is_valid = [id == d and id >= 0 for id, d in zip(ideg, deg)] if is_valid != [1, 1, 1]: raise ValueError("degrees must be non-negative integers") - degx, degy, degz = deg + degx, degy, degz = ideg x, y, z = np.array((x, y, z), copy=0) + 0.0 - vx = polyvander(x, deg_x) - vy = polyvander(y, deg_y) - vz = polyvander(z, deg_z) - v = np.einsum("...i,...j,...k->...ijk", vx, vy, vz) + vx = polyvander(x, degx) + vy = polyvander(y, degy) + vz = polyvander(z, degz) + v = vx[..., None, None]*vy[..., None, :, None]*vz[..., None, None, :] + # einsum bug + #v = np.einsum("...i, ...j, ...k->...ijk", vx, vy, vz) return v.reshape(v.shape[:-3] + (-1,)) |