[Numpy-svn] r8466 - in branches/1.4.x/numpy/lib: . tests

numpy-svn@scip... numpy-svn@scip...
Sun Jun 27 06:09:58 CDT 2010


Author: ptvirtan
Date: 2010-06-27 06:09:58 -0500 (Sun, 27 Jun 2010)
New Revision: 8466

Modified:
   branches/1.4.x/numpy/lib/function_base.py
   branches/1.4.x/numpy/lib/tests/test_function_base.py
Log:
BUG (backport r8465): lib: fix sinc to handle array-like inputs properly (fixes #1523)

(cherry picked from r8465)

Modified: branches/1.4.x/numpy/lib/function_base.py
===================================================================
--- branches/1.4.x/numpy/lib/function_base.py	2010-06-27 11:07:15 UTC (rev 8465)
+++ branches/1.4.x/numpy/lib/function_base.py	2010-06-27 11:09:58 UTC (rev 8466)
@@ -2688,6 +2688,7 @@
     >>> plt.imshow(np.sinc(xx))
 
     """
+    x = np.asanyarray(x)
     y = pi* where(x == 0, 1.0e-20, x)
     return sin(y)/y
 

Modified: branches/1.4.x/numpy/lib/tests/test_function_base.py
===================================================================
--- branches/1.4.x/numpy/lib/tests/test_function_base.py	2010-06-27 11:07:15 UTC (rev 8465)
+++ branches/1.4.x/numpy/lib/tests/test_function_base.py	2010-06-27 11:09:58 UTC (rev 8466)
@@ -438,8 +438,16 @@
         assert(sinc(0)==1)
         w=sinc(linspace(-1,1,100))
         #check symmetry
-        assert_array_almost_equal(w,flipud(w),7)
+        assert_array_almost_equal(w, flipud(w), 7)
 
+    def test_array_like(self):
+        x = [0, 0.5]
+        y1 = sinc(array(x))
+        y2 = sinc(list(x))
+        y3 = sinc(tuple(x))
+        assert_array_equal(y1, y2)
+        assert_array_equal(y1, y3)
+
 class TestHistogram(TestCase):
     def setUp(self):
         warnings.simplefilter('ignore', DeprecationWarning)



More information about the Numpy-svn mailing list