Custom lag parameters on numpy correlate and convolve functions

Hi all,

I have an open numpy PR (#31261) that adds maxlag and lags keyword parameters to np.correlate and np.convolve, allowing users to compute correlation/convolution at only a subset of lags rather than the full set. The motivation for this feature is that there are great performance improvements when the set of lags of interest is much smaller than the set of lags corresponding to any of the existing modes, as is frequently the case when analyzing long time series. There is also a new companion function np.correlation_lags() analogous to scipy.signal.correlation_lags() to allow a user to generate an array of the lags that correspond to the cross-correlation/convolution they calculated.

Matplotlib currently has a maxlags parameter on its xcorr() function, which calls np.correlate(). The matplotlib implementation calculates the full cross-correlation at all lags and then returns the relevant lags. So if this gets included in numpy, matplotlib can call the np.correlate() function with the new maxlag parameter to get the appropriate result with a huge performance improvement.

Two questions:

  • Would this functionality in numpy be of interest to matplotlib? Would you like a PR to use the new function keyword if it gets merged in numpy?
  • maxlag seems like a more appropriate name for this parameter in the numpy function than maxlags since it is a scalar value, and since it will be paired with a lags parameter that will actually be an array-like value. Does that difference of terminology bother you, as long as it is explicitly documented?

Looking forward to your thoughts,

Honi

xcorr is a convenience function merging data processing and visualization. We nowadays tend to keep these concerns separated and the is no ambition to support all parameters of underlying data processing functions.

Let’s not jump ahead. We can disucuss whether a we want to take any action when the numpy change is merged. Feel free to re-ping then.