summaryrefslogtreecommitdiff
path: root/numpy/polynomial/polytemplate.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2014-05-04 07:35:14 -0600
committerCharles Harris <charlesr.harris@gmail.com>2014-05-04 07:35:14 -0600
commitac92c617851994ac1f400886c736cd4d44e2c836 (patch)
tree94a46e2f418cf34b48f2401f145200c0c2469017 /numpy/polynomial/polytemplate.py
parent2142962868687eba3d05f9e50a6648a1b9b3c185 (diff)
parent24a0fd428b80d8db50a9bd5f1c151d3a99bcdcb2 (diff)
downloadnumpy-ac92c617851994ac1f400886c736cd4d44e2c836.tar.gz
Merge pull request #4633 from charris/fix-polynomial-true-division
Fix polynomial true division
Diffstat (limited to 'numpy/polynomial/polytemplate.py')
-rw-r--r--numpy/polynomial/polytemplate.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/numpy/polynomial/polytemplate.py b/numpy/polynomial/polytemplate.py
index eeacf24fb..6c60ab3b2 100644
--- a/numpy/polynomial/polytemplate.py
+++ b/numpy/polynomial/polytemplate.py
@@ -14,6 +14,7 @@ from __future__ import division, absolute_import, print_function
import string
import sys
import warnings
+from number import Number
from numpy import ModuleDeprecationWarning
@@ -287,15 +288,13 @@ class $name(pu.PolyBase) :
return self.__floordiv__(other)
def __truediv__(self, other) :
- # there is no true divide if the rhs is not a scalar, although it
+ # there is no true divide if the rhs is not a Number, although it
# could return the first n elements of an infinite series.
# It is hard to see where n would come from, though.
- if np.isscalar(other) :
- # this might be overly restrictive
- coef = self.coef/other
- return self.__class__(coef, self.domain, self.window)
- else :
- return NotImplemented
+ if not isinstance(other, Number) or isinstance(other, bool):
+ form = "unsupported types for true division: '%s', '%s'"
+ raise TypeError(form % (type(self), type(other)))
+ return self.__floordiv__(other)
def __floordiv__(self, other) :
"""Returns the quotient."""
@@ -384,20 +383,14 @@ class $name(pu.PolyBase) :
return self.__rfloordiv__(other)
def __rtruediv__(self, other) :
- # there is no true divide if the rhs is not a scalar, although it
- # could return the first n elements of an infinite series.
- # It is hard to see where n would come from, though.
- if len(self.coef) == 1 :
- try :
- quo, rem = ${nick}div(other, self.coef[0])
- except :
- return NotImplemented
- return self.__class__(quo, self.domain, self.window)
+ # An instance of PolyBase is not considered a
+ # Number.
+ return NotImplemented
def __rfloordiv__(self, other) :
try :
quo, rem = ${nick}div(other, self.coef)
- except :
+ except:
return NotImplemented
return self.__class__(quo, self.domain, self.window)