changeset 78:2357a9a5fc34

make simplify more NumPy compatible
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 18 Sep 2009 06:57:23 +0200
parents fb227ceacc65
children d60165bfc849
files ChangeLog package/pytave.py
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Sep 18 06:14:59 2009 +0200
+++ b/ChangeLog	Fri Sep 18 06:57:23 2009 +0200
@@ -1,3 +1,7 @@
+2009-09-18  Jaroslav Hajek  <highegg@gmail.com>
+
+	* package/pytave.py (simplify): Improve NumPy compatibility.
+
 2009-09-17  Jaroslav Hajek  <highegg@gmail.com>
 
 	* pytave.cc: Move #include of arrayobjectdefs after pytavedefs to
--- a/package/pytave.py	Fri Sep 18 06:14:59 2009 +0200
+++ b/package/pytave.py	Fri Sep 18 06:57:23 2009 +0200
@@ -187,13 +187,21 @@
     1xN and 0x0 character arrays to strings, 1xN, Nx1 and 0x0 cell
     arrays to lists, and strip scalar dicts. It will work recursively."""
 
+    def get_typecode(array):
+	"""gets the typecode from both Numeric and NumPy array"""
+	try:
+	    tc = array.typecode
+	except:
+	    tc = array.dtype.char
+	return tc
+
     def vectordims(dims,column_allowed = True):
 	return (len(dims) == 2 and 
 		((dims[0] == 1 or (column_allowed and dims[1] == 1)) or
 		(dims[0] == 0 and dims[1] == 0)))
 
     if isinstance(obj,Numeric.ArrayType):
-	tc = obj.typecode()
+	tc = get_typecode(obj)
 	if tc == 'O':
 	    if vectordims(Numeric.shape(obj)):
 		return map(simplify,narrowlist(obj))
@@ -203,7 +211,7 @@
 	else:
 	    dims = Numeric.shape(obj)
 	    if dims == (1,1):
-		return obj.toscalar()
+		return obj[0,0]
 	    elif vectordims(dims):
 		return Numeric.ravel(obj)
     elif isinstance(obj,dict):