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

numpy-svn@scip... numpy-svn@scip...
Thu Feb 1 14:34:58 CST 2007


Author: oliphant
Date: 2007-02-01 14:34:56 -0600 (Thu, 01 Feb 2007)
New Revision: 3530

Modified:
   trunk/numpy/lib/type_check.py
   trunk/numpy/lib/ufunclike.py
Log:
Allow matrices to pass through more functions.

Modified: trunk/numpy/lib/type_check.py
===================================================================
--- trunk/numpy/lib/type_check.py	2007-02-01 20:34:23 UTC (rev 3529)
+++ trunk/numpy/lib/type_check.py	2007-02-01 20:34:56 UTC (rev 3530)
@@ -6,7 +6,8 @@
            'common_type']
 
 import numpy.core.numeric as _nx
-from numpy.core.numeric import asarray, array, isnan, obj2sctype, zeros
+from numpy.core.numeric import asarray, asanyarray, array, isnan, \
+		obj2sctype, zeros
 from ufunclike import isneginf, isposinf
 
 _typecodes_by_elsize = 'GDFgdfQqLlIiHhBb?'
@@ -45,22 +46,21 @@
     dtype = _nx.obj2sctype(dtype)
     if not issubclass(dtype, _nx.inexact):
         dtype = _nx.float_
-    a = asarray(a,dtype=dtype)
-    return a
+    return asanyarray(a,dtype=dtype)
 
 def real(val):
     """Return the real part of val.
 
     Useful if val maybe a scalar or an array.
     """
-    return asarray(val).real
+    return asanyarray(val).real
 
 def imag(val):
     """Return the imaginary part of val.
 
     Useful if val maybe a scalar or an array.
     """
-    return asarray(val).imag
+    return asanyarray(val).imag
 
 def iscomplex(x):
     """Return a boolean array where elements are True if that element
@@ -68,7 +68,7 @@
 
     For scalars, return a boolean.
     """
-    ax = asarray(x)
+    ax = asanyarray(x)
     if issubclass(ax.dtype.type, _nx.complexfloating):
         return ax.imag != 0
     res = zeros(ax.shape, bool)
@@ -105,7 +105,7 @@
 
 def nan_to_num(x):
     """
-    Replaces NaN's with 0 and infinities with large numbers
+    Returns a copy of replacing NaN's with 0 and Infs with large numbers
 
     The following mappings are applied:
         NaN -> 0
@@ -118,10 +118,12 @@
         t = obj2sctype(type(x))
     if issubclass(t, _nx.complexfloating):
         y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)
-    elif issubclass(t, _nx.integer):
-        y = array(x)
     else:
-        y = array(x)
+        try:
+            y = x.copy()
+        except AttributeError:
+            y = array(x)
+    if not issubclass(t, _nx.integer):
         if not y.shape:
             y = array([x])
             scalar = True
@@ -146,7 +148,7 @@
 
     "Close enough" is defined as tol*(machine epsilon of a's element type).
     """
-    a = asarray(a)
+    a = asanyarray(a)
     if not issubclass(a.dtype.type, _nx.complexfloating):
         return a
     if tol > 1:

Modified: trunk/numpy/lib/ufunclike.py
===================================================================
--- trunk/numpy/lib/ufunclike.py	2007-02-01 20:34:23 UTC (rev 3529)
+++ trunk/numpy/lib/ufunclike.py	2007-02-01 20:34:56 UTC (rev 3530)
@@ -5,13 +5,13 @@
 __all__ = ['fix', 'isneginf', 'isposinf', 'log2']
 
 import numpy.core.numeric as nx
-from numpy.core.numeric import asarray, empty, isinf, signbit
+from numpy.core.numeric import asarray, empty, isinf, signbit, asanyarray
 import numpy.core.umath as umath
 
 def fix(x, y=None):
     """ Round x to nearest integer towards zero.
     """
-    x = asarray(x)
+    x = asanyarray(x)
     if y is None:
         y = nx.floor(x)
     else:
@@ -49,7 +49,7 @@
 
     If y is an array, the result replaces the contents of y.
     """
-    x = asarray(x)
+    x = asanyarray(x)
     if y is None:
         y = umath.log(x)
     else:



More information about the Numpy-svn mailing list