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

numpy-svn@scip... numpy-svn@scip...
Thu Mar 18 16:43:07 CDT 2010


Author: ptvirtan
Date: 2010-03-18 16:43:07 -0500 (Thu, 18 Mar 2010)
New Revision: 8297

Modified:
   trunk/numpy/lib/function_base.py
   trunk/numpy/lib/tests/test_function_base.py
Log:
BUG: lib: fix #1435, np.gradient should use zeros_like

Thanks to Ryan May for the patch.

Modified: trunk/numpy/lib/function_base.py
===================================================================
--- trunk/numpy/lib/function_base.py	2010-03-18 21:41:03 UTC (rev 8296)
+++ trunk/numpy/lib/function_base.py	2010-03-18 21:43:07 UTC (rev 8297)
@@ -808,7 +808,7 @@
 
     for axis in range(N):
         # select out appropriate parts for this dimension
-        out = zeros(f.shape, f.dtype.char)
+        out = np.zeros_like(f).astype(otype)
         slice1[axis] = slice(1, -1)
         slice2[axis] = slice(2, None)
         slice3[axis] = slice(None, -2)

Modified: trunk/numpy/lib/tests/test_function_base.py
===================================================================
--- trunk/numpy/lib/tests/test_function_base.py	2010-03-18 21:41:03 UTC (rev 8296)
+++ trunk/numpy/lib/tests/test_function_base.py	2010-03-18 21:43:07 UTC (rev 8297)
@@ -266,6 +266,11 @@
         assert_raises(SyntaxError, gradient, x, array([1.,1.]),
                       array([1.,1.]), array([1.,1.]))
 
+    def test_masked(self):
+        # Make sure that gradient supports subclasses like masked arrays
+        x = np.ma.array([[1,1],[3,4]])
+        assert_equal(type(gradient(x)[0]), type(x))
+
 class TestAngle(TestCase):
     def test_basic(self):
         x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]



More information about the Numpy-svn mailing list