[Numpy-svn] r3544 - in trunk/numpy/core: . tests

numpy-svn@scip... numpy-svn@scip...
Fri Feb 9 11:55:48 CST 2007


Author: stefan
Date: 2007-02-09 11:55:37 -0600 (Fri, 09 Feb 2007)
New Revision: 3544

Modified:
   trunk/numpy/core/numeric.py
   trunk/numpy/core/tests/test_regression.py
Log:
Do not attempt to convolve empty arrays.


Modified: trunk/numpy/core/numeric.py
===================================================================
--- trunk/numpy/core/numeric.py	2007-02-09 17:34:23 UTC (rev 3543)
+++ trunk/numpy/core/numeric.py	2007-02-09 17:55:37 UTC (rev 3544)
@@ -219,8 +219,11 @@
     """Returns the discrete, linear convolution of 1-D sequences a and v; mode
     can be 'valid', 'same', or 'full' to specify size of the resulting sequence.
     """
+    a,v = array(a,ndmin=1),array(v,ndmin=1)
     if (len(v) > len(a)):
         a, v = v, a
+    assert len(a) > 0, 'a cannot be empty'
+    assert len(v) > 0, 'v cannot be empty'
     mode = _mode_from_name(mode)
     return multiarray.correlate(a,asarray(v)[::-1],mode)
 

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2007-02-09 17:34:23 UTC (rev 3543)
+++ trunk/numpy/core/tests/test_regression.py	2007-02-09 17:55:37 UTC (rev 3544)
@@ -616,6 +616,11 @@
     def check_mem_polymul(self, level=rlevel):
         """Ticket #448"""
         N.polymul([],[1.])
+        
+    def check_convolve_empty(self, level=rlevel):
+        """Convolve should raise an error for empty input array."""
+        self.failUnlessRaises(AssertionError,N.convolve,[],[1])
+        self.failUnlessRaises(AssertionError,N.convolve,[1],[])
 
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list