[Matrix-SIG] Bug in convolve.
Tim Hochberg
tim.hochberg@ieee.org
Thu, 22 Oct 1998 07:39:22 -0600
While working on JNumeric I found what appears to be a bug in convolve.
Here's an illustration:
CNumeric:
>>> from Numeric import *
>>> a = arange(5)
>>> convolve(a,a,2)
array([ 0, 4, 11, 20, 30, 20, 11, 4, 0])
>>> convolve(a,a[::-1],2)
array([ 0, 0, 1, 4, 10, 20, 25, 24, 16])
>>> convolve(a[::-1],a,2)
array([16, 24, 25, 20, 10, 4, 1, 0, 0])
JNumeric:
>>> from Numeric import *
>>> a = arange(5)
>>> convolve(a,a,2)
array([ 0, 0, 1, 4, 10, 20, 25, 24, 16])
>>> convolve(a, a[::-1], 2)
array([ 0, 4, 11, 20, 30, 20, 11, 4, 0])
>>> convolve(a[::-1], a, 2)
array([ 0, 4, 11, 20, 30, 20, 11, 4, 0])
One of these is obviously wrong. Since convolve(a, b) = convolve(b,a) should
hold, the culprit appears to be CNumeric's convolve. It appears that:
convolve_CNumeric(a, b, mode) = convolve_JNumeric(a, b[::-1], mode)
This means a quick fix could be implemented in Python by defining:
def convolve(a, b, mode=0):
return convolve(a, b[::-1], mode)
in Numeric.
____
/im (tim.hochberg@ieee.org)