{"action":"created","comment":{"url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/comments/30010142","id":30010142,"diff_hunk":"@@ -0,0 +1,93 @@\n+from math import ceil\n+from multiprocessing import cpu_count\n+\n+import dask.array as da\n+\n+__all__ = ['process_chunks']\n+\n+\n+def _get_chunks(shape, ncpu):\n+    \"\"\"\n+    Split the array into equal sized chunks based on the number of\n+    available processors. The last chunk in each dimension absorbs the\n+    remainder array elements if the number of cpus does not divide evenly into\n+    the number of array elements.\n+\n+    >>> _get_chunks((4, 4), 4)\n+    ((2, 2), (2, 2))\n+    >>> _get_chunks((4, 4), 2)\n+    ((2, 2), (4,))\n+    >>> _get_chunks((5, 5), 2)\n+    ((2, 3), (5,))\n+    >>> _get_chunks((2, 4), 2)\n+    ((1, 1), (4,))\n+    \"\"\"\n+    chunks = []\n+    nchunks_per_dim = int(ceil(ncpu ** (1./len(shape))))\n+\n+    used_chunks = 1\n+    for i in shape:\n+        if used_chunks < ncpu:\n+            regular_chunk = i // nchunks_per_dim\n+            remainder_chunk = regular_chunk + (i % nchunks_per_dim)\n+\n+            if regular_chunk == 0:\n+                chunk_lens = (remainder_chunk,)\n+            else:\n+                chunk_lens = ((regular_chunk,) * (nchunks_per_dim - 1) +\n+                              (remainder_chunk,))\n+        else:\n+            chunk_lens = (i,)\n+\n+        chunks.append(chunk_lens)\n+        used_chunks *= nchunks_per_dim\n+    return tuple(chunks)\n+\n+\n+def process_chunks(function, array, chunks=None, depth=0,","path":"skimage/util/process.py","position":47,"original_position":47,"commit_id":"38bde993486416ef55da7ae8797513e3df41d95c","original_commit_id":"38bde993486416ef55da7ae8797513e3df41d95c","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},"body":"Maybe \"apply_chunks\" is more intuitive, given that a function is the first parameter?","created_at":"2015-05-11T02:17:03Z","updated_at":"2015-05-11T02:17:03Z","html_url":"https://github.com/scikit-image/scikit-image/pull/1493#discussion_r30010142","pull_request_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1493","_links":{"self":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/comments/30010142"},"html":{"href":"https://github.com/scikit-image/scikit-image/pull/1493#discussion_r30010142"},"pull_request":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1493"}}},"pull_request":{"url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1493","id":34669851,"html_url":"https://github.com/scikit-image/scikit-image/pull/1493","diff_url":"https://github.com/scikit-image/scikit-image/pull/1493.diff","patch_url":"https://github.com/scikit-image/scikit-image/pull/1493.patch","issue_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1493","number":1493,"state":"open","locked":false,"title":"parallel function mapping","user":{"login":"cowlicks","id":598099,"avatar_url":"https://avatars.githubusercontent.com/u/598099?v=3","gravatar_id":"","url":"https://api.github.com/users/cowlicks","html_url":"https://github.com/cowlicks","followers_url":"https://api.github.com/users/cowlicks/followers","following_url":"https://api.github.com/users/cowlicks/following{/other_user}","gists_url":"https://api.github.com/users/cowlicks/gists{/gist_id}","starred_url":"https://api.github.com/users/cowlicks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cowlicks/subscriptions","organizations_url":"https://api.github.com/users/cowlicks/orgs","repos_url":"https://api.github.com/users/cowlicks/repos","events_url":"https://api.github.com/users/cowlicks/events{/privacy}","received_events_url":"https://api.github.com/users/cowlicks/received_events","type":"User","site_admin":false},"body":"This is the spiritual successor to PR #723 \r\n\r\nIt allows you to break an image into chunks and map a function, in parallel, over the chunks. The chunks' boundary conditions and boundary depth can be specified to match those the function needs.\r\n\r\nThis adds [dask](https://github.com/ContinuumIO/dask) as a dependency, and is based off dask master.","created_at":"2015-05-04T20:06:58Z","updated_at":"2015-05-11T02:17:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"33f2478b3ddf8ebed52a890a31023c1caae75b04","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1493/commits","review_comments_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1493/comments","review_comment_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/1493/comments","statuses_url":"https://api.github.com/repos/scikit-image/scikit-image/statuses/38bde993486416ef55da7ae8797513e3df41d95c","head":{"label":"cowlicks:chunk-map","ref":"chunk-map","sha":"38bde993486416ef55da7ae8797513e3df41d95c","user":{"login":"cowlicks","id":598099,"avatar_url":"https://avatars.githubusercontent.com/u/598099?v=3","gravatar_id":"","url":"https://api.github.com/users/cowlicks","html_url":"https://github.com/cowlicks","followers_url":"https://api.github.com/users/cowlicks/followers","following_url":"https://api.github.com/users/cowlicks/following{/other_user}","gists_url":"https://api.github.com/users/cowlicks/gists{/gist_id}","starred_url":"https://api.github.com/users/cowlicks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cowlicks/subscriptions","organizations_url":"https://api.github.com/users/cowlicks/orgs","repos_url":"https://api.github.com/users/cowlicks/repos","events_url":"https://api.github.com/users/cowlicks/events{/privacy}","received_events_url":"https://api.github.com/users/cowlicks/received_events","type":"User","site_admin":false},"repo":{"id":34545303,"name":"scikit-image","full_name":"cowlicks/scikit-image","owner":{"login":"cowlicks","id":598099,"avatar_url":"https://avatars.githubusercontent.com/u/598099?v=3","gravatar_id":"","url":"https://api.github.com/users/cowlicks","html_url":"https://github.com/cowlicks","followers_url":"https://api.github.com/users/cowlicks/followers","following_url":"https://api.github.com/users/cowlicks/following{/other_user}","gists_url":"https://api.github.com/users/cowlicks/gists{/gist_id}","starred_url":"https://api.github.com/users/cowlicks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cowlicks/subscriptions","organizations_url":"https://api.github.com/users/cowlicks/orgs","repos_url":"https://api.github.com/users/cowlicks/repos","events_url":"https://api.github.com/users/cowlicks/events{/privacy}","received_events_url":"https://api.github.com/users/cowlicks/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cowlicks/scikit-image","description":"Image Processing SciKit (Toolbox for SciPy)","fork":true,"url":"https://api.github.com/repos/cowlicks/scikit-image","forks_url":"https://api.github.com/repos/cowlicks/scikit-image/forks","keys_url":"https://api.github.com/repos/cowlicks/scikit-image/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cowlicks/scikit-image/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cowlicks/scikit-image/teams","hooks_url":"https://api.github.com/repos/cowlicks/scikit-image/hooks","issue_events_url":"https://api.github.com/repos/cowlicks/scikit-image/issues/events{/number}","events_url":"https://api.github.com/repos/cowlicks/scikit-image/events","assignees_url":"https://api.github.com/repos/cowlicks/scikit-image/assignees{/user}","branches_url":"https://api.github.com/repos/cowlicks/scikit-image/branches{/branch}","tags_url":"https://api.github.com/repos/cowlicks/scikit-image/tags","blobs_url":"https://api.github.com/repos/cowlicks/scikit-image/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cowlicks/scikit-image/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cowlicks/scikit-image/git/refs{/sha}","trees_url":"https://api.github.com/repos/cowlicks/scikit-image/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cowlicks/scikit-image/statuses/{sha}","languages_url":"https://api.github.com/repos/cowlicks/scikit-image/languages","stargazers_url":"https://api.github.com/repos/cowlicks/scikit-image/stargazers","contributors_url":"https://api.github.com/repos/cowlicks/scikit-image/contributors","subscribers_url":"https://api.github.com/repos/cowlicks/scikit-image/subscribers","subscription_url":"https://api.github.com/repos/cowlicks/scikit-image/subscription","commits_url":"https://api.github.com/repos/cowlicks/scikit-image/commits{/sha}","git_commits_url":"https://api.github.com/repos/cowlicks/scikit-image/git/commits{/sha}","comments_url":"https://api.github.com/repos/cowlicks/scikit-image/comments{/number}","issue_comment_url":"https://api.github.com/repos/cowlicks/scikit-image/issues/comments{/number}","contents_url":"https://api.github.com/repos/cowlicks/scikit-image/contents/{+path}","compare_url":"https://api.github.com/repos/cowlicks/scikit-image/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cowlicks/scikit-image/merges","archive_url":"https://api.github.com/repos/cowlicks/scikit-image/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cowlicks/scikit-image/downloads","issues_url":"https://api.github.com/repos/cowlicks/scikit-image/issues{/number}","pulls_url":"https://api.github.com/repos/cowlicks/scikit-image/pulls{/number}","milestones_url":"https://api.github.com/repos/cowlicks/scikit-image/milestones{/number}","notifications_url":"https://api.github.com/repos/cowlicks/scikit-image/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cowlicks/scikit-image/labels{/name}","releases_url":"https://api.github.com/repos/cowlicks/scikit-image/releases{/id}","created_at":"2015-04-24T22:35:47Z","updated_at":"2015-05-04T19:56:39Z","pushed_at":"2015-05-10T23:02:47Z","git_url":"git://github.com/cowlicks/scikit-image.git","ssh_url":"git@github.com:cowlicks/scikit-image.git","clone_url":"https://github.com/cowlicks/scikit-image.git","svn_url":"https://github.com/cowlicks/scikit-image","homepage":"http://scikit-image.org","size":36987,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scikit-image:master","ref":"master","sha":"92b40816ed9bbc91e2860abb88c24772e545f27c","user":{"login":"scikit-image","id":897180,"avatar_url":"https://avatars.githubusercontent.com/u/897180?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-image","html_url":"https://github.com/scikit-image","followers_url":"https://api.github.com/users/scikit-image/followers","following_url":"https://api.github.com/users/scikit-image/following{/other_user}","gists_url":"https://api.github.com/users/scikit-image/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-image/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-image/subscriptions","organizations_url":"https://api.github.com/users/scikit-image/orgs","repos_url":"https://api.github.com/users/scikit-image/repos","events_url":"https://api.github.com/users/scikit-image/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-image/received_events","type":"Organization","site_admin":false},"repo":{"id":2014929,"name":"scikit-image","full_name":"scikit-image/scikit-image","owner":{"login":"scikit-image","id":897180,"avatar_url":"https://avatars.githubusercontent.com/u/897180?v=3","gravatar_id":"","url":"https://api.github.com/users/scikit-image","html_url":"https://github.com/scikit-image","followers_url":"https://api.github.com/users/scikit-image/followers","following_url":"https://api.github.com/users/scikit-image/following{/other_user}","gists_url":"https://api.github.com/users/scikit-image/gists{/gist_id}","starred_url":"https://api.github.com/users/scikit-image/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scikit-image/subscriptions","organizations_url":"https://api.github.com/users/scikit-image/orgs","repos_url":"https://api.github.com/users/scikit-image/repos","events_url":"https://api.github.com/users/scikit-image/events{/privacy}","received_events_url":"https://api.github.com/users/scikit-image/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scikit-image/scikit-image","description":"Image Processing SciKit (Toolbox for SciPy)","fork":false,"url":"https://api.github.com/repos/scikit-image/scikit-image","forks_url":"https://api.github.com/repos/scikit-image/scikit-image/forks","keys_url":"https://api.github.com/repos/scikit-image/scikit-image/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scikit-image/scikit-image/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scikit-image/scikit-image/teams","hooks_url":"https://api.github.com/repos/scikit-image/scikit-image/hooks","issue_events_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/events{/number}","events_url":"https://api.github.com/repos/scikit-image/scikit-image/events","assignees_url":"https://api.github.com/repos/scikit-image/scikit-image/assignees{/user}","branches_url":"https://api.github.com/repos/scikit-image/scikit-image/branches{/branch}","tags_url":"https://api.github.com/repos/scikit-image/scikit-image/tags","blobs_url":"https://api.github.com/repos/scikit-image/scikit-image/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scikit-image/scikit-image/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scikit-image/scikit-image/git/refs{/sha}","trees_url":"https://api.github.com/repos/scikit-image/scikit-image/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scikit-image/scikit-image/statuses/{sha}","languages_url":"https://api.github.com/repos/scikit-image/scikit-image/languages","stargazers_url":"https://api.github.com/repos/scikit-image/scikit-image/stargazers","contributors_url":"https://api.github.com/repos/scikit-image/scikit-image/contributors","subscribers_url":"https://api.github.com/repos/scikit-image/scikit-image/subscribers","subscription_url":"https://api.github.com/repos/scikit-image/scikit-image/subscription","commits_url":"https://api.github.com/repos/scikit-image/scikit-image/commits{/sha}","git_commits_url":"https://api.github.com/repos/scikit-image/scikit-image/git/commits{/sha}","comments_url":"https://api.github.com/repos/scikit-image/scikit-image/comments{/number}","issue_comment_url":"https://api.github.com/repos/scikit-image/scikit-image/issues/comments{/number}","contents_url":"https://api.github.com/repos/scikit-image/scikit-image/contents/{+path}","compare_url":"https://api.github.com/repos/scikit-image/scikit-image/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scikit-image/scikit-image/merges","archive_url":"https://api.github.com/repos/scikit-image/scikit-image/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scikit-image/scikit-image/downloads","issues_url":"https://api.github.com/repos/scikit-image/scikit-image/issues{/number}","pulls_url":"https://api.github.com/repos/scikit-image/scikit-image/pulls{/number}","milestones_url":"https://api.github.com/repos/scikit-image/scikit-image/milestones{/number}","notifications_url":"https://api.github.com/repos/scikit-image/scikit-image/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scikit-image/scikit-image/labels{/name}","releases_url":"https://api.github.com/repos/scikit-image/scikit-image/releases{/id}","created_at":"2011-07-07T22:07:20Z","updated_at":"2015-05-10T21:11:22Z","pushed_at":"2015-05-11T01:49:50Z","git_url":"git://github.com/scikit-image/scikit-image.git","ssh_url":"git@github.com:scikit-image/scikit-image.git","clone_url":"https://github.com/scikit-image/scikit-image.git","svn_url":"https://github.com/scikit-image/scikit-image","homepage":"http://scikit-image.org","size":64746,"stargazers_count":696,"watchers_count":696,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":353,"mirror_url":null,"open_issues_count":176,"forks":353,"open_issues":176,"watchers":696,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1493"},"html":{"href":"https://github.com/scikit-image/scikit-image/pull/1493"},"issue":{"href":"https://api.github.com/repos/scikit-image/scikit-image/issues/1493"},"comments":{"href":"https://api.github.com/repos/scikit-image/scikit-image/issues/1493/comments"},"review_comments":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1493/comments"},"review_comment":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scikit-image/scikit-image/pulls/1493/commits"},"statuses":{"href":"https://api.github.com/repos/scikit-image/scikit-image/statuses/38bde993486416ef55da7ae8797513e3df41d95c"}}}}