summaryrefslogtreecommitdiff
path: root/numpy/polynomial/polyutils.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-03-14 21:47:28 -0700
committerEric Wieser <wieser.eric@gmail.com>2019-03-14 22:16:15 -0700
commit2829cc559d4887ab0fe86d4dce97c435009d1fd7 (patch)
tree9ea49bd2a7188f99e887a7eea94e0cb9ad3cd76f /numpy/polynomial/polyutils.py
parent43c79ff448534e1d672e5c6013f9659d27d69aa0 (diff)
downloadnumpy-2829cc559d4887ab0fe86d4dce97c435009d1fd7.tar.gz
MAINT: Unify polynomial addition and subtraction functions
These functions are all the same - the algorithm used does not care about the basis.
Diffstat (limited to 'numpy/polynomial/polyutils.py')
-rw-r--r--numpy/polynomial/polyutils.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/numpy/polynomial/polyutils.py b/numpy/polynomial/polyutils.py
index 1d5390984..d8e922b0a 100644
--- a/numpy/polynomial/polyutils.py
+++ b/numpy/polynomial/polyutils.py
@@ -573,3 +573,30 @@ def _div(mul_f, c1, c2):
rem = rem[:-1] - q*p[:-1]
quo[i] = q
return quo, trimseq(rem)
+
+
+def _add(c1, c2):
+ """ Helper function used to implement the ``<type>add`` functions. """
+ # c1, c2 are trimmed copies
+ [c1, c2] = as_series([c1, c2])
+ if len(c1) > len(c2):
+ c1[:c2.size] += c2
+ ret = c1
+ else:
+ c2[:c1.size] += c1
+ ret = c2
+ return trimseq(ret)
+
+
+def _sub(c1, c2):
+ """ Helper function used to implement the ``<type>sub`` functions. """
+ # c1, c2 are trimmed copies
+ [c1, c2] = as_series([c1, c2])
+ if len(c1) > len(c2):
+ c1[:c2.size] -= c2
+ ret = c1
+ else:
+ c2 = -c2
+ c2[:c1.size] += c1
+ ret = c2
+ return trimseq(ret)