summaryrefslogtreecommitdiff
path: root/numpy/polynomial/legendre.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-03-02 16:03:19 -0800
committerEric Wieser <wieser.eric@gmail.com>2019-03-02 19:34:25 -0800
commit379995dcc10fd9c58336420bd995b6d8a1b61288 (patch)
tree2deac0881f72c52e44f3f76ccb01bb1658ebd440 /numpy/polynomial/legendre.py
parente7b529c55cf9f5e27517d75df91211eb35f60d6c (diff)
downloadnumpy-379995dcc10fd9c58336420bd995b6d8a1b61288.tar.gz
MAINT: Merge duplicate implementations of `*vander2d` and `*vander3d` functions
Every implementation is the same right now, other than calling a different `*vander` function. Merging these into a single private function taking a callback results in significant deduplication. Found by LGTM.
Diffstat (limited to 'numpy/polynomial/legendre.py')
-rw-r--r--numpy/polynomial/legendre.py25
1 files changed, 2 insertions, 23 deletions
diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py
index f81bc002c..b5e4c9bef 100644
--- a/numpy/polynomial/legendre.py
+++ b/numpy/polynomial/legendre.py
@@ -1327,17 +1327,7 @@ def legvander2d(x, y, deg):
.. versionadded:: 1.7.0
"""
- ideg = [int(d) for d in 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 = ideg
- x, y = np.array((x, y), copy=0) + 0.0
-
- vx = legvander(x, degx)
- vy = legvander(y, degy)
- v = vx[..., None]*vy[..., None,:]
- return v.reshape(v.shape[:-2] + (-1,))
+ return pu._vander2d(legvander, x, y, deg)
def legvander3d(x, y, z, deg):
@@ -1391,18 +1381,7 @@ def legvander3d(x, y, z, deg):
.. versionadded:: 1.7.0
"""
- ideg = [int(d) for d in 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 = ideg
- x, y, z = np.array((x, y, z), copy=0) + 0.0
-
- vx = legvander(x, degx)
- vy = legvander(y, degy)
- vz = legvander(z, degz)
- v = vx[..., None, None]*vy[..., None,:, None]*vz[..., None, None,:]
- return v.reshape(v.shape[:-3] + (-1,))
+ return pu._vander3d(legvander, x, y, z, deg)
def legfit(x, y, deg, rcond=None, full=False, w=None):