[Scipy-svn] r4863 - in trunk/scipy/integrate: . tests

scipy-svn@scip... scipy-svn@scip...
Sat Nov 1 05:57:00 CDT 2008


Author: stefan
Date: 2008-11-01 05:56:47 -0500 (Sat, 01 Nov 2008)
New Revision: 4863

Modified:
   trunk/scipy/integrate/quadrature.py
   trunk/scipy/integrate/tests/test_quadrature.py
Log:
Fix internally used vectorize1 to work with functions that return floats
[patch by Neil Muller].  Closes #288.


Modified: trunk/scipy/integrate/quadrature.py
===================================================================
--- trunk/scipy/integrate/quadrature.py	2008-10-29 22:42:23 UTC (rev 4862)
+++ trunk/scipy/integrate/quadrature.py	2008-11-01 10:56:47 UTC (rev 4863)
@@ -59,7 +59,10 @@
             # call with first point to get output type
             y0 = func(x[0], *args)
             n = len(x)
-            output = empty((n,), dtype=y0.dtype)
+            if hasattr(y0, 'dtype'):
+                output = empty((n,), dtype=y0.dtype)
+            else:
+                output = empty((n,), dtype=type(y0))
             output[0] = y0
             for i in xrange(1, n):
                 output[i] = func(x[i], *args)

Modified: trunk/scipy/integrate/tests/test_quadrature.py
===================================================================
--- trunk/scipy/integrate/tests/test_quadrature.py	2008-10-29 22:42:23 UTC (rev 4862)
+++ trunk/scipy/integrate/tests/test_quadrature.py	2008-11-01 10:56:47 UTC (rev 4863)
@@ -28,5 +28,13 @@
     def test_romb(self):
         assert_equal(romb(numpy.arange(17)),128)
 
+    def test_non_dtype(self):
+        # Check that we work fine with functions returning float
+        import math
+        valmath = romberg(math.sin, 0, 1)
+        expected_val = 0.45969769413185085
+        assert_almost_equal(valmath, expected_val, decimal=7)
+
+
 if __name__ == "__main__":
     run_module_suite()



More information about the Scipy-svn mailing list