[Numpy-svn] r8293 - in trunk/numpy/lib: . tests

numpy-svn@scip... numpy-svn@scip...
Sun Mar 14 13:44:37 CDT 2010


Author: darren.dale
Date: 2010-03-14 13:44:36 -0500 (Sun, 14 Mar 2010)
New Revision: 8293

Modified:
   trunk/numpy/lib/tests/test_ufunclike.py
   trunk/numpy/lib/ufunclike.py
Log:
minor change to ufunclike.fix, one less array to build and make compatible
with subclasses of ndarray


Modified: trunk/numpy/lib/tests/test_ufunclike.py
===================================================================
--- trunk/numpy/lib/tests/test_ufunclike.py	2010-03-11 23:32:41 UTC (rev 8292)
+++ trunk/numpy/lib/tests/test_ufunclike.py	2010-03-14 18:44:36 UTC (rev 8293)
@@ -58,10 +58,28 @@
 """
 
 from numpy.testing import *
+import numpy.core as nx
+import numpy.lib.ufunclike as ufl
 
 def test():
     return rundocs()
 
+def test_fix_with_subclass():
+    class MyArray(nx.ndarray):
+        def __new__(cls, data, metadata=None):
+            res = nx.array(data, copy=True).view(cls)
+            res.metadata = metadata
+            return res
+        def __array_wrap__(self, obj, context=None):
+            obj.metadata = self.metadata
+            return obj
+            
+    a = nx.array([1.1, -1.1])
+    m = MyArray(a, metadata='foo')
+    f = ufl.fix(m)
+    assert_array_equal(f, nx.array([1,-1]))
+    assert isinstance(f, MyArray)
+    assert_equal(f.metadata, 'foo')
 
 if __name__ == "__main__":
     run_module_suite()

Modified: trunk/numpy/lib/ufunclike.py
===================================================================
--- trunk/numpy/lib/ufunclike.py	2010-03-11 23:32:41 UTC (rev 8292)
+++ trunk/numpy/lib/ufunclike.py	2010-03-14 18:44:36 UTC (rev 8293)
@@ -41,10 +41,10 @@
 
     """
     x = nx.asanyarray(x)
-    if y is None:
-        y = nx.zeros_like(x)
     y1 = nx.floor(x)
     y2 = nx.ceil(x)
+    if y is None:
+        y = y1
     y[...] = nx.where(x >= 0, y1, y2)
     return y
 



More information about the Numpy-svn mailing list