[Numpy-svn] r5660 - in trunk/numpy: core lib
numpy-svn at scipy.org
numpy-svn at scipy.org
Fri Aug 15 17:15:59 EDT 2008
Author: oliphant
Date: 2008-08-15 16:15:58 -0500 (Fri, 15 Aug 2008)
New Revision: 5660
Modified:
trunk/numpy/core/defmatrix.py
trunk/numpy/core/numerictypes.py
trunk/numpy/lib/utils.py
Log:
Re-factor code to remove dependency of numpy.core on numpy.lib by moving issubclass_, issubsctype, and issubdtype to numpy.core.numerictypes
Modified: trunk/numpy/core/defmatrix.py
===================================================================
--- trunk/numpy/core/defmatrix.py 2008-08-15 15:00:43 UTC (rev 5659)
+++ trunk/numpy/core/defmatrix.py 2008-08-15 21:15:58 UTC (rev 5660)
@@ -3,7 +3,7 @@
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
Modified: trunk/numpy/core/numerictypes.py
===================================================================
--- trunk/numpy/core/numerictypes.py 2008-08-15 15:00:43 UTC (rev 5659)
+++ trunk/numpy/core/numerictypes.py 2008-08-15 21:15:58 UTC (rev 5660)
@@ -484,6 +484,49 @@
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):
Modified: trunk/numpy/lib/utils.py
===================================================================
--- trunk/numpy/lib/utils.py 2008-08-15 15:00:43 UTC (rev 5659)
+++ trunk/numpy/lib/utils.py 2008-08-15 21:15:58 UTC (rev 5660)
@@ -4,7 +4,8 @@
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 @@
'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.
More information about the Numpy-svn
mailing list