[Numpy-svn] r3007 - trunk/numpy/lib

numpy-svn at scipy.org numpy-svn at scipy.org
Sun Aug 13 05:06:50 CDT 2006


Author: oliphant
Date: 2006-08-13 05:06:48 -0500 (Sun, 13 Aug 2006)
New Revision: 3007

Modified:
   trunk/numpy/lib/utils.py
Log:
Allow for type-less ndpointer.

Modified: trunk/numpy/lib/utils.py
===================================================================
--- trunk/numpy/lib/utils.py	2006-08-13 10:03:13 UTC (rev 3006)
+++ trunk/numpy/lib/utils.py	2006-08-13 10:06:48 UTC (rev 3007)
@@ -93,7 +93,7 @@
     def from_param(cls, obj):
         if not isinstance(obj, ndarray):
             raise TypeError("argument must be an ndarray")
-        if obj.dtype != cls._dtype_:
+        if cls._dtype_ and obj.dtype != cls._dtype_:
             raise TypeError("array must have data type", cls._dtype_)
         if cls._ndim_ and obj.ndim != cls._ndim_:
             raise TypeError("array must have %d dimension(s)" % cls._ndim_)
@@ -107,8 +107,9 @@
 
 # Factory for an array-checking object with from_param defined
 _pointer_type_cache = {}
-def ndpointer(datatype, ndim=None, shape=None, flags=None):
-    datatype = dtype(datatype)
+def ndpointer(datatype=None, ndim=None, shape=None, flags=None):
+    if datatype is not None:
+        datatype = dtype(datatype)
     num = None
     if flags is not None:
         if isinstance(flags, str):
@@ -122,8 +123,10 @@
     try:
         return _pointer_type_cache[(datatype, ndim, shape, num)]
     except KeyError:
-        pass        
-    if datatype.names:
+        pass
+    if datatype is None:
+        name = 'any'
+    elif datatype.names:
         name = str(id(datatype))
     else:
         name = datatype.str



More information about the Numpy-svn mailing list