diff options
author | Stefan van der Walt <stefan@sun.ac.za> | 2007-02-09 17:55:37 +0000 |
---|---|---|
committer | Stefan van der Walt <stefan@sun.ac.za> | 2007-02-09 17:55:37 +0000 |
commit | de63203a32c9ce24cb1cd090a232c47833476dfd (patch) | |
tree | 42baf27f7be2d749dcca4e7d117849652202134a /numpy/core | |
parent | e7a51c37517f0fc62624c7e8e40d63ba416d096d (diff) | |
download | numpy-de63203a32c9ce24cb1cd090a232c47833476dfd.tar.gz |
Do not attempt to convolve empty arrays.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/numeric.py | 3 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 4329cae5c..b56dfbc44 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -219,8 +219,11 @@ def convolve(a,v,mode='full'): """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) diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 38607ba27..3f00beb6e 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -616,6 +616,11 @@ class test_regression(NumpyTestCase): 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() |