diff options
-rw-r--r-- | numpy/core/defmatrix.py | 2 | ||||
-rw-r--r-- | numpy/core/numerictypes.py | 43 | ||||
-rw-r--r-- | numpy/lib/utils.py | 45 |
3 files changed, 46 insertions, 44 deletions
diff --git a/numpy/core/defmatrix.py b/numpy/core/defmatrix.py index 1707e49fd..97602918d 100644 --- a/numpy/core/defmatrix.py +++ b/numpy/core/defmatrix.py @@ -3,7 +3,7 @@ __all__ = ['matrix', 'bmat', 'mat', 'asmatrix'] import sys import numeric as N from numeric import concatenate, isscalar, binary_repr, identity -from numpy.lib.utils import issubdtype +from numerictypes import issubdtype # make translation table _table = [None]*256 diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index 548740eb1..ad555f2e0 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -484,6 +484,49 @@ def obj2sctype(rep, default=None): return res.type +def issubclass_(arg1, arg2): + try: + return issubclass(arg1, arg2) + except TypeError: + return False + +def issubsctype(arg1, arg2): + return issubclass(obj2sctype(arg1), obj2sctype(arg2)) + +def issubdtype(arg1, arg2): + """ + Returns True if first argument is a typecode lower/equal in type hierarchy. + + Parameters + ---------- + arg1 : dtype_like + dtype or string representing a typecode. + arg2 : dtype_like + dtype or string representing a typecode. + + + See Also + -------- + numpy.core.numerictypes : Overview of numpy type hierarchy. + + Examples + -------- + >>> np.issubdtype('S1', str) + True + >>> np.issubdtype(np.float64, np.float32) + False + + """ + if issubclass_(arg2, generic): + return issubclass(dtype(arg1).type, arg2) + mro = dtype(arg2).type.mro() + if len(mro) > 1: + val = mro[1] + else: + val = mro[0] + return issubclass(dtype(arg1).type, val) + + # This dictionary allows look up based on any alias for an array data-type class _typedict(dict): def __getitem__(self, obj): diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index bb162bfd3..684876591 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -4,7 +4,8 @@ import pkgutil import types import re -from numpy.core.numerictypes import obj2sctype, generic +from numpy.core.numerictypes import obj2sctype, generic, issubclass_, \ + issubsctype, issubdtype from numpy.core.multiarray import dtype as _dtype from numpy.core import product, ndarray @@ -14,48 +15,6 @@ __all__ = ['issubclass_', 'get_numpy_include', 'issubsctype', 'get_include', 'info', 'source', 'who', 'lookfor', 'byte_bounds', 'may_share_memory', 'safe_eval'] -def issubclass_(arg1, arg2): - try: - return issubclass(arg1, arg2) - except TypeError: - return False - -def issubsctype(arg1, arg2): - return issubclass(obj2sctype(arg1), obj2sctype(arg2)) - -def issubdtype(arg1, arg2): - """ - Returns True if first argument is a typecode lower/equal in type hierarchy. - - Parameters - ---------- - arg1 : dtype_like - dtype or string representing a typecode. - arg2 : dtype_like - dtype or string representing a typecode. - - - See Also - -------- - numpy.core.numerictypes : Overview of numpy type hierarchy. - - Examples - -------- - >>> np.issubdtype('S1', str) - True - >>> np.issubdtype(np.float64, np.float32) - False - - """ - if issubclass_(arg2, generic): - return issubclass(_dtype(arg1).type, arg2) - mro = _dtype(arg2).type.mro() - if len(mro) > 1: - val = mro[1] - else: - val = mro[0] - return issubclass(_dtype(arg1).type, val) - def get_include(): """ Return the directory that contains the numpy \\*.h header files. |