def test_1d_filter():
    """Test our private overlap-add filtering function"""
    # make some random signals and filters
    for n_signal in (1, 2, 5, 10, 20, 40, 100, 200, 400, 1000, 2000):
        x = rng.randn(n_signal)
        for n_filter in (2, 5, 10, 20, 40, 100, 200, 400, 1000, 2000):
            # Don't test n_filter == 1 because scipy can't handle it.
            if n_filter > n_signal:
                continue  # only equal or lesser lengths supported
            for filter_type in ('identity', 'random'):
                if filter_type == 'random':
                    h = rng.randn(n_filter)
                else:  # filter_type == 'identity'
                    h = np.concatenate([[1.], np.zeros(n_filter - 1)])
                # ensure we pad the signal the same way for both filters
                n_pad = max(min(n_filter, n_signal - 1), 0)
                x_pad = _smart_pad(x, np.array([n_pad, n_pad]))
                for zero_phase in (True, False):
                    # compute our expected result the slow way
                    if zero_phase:
                        x_expected = np.convolve(x_pad, h)[::-1]
                        x_expected = np.convolve(x_expected, h)[::-1]
                        x_expected = x_expected[len(h) - 1:-(len(h) - 1)]
                    else:
                        x_expected = np.convolve(x_pad, h)
                        x_expected = x_expected[:-(len(h) - 1)]
                    # remove padding
                    if n_pad > 0:
                        x_expected = x_expected[n_pad:-n_pad]
                    # make sure we actually set things up reasonably
                    if filter_type == 'identity':
                        assert_allclose(x_expected, x)
                    # compute our version
                    for n_fft in (None, 32, 128, 129, 1023, 1024, 1025, 2048):
                        # need to use .copy() b/c signal gets modified inplace
                        x_copy = x[np.newaxis, :].copy()
                        if (n_fft is not None and n_fft < 2 * n_filter - 1 and
                                zero_phase):
                            assert_raises(ValueError, _overlap_add_filter,
                                          x_copy, h, n_fft, zero_phase)
                        elif (n_fft is not None and n_fft < n_filter and not
                                zero_phase):
                            assert_raises(ValueError, _overlap_add_filter,
                                          x_copy, h, n_fft, zero_phase)
                        else:
                            # bad len warning
                            with warnings.catch_warnings(record=True):
                                x_filtered = _overlap_add_filter(
                                    x_copy, h, n_fft, zero_phase)[0]
                            assert_allclose(x_expected, x_filtered)
dataset/ETHPy150Open mne-tools/mne-python/mne/tests/test_filter.py/test_1d_filter/original