open-cogsci / datamatrix

An intuitive, Pythonic way to work with tabular data
https://pydatamatrix.eu/
GNU General Public License v3.0
25 stars 10 forks source link

problem with _blinkreconstruct_recursive #19

Closed navidivan closed 11 months ago

navidivan commented 11 months ago

In the _blinkreconstruct_recursive function, processed_blink_points is used to keep track of blink points processed in recursive calls. Since this list is not reinitialized on subsequent function calls, it retains its state from previous runs, leading to the "infinite loop" warning and incorrect behavior in subsequent runs.

To fix this issue, you should initialize processed_blink_points within the function rather than using it as a default argument. Here's the corrected version of _blinkreconstruct_recursive:

python

def _blinkreconstruct_recursive(a, vt_start=10, vt_end=5, maxdur=500, margin=10, gap_margin=20, gap_vt=10, smooth_winlen=21, std_thr=3, processed_blink_points=None): """Implements a recursive blink-reconstruction algorithm."""

# Initialize processed_blink_points if it's None
if processed_blink_points is None:
    processed_blink_points = []

def fnc_recursive(a):
    """Shortcut for recursive function call that retains all keywords."""
    return _blinkreconstruct_recursive(
        a, vt_start=vt_start, vt_end=vt_end, maxdur=maxdur, margin=margin,
        gap_margin=gap_margin, gap_vt=gap_vt, smooth_winlen=smooth_winlen,
        std_thr=std_thr, processed_blink_points=processed_blink_points)

# ... rest of the function

return fnc_recursive(a)

With this change, processed_blink_points is initialized as an empty list on each top-level call to _blinkreconstruct_recursive, preventing the retention of state across different invocations of the function.

smathot commented 11 months ago

Thanks for spotting this!