Skip to content

Crash in signal.lfilter on nd input with wrong shaped zi #4612

@ewmoore

Description

@ewmoore
import numpy as np
from scipy import signal

y, zf = signal.lfilter([1,1], [1.], np.arange(12).reshape((4,3)), 0, [[1]])

On Windows 7, python 2.7, scipy 0.15.1 from anaconda64 this crashes.

Running on the same on Linux (python 2.7, scipy 0.15.1, from anaconda64) i get:

In [7]: y
Out[7]:
array([[  1.,   1.,   2.],
       [  3.,   5.,   7.],
       [  9.,  11.,  13.],
       [ 15.,  17.,  19.]])

In [8]: zf
Out[8]: array([[ 9.]])

Which still seems wrong, shouldn't this fail and complain about a zi having the wrong shape? Even if it would take a (1,1) shaped zi shouldn't the produced zf be (4,1) in this case? AFAICT, the handling of initial conditions for multidimensional x is not quite right. For instance, there is also this issue:

In [16]: signal.lfilter([1, -1], [1.], np.arange(10).reshape(2,5), 1, [[1],[1],[1],[1]])
Out[16]: 
(array([[ 1.,  1.,  1.,  1.,  1.],
        [ 6.,  1.,  1.,  1.,  1.]]), array([[ -4.00000000e+00],
        [ -9.00000000e+00],
        [  2.52787376e-45],
        [  2.64228486e-58]]))

Which gives the same uninitialized junk on both Windows and Linux. This makes me think the code that does not crash on Linux is just getting lucky and not crashing even though it is still stepping past the array bounds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.signal

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions