{"action":"created","issue":{"url":"https://api.github.com/repos/numpy/numpy/issues/5978","labels_url":"https://api.github.com/repos/numpy/numpy/issues/5978/labels{/name}","comments_url":"https://api.github.com/repos/numpy/numpy/issues/5978/comments","events_url":"https://api.github.com/repos/numpy/numpy/issues/5978/events","html_url":"https://github.com/numpy/numpy/pull/5978","id":89121570,"number":5978,"title":"ENH: adding maxlag mode to convolve and correlate","user":{"login":"bringingheavendown","id":6538616,"avatar_url":"https://avatars.githubusercontent.com/u/6538616?v=3","gravatar_id":"","url":"https://api.github.com/users/bringingheavendown","html_url":"https://github.com/bringingheavendown","followers_url":"https://api.github.com/users/bringingheavendown/followers","following_url":"https://api.github.com/users/bringingheavendown/following{/other_user}","gists_url":"https://api.github.com/users/bringingheavendown/gists{/gist_id}","starred_url":"https://api.github.com/users/bringingheavendown/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bringingheavendown/subscriptions","organizations_url":"https://api.github.com/users/bringingheavendown/orgs","repos_url":"https://api.github.com/users/bringingheavendown/repos","events_url":"https://api.github.com/users/bringingheavendown/events{/privacy}","received_events_url":"https://api.github.com/users/bringingheavendown/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/numpy/numpy/labels/component:%20numpy.core","name":"component: numpy.core","color":"ff0000"},{"url":"https://api.github.com/repos/numpy/numpy/labels/Enhancement","name":"Enhancement","color":"e102d8"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-06-17T20:44:12Z","updated_at":"2015-06-23T06:38:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/numpy/numpy/pulls/5978","html_url":"https://github.com/numpy/numpy/pull/5978","diff_url":"https://github.com/numpy/numpy/pull/5978.diff","patch_url":"https://github.com/numpy/numpy/pull/5978.patch"},"body":"What was troubling me is that numpy.correlate does not have a maxlag feature. This means that even if I only want to see correlations between two time series with lags between -100 and +100 ms, for example, it will still calculate the correlation for every lag between -20000 and +20000 ms (which is the length of the time series). This (theoretically) gives a 200x performance hit! Is it possible that I could contribute this feature?\r\n\r\nI have introduced this question as a [numpy issue](https://github.com/numpy/numpy/issues/5954), a [scipy issue](https://github.com/scipy/scipy/issues/4940) and on the [scipy-dev list](http://mail.scipy.org/pipermail/scipy-dev/2015-June/020757.html).  It seems the best place to start is with numpy.correlate, so that is what I am requesting.  \r\n\r\nThis is my first experience with contributing to open-source software, so any pointers are appreciated. \r\n\r\nPrevious discussion of this functionality can be found at [another discussion on numpy correlate (and convolution)](http://numpy-discussion.10968.n7.nabble.com/another-discussion-on-numpy-correlate-and-convolution-td32925.html).  Other issues related to correlate functions include [ENH: Fold fftconvolve into convolve/correlate functions as a parameter #2651](https://github.com/scipy/scipy/issues/2651), [Use FFT in np.correlate/convolve? (Trac #1260) #1858](https://github.com/numpy/numpy/issues/1858), and [normalized cross-correlation (Trac #1714) #2310](https://github.com/numpy/numpy/issues/2310).\r\n\r\n\r\nI have added extra options for the \"mode\" parameter, namely an int or an int tuple that determine for which lags the correlation/convolution should be calculated.  These correspond to the values in the vector that the same tuple would generate if used as an argument to the numpy.arange() function.  \r\n\r\nHere are the specific issues that could use attention in this implementation:\r\n\r\nIs it ok that this implementation breaks the previous undocumented behavior of mode=0, 1, or 2 returning the correlation for mode='valid', 'same', or 'full' respectively? If not, how should maxlag input be passed?\r\nShould the checks that are included in convolve() be added to correlate()?\r\nIs it ok that I used NPY_MAX_INT to represent requests for a default argument in the C code?\r\nDo I need to check for \"default arguments\" at all, given that the calling functions should now always call _pyarray_correlate with the appropriate number of arguments? I kind of feel there is some legacy behavior I should be maintaining, but I'm not 100% sure.\r\nIs the error message in _pyarray_correlate \"PyErr_SetString(PyExc_ValueError, \"mode must be 0, 1, 2, or 3\")\" still valuable? What should it be replaced with?\r\nAre there other error checks I should add to the code at this or other points?\r\nCould you all clean up the unit tests/add some new ones to be absolutely sure that it deals properly with weird combinations of input array sizes and lag inputs? I couldn't figure out how to run all the same unit tests with the order of input arrays switched."},"comment":{"url":"https://api.github.com/repos/numpy/numpy/issues/comments/114377444","html_url":"https://github.com/numpy/numpy/pull/5978#issuecomment-114377444","issue_url":"https://api.github.com/repos/numpy/numpy/issues/5978","id":114377444,"user":{"login":"rgommers","id":98330,"avatar_url":"https://avatars.githubusercontent.com/u/98330?v=3","gravatar_id":"","url":"https://api.github.com/users/rgommers","html_url":"https://github.com/rgommers","followers_url":"https://api.github.com/users/rgommers/followers","following_url":"https://api.github.com/users/rgommers/following{/other_user}","gists_url":"https://api.github.com/users/rgommers/gists{/gist_id}","starred_url":"https://api.github.com/users/rgommers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rgommers/subscriptions","organizations_url":"https://api.github.com/users/rgommers/orgs","repos_url":"https://api.github.com/users/rgommers/repos","events_url":"https://api.github.com/users/rgommers/events{/privacy}","received_events_url":"https://api.github.com/users/rgommers/received_events","type":"User","site_admin":false},"created_at":"2015-06-23T06:38:27Z","updated_at":"2015-06-23T06:38:27Z","body":"Style comment: it would be good to put most comments above the code instead of behind it. This is what our C style guide says (https://github.com/numpy/numpy/blob/master/doc/C_STYLE_GUIDE.rst.txt)\r\nThe current code is hardly readable with my default editor width of just over 80 chars."}}