{"action":"created","issue":{"url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1792","labels_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1792/labels{/name}","comments_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1792/comments","events_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1792/events","html_url":"https://github.com/scikit-image/scikit-image/pull/1792","id":119646819,"number":1792,"title":"Uses fftconvolve instead of convolve2d for speedups","user":{"login":"scottsievert","id":1320475,"avatar_url":"https://avatars.githubusercontent.com/u/1320475?v=3","gravatar_id":"","url":"https://api.github.com/users/scottsievert","html_url":"https://github.com/scottsievert","followers_url":"https://api.github.com/users/scottsievert/followers","following_url":"https://api.github.com/users/scottsievert/following{/other_user}","gists_url":"https://api.github.com/users/scottsievert/gists{/gist_id}","starred_url":"https://api.github.com/users/scottsievert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottsievert/subscriptions","organizations_url":"https://api.github.com/users/scottsievert/orgs","repos_url":"https://api.github.com/users/scottsievert/repos","events_url":"https://api.github.com/users/scottsievert/events{/privacy}","received_events_url":"https://api.github.com/users/scottsievert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-12-01T05:47:39Z","updated_at":"2015-12-01T21:22:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1792","html_url":"https://github.com/scikit-image/scikit-image/pull/1792","diff_url":"https://github.com/scikit-image/scikit-image/pull/1792.diff","patch_url":"https://github.com/scikit-image/scikit-image/pull/1792.patch"},"body":"This pull request uses [`scipy.signal.fftconvolve`] instead of [`scipy.signal.convolve2d`] in skimage/restoration/deconvolution.py. These are equivalent functions, as noted in [this StackOverflow answer] but `fftconvolve` is much faster. Quoting the documentation page for fftconvolve,\r\n\r\n> This is generally much faster than convolve for large arrays (n > ~500)\r\n\r\nThis function change gives equivalent results (up a to a machine epsilon) as indicated by the test below:\r\n\r\n[this StackOverflow answer]:http://stackoverflow.com/a/1768140/1141256\r\n\r\n```python\r\nfrom scipy.signal import convolve2d, fftconvolve\r\nimport numpy as np\r\n\r\nN, m = 1e3, 10\r\nnp.random.seed(42)\r\nx = np.random.randn(int(N), int(N))\r\nh = np.ones((m, m)) / m**2\r\n\r\ny1 = convolve2d(x, h, mode='same')\r\ny2 = fftconvolve(x, h, mode='same')\r\n\r\nassert np.allclose(y1, y2)\r\n\r\nprint(\"{:0.4e}\".format(np.max(np.abs(y1 - y2)))) # prints 1.7876e-15\r\n```\r\n\r\nWhen I use `N = 1e3`, I see speedups of roughly 6x.\r\n\r\n[`scipy.signal.fftconvolve`]:http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.fftconvolve.html#scipy.signal.fftconvolve\r\n[`scipy.signal.convolve2d`]:http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve2d.html#scipy.signal.convolve2d"},"comment":{"url":"https://api.github.com/repos/scikit-image/scikit-image/issues/comments/161099599","html_url":"https://github.com/scikit-image/scikit-image/pull/1792#issuecomment-161099599","issue_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1792","id":161099599,"user":{"login":"stefanv","id":45071,"avatar_url":"https://avatars.githubusercontent.com/u/45071?v=3","gravatar_id":"","url":"https://api.github.com/users/stefanv","html_url":"https://github.com/stefanv","followers_url":"https://api.github.com/users/stefanv/followers","following_url":"https://api.github.com/users/stefanv/following{/other_user}","gists_url":"https://api.github.com/users/stefanv/gists{/gist_id}","starred_url":"https://api.github.com/users/stefanv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefanv/subscriptions","organizations_url":"https://api.github.com/users/stefanv/orgs","repos_url":"https://api.github.com/users/stefanv/repos","events_url":"https://api.github.com/users/stefanv/events{/privacy}","received_events_url":"https://api.github.com/users/stefanv/received_events","type":"User","site_admin":false},"created_at":"2015-12-01T21:22:22Z","updated_at":"2015-12-01T21:22:22Z","body":"We should definitely improve fftconvolve as a start.  There is no need to\npad to a power of two when instead we can pad to a nearby smooth number.\n"}}