{"action":"created","comment":{"url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/comments/45502955","id":45502955,"diff_hunk":"@@ -17,15 +17,67 @@\n \n def py_median_3x3(image, iterations=10, num_threads=1):\n     ''' repeatedly filter with a 3x3 median '''\n+    # create a new memory location with image data for tmpA\n     tmpA = image.copy()\n+    # create an empty structure for tmpB with same dimensions as tmpA\n     tmpB = np.empty_like(tmpA)\n+    # initialize num_threads-sized list for threads\n+    threads = [None] * num_threads\n+    # initialize (num-threads * (iterations)-sized list for events\n+    events = [None] * num_threads * (iterations)\n+\n+    # initialize events across all elements in list\n+    for threadidx in range(num_threads * (iterations)):\n+        # initialize each position with an event\n+        events[threadidx] = threading.Event()\n+    \n+    # reshape the events list to correspond to a 2D matrix\n+    events = np.reshape(events, [num_threads, iterations])\n+\n+    # iterate for each thread\n+    for threadidx in range(num_threads):\n+        # initialize each thread with the appropriate arguments to the worker function\n+        threads[threadidx] = threading.Thread(target = worker, args = (threadidx, events, tmpA, tmpB, num_threads, iterations))\n+        # exit even when this thread is alive\n+        threads[threadidx].daemon = True\n+        # start the thread\n+        threads[threadidx].start()\n+\n+    # collect and end the threads\n+    for t in threads:\n+        t.join()\n+\n+    # return our result\n+    return tmpA\n+\n \n+def worker(threadidx, events, tmpA, tmpB, num_threads, iterations):\n+    # initialize the list of adjacent threads\n+    adj_threads = []\n+    # set up adjacent threads (representing n-1 and n+1 threads) \n+    for i in range(threadidx-1, threadidx+2):\n+        # exclude indices corresponding to edges\n+        if (i >= 0 and i < num_threads):\n+            adj_threads.append(i)\n+            \n+    # 10 interations\n     for i in range(iterations):\n-        filtering.median_3x3(tmpA, tmpB, 0, 1)\n-        # swap direction of filtering\n+        # skip event-checking if this is the first iteration\n+        if i != 0:\n+            # iterate only among adjacent threads (e.g., other threads are not touched)\n+            for j in adj_threads:\n+                # for these threads, block until the filtering/switching has occurred\n+                events[j, i-1].wait()\n+\n+        # call median_3x3 Cython code with threadidx-multiple rows and offset num_threads\n+        filtering.median_3x3(tmpA, tmpB, threadidx, num_threads)\n+        # switch only the pertinent values of tmpA and tmpB","path":"HW2/P4/driver.py","position":60,"original_position":60,"commit_id":"89acbca16b5cca0cb6142944a19c5a3e7ab4e223","original_commit_id":"89acbca16b5cca0cb6142944a19c5a3e7ab4e223","user":{"login":"patrickday9","id":9629702,"avatar_url":"https://avatars.githubusercontent.com/u/9629702?v=3","gravatar_id":"","url":"https://api.github.com/users/patrickday9","html_url":"https://github.com/patrickday9","followers_url":"https://api.github.com/users/patrickday9/followers","following_url":"https://api.github.com/users/patrickday9/following{/other_user}","gists_url":"https://api.github.com/users/patrickday9/gists{/gist_id}","starred_url":"https://api.github.com/users/patrickday9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrickday9/subscriptions","organizations_url":"https://api.github.com/users/patrickday9/orgs","repos_url":"https://api.github.com/users/patrickday9/repos","events_url":"https://api.github.com/users/patrickday9/events{/privacy}","received_events_url":"https://api.github.com/users/patrickday9/received_events","type":"User","site_admin":false},"body":"Thank you for including thorough comments, it made this section very easy to understand. ","created_at":"2015-11-20T18:47:55Z","updated_at":"2015-11-20T18:47:55Z","html_url":"https://github.com/harvard-cs205/cs205-homework/pull/329#discussion_r45502955","pull_request_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/329","_links":{"self":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/comments/45502955"},"html":{"href":"https://github.com/harvard-cs205/cs205-homework/pull/329#discussion_r45502955"},"pull_request":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/329"}}},"pull_request":{"url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/329","id":49697906,"html_url":"https://github.com/harvard-cs205/cs205-homework/pull/329","diff_url":"https://github.com/harvard-cs205/cs205-homework/pull/329.diff","patch_url":"https://github.com/harvard-cs205/cs205-homework/pull/329.patch","issue_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/329","number":329,"state":"open","locked":false,"title":"Hw2","user":{"login":"jdlkem","id":14164180,"avatar_url":"https://avatars.githubusercontent.com/u/14164180?v=3","gravatar_id":"","url":"https://api.github.com/users/jdlkem","html_url":"https://github.com/jdlkem","followers_url":"https://api.github.com/users/jdlkem/followers","following_url":"https://api.github.com/users/jdlkem/following{/other_user}","gists_url":"https://api.github.com/users/jdlkem/gists{/gist_id}","starred_url":"https://api.github.com/users/jdlkem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdlkem/subscriptions","organizations_url":"https://api.github.com/users/jdlkem/orgs","repos_url":"https://api.github.com/users/jdlkem/repos","events_url":"https://api.github.com/users/jdlkem/events{/privacy}","received_events_url":"https://api.github.com/users/jdlkem/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-04T14:55:14Z","updated_at":"2015-11-20T18:47:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"533a252288dfa2d4d8a49feeb9cb0554c129e21f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/329/commits","review_comments_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/329/comments","review_comment_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/329/comments","statuses_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/statuses/89acbca16b5cca0cb6142944a19c5a3e7ab4e223","head":{"label":"jdlkem:HW2","ref":"HW2","sha":"89acbca16b5cca0cb6142944a19c5a3e7ab4e223","user":{"login":"jdlkem","id":14164180,"avatar_url":"https://avatars.githubusercontent.com/u/14164180?v=3","gravatar_id":"","url":"https://api.github.com/users/jdlkem","html_url":"https://github.com/jdlkem","followers_url":"https://api.github.com/users/jdlkem/followers","following_url":"https://api.github.com/users/jdlkem/following{/other_user}","gists_url":"https://api.github.com/users/jdlkem/gists{/gist_id}","starred_url":"https://api.github.com/users/jdlkem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdlkem/subscriptions","organizations_url":"https://api.github.com/users/jdlkem/orgs","repos_url":"https://api.github.com/users/jdlkem/repos","events_url":"https://api.github.com/users/jdlkem/events{/privacy}","received_events_url":"https://api.github.com/users/jdlkem/received_events","type":"User","site_admin":false},"repo":{"id":42060585,"name":"cs205-homework","full_name":"jdlkem/cs205-homework","owner":{"login":"jdlkem","id":14164180,"avatar_url":"https://avatars.githubusercontent.com/u/14164180?v=3","gravatar_id":"","url":"https://api.github.com/users/jdlkem","html_url":"https://github.com/jdlkem","followers_url":"https://api.github.com/users/jdlkem/followers","following_url":"https://api.github.com/users/jdlkem/following{/other_user}","gists_url":"https://api.github.com/users/jdlkem/gists{/gist_id}","starred_url":"https://api.github.com/users/jdlkem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdlkem/subscriptions","organizations_url":"https://api.github.com/users/jdlkem/orgs","repos_url":"https://api.github.com/users/jdlkem/repos","events_url":"https://api.github.com/users/jdlkem/events{/privacy}","received_events_url":"https://api.github.com/users/jdlkem/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jdlkem/cs205-homework","description":"","fork":true,"url":"https://api.github.com/repos/jdlkem/cs205-homework","forks_url":"https://api.github.com/repos/jdlkem/cs205-homework/forks","keys_url":"https://api.github.com/repos/jdlkem/cs205-homework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jdlkem/cs205-homework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jdlkem/cs205-homework/teams","hooks_url":"https://api.github.com/repos/jdlkem/cs205-homework/hooks","issue_events_url":"https://api.github.com/repos/jdlkem/cs205-homework/issues/events{/number}","events_url":"https://api.github.com/repos/jdlkem/cs205-homework/events","assignees_url":"https://api.github.com/repos/jdlkem/cs205-homework/assignees{/user}","branches_url":"https://api.github.com/repos/jdlkem/cs205-homework/branches{/branch}","tags_url":"https://api.github.com/repos/jdlkem/cs205-homework/tags","blobs_url":"https://api.github.com/repos/jdlkem/cs205-homework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jdlkem/cs205-homework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jdlkem/cs205-homework/git/refs{/sha}","trees_url":"https://api.github.com/repos/jdlkem/cs205-homework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jdlkem/cs205-homework/statuses/{sha}","languages_url":"https://api.github.com/repos/jdlkem/cs205-homework/languages","stargazers_url":"https://api.github.com/repos/jdlkem/cs205-homework/stargazers","contributors_url":"https://api.github.com/repos/jdlkem/cs205-homework/contributors","subscribers_url":"https://api.github.com/repos/jdlkem/cs205-homework/subscribers","subscription_url":"https://api.github.com/repos/jdlkem/cs205-homework/subscription","commits_url":"https://api.github.com/repos/jdlkem/cs205-homework/commits{/sha}","git_commits_url":"https://api.github.com/repos/jdlkem/cs205-homework/git/commits{/sha}","comments_url":"https://api.github.com/repos/jdlkem/cs205-homework/comments{/number}","issue_comment_url":"https://api.github.com/repos/jdlkem/cs205-homework/issues/comments{/number}","contents_url":"https://api.github.com/repos/jdlkem/cs205-homework/contents/{+path}","compare_url":"https://api.github.com/repos/jdlkem/cs205-homework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jdlkem/cs205-homework/merges","archive_url":"https://api.github.com/repos/jdlkem/cs205-homework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jdlkem/cs205-homework/downloads","issues_url":"https://api.github.com/repos/jdlkem/cs205-homework/issues{/number}","pulls_url":"https://api.github.com/repos/jdlkem/cs205-homework/pulls{/number}","milestones_url":"https://api.github.com/repos/jdlkem/cs205-homework/milestones{/number}","notifications_url":"https://api.github.com/repos/jdlkem/cs205-homework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jdlkem/cs205-homework/labels{/name}","releases_url":"https://api.github.com/repos/jdlkem/cs205-homework/releases{/id}","created_at":"2015-09-07T15:29:02Z","updated_at":"2015-09-07T15:29:03Z","pushed_at":"2015-11-19T00:41:51Z","git_url":"git://github.com/jdlkem/cs205-homework.git","ssh_url":"git@github.com:jdlkem/cs205-homework.git","clone_url":"https://github.com/jdlkem/cs205-homework.git","svn_url":"https://github.com/jdlkem/cs205-homework","homepage":null,"size":491,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"harvard-cs205:master","ref":"master","sha":"ed6f0167fd1f6097ce9e454c2950c5db00a0c513","user":{"login":"harvard-cs205","id":13456002,"avatar_url":"https://avatars.githubusercontent.com/u/13456002?v=3","gravatar_id":"","url":"https://api.github.com/users/harvard-cs205","html_url":"https://github.com/harvard-cs205","followers_url":"https://api.github.com/users/harvard-cs205/followers","following_url":"https://api.github.com/users/harvard-cs205/following{/other_user}","gists_url":"https://api.github.com/users/harvard-cs205/gists{/gist_id}","starred_url":"https://api.github.com/users/harvard-cs205/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harvard-cs205/subscriptions","organizations_url":"https://api.github.com/users/harvard-cs205/orgs","repos_url":"https://api.github.com/users/harvard-cs205/repos","events_url":"https://api.github.com/users/harvard-cs205/events{/privacy}","received_events_url":"https://api.github.com/users/harvard-cs205/received_events","type":"Organization","site_admin":false},"repo":{"id":40614104,"name":"cs205-homework","full_name":"harvard-cs205/cs205-homework","owner":{"login":"harvard-cs205","id":13456002,"avatar_url":"https://avatars.githubusercontent.com/u/13456002?v=3","gravatar_id":"","url":"https://api.github.com/users/harvard-cs205","html_url":"https://github.com/harvard-cs205","followers_url":"https://api.github.com/users/harvard-cs205/followers","following_url":"https://api.github.com/users/harvard-cs205/following{/other_user}","gists_url":"https://api.github.com/users/harvard-cs205/gists{/gist_id}","starred_url":"https://api.github.com/users/harvard-cs205/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harvard-cs205/subscriptions","organizations_url":"https://api.github.com/users/harvard-cs205/orgs","repos_url":"https://api.github.com/users/harvard-cs205/repos","events_url":"https://api.github.com/users/harvard-cs205/events{/privacy}","received_events_url":"https://api.github.com/users/harvard-cs205/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/harvard-cs205/cs205-homework","description":"","fork":false,"url":"https://api.github.com/repos/harvard-cs205/cs205-homework","forks_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/forks","keys_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/teams","hooks_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/hooks","issue_events_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/events{/number}","events_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/events","assignees_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/assignees{/user}","branches_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/branches{/branch}","tags_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/tags","blobs_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/refs{/sha}","trees_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/statuses/{sha}","languages_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/languages","stargazers_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/stargazers","contributors_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/contributors","subscribers_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/subscribers","subscription_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/subscription","commits_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/commits{/sha}","git_commits_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/git/commits{/sha}","comments_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/comments{/number}","issue_comment_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/comments{/number}","contents_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/contents/{+path}","compare_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/merges","archive_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/downloads","issues_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues{/number}","pulls_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls{/number}","milestones_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/milestones{/number}","notifications_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/labels{/name}","releases_url":"https://api.github.com/repos/harvard-cs205/cs205-homework/releases{/id}","created_at":"2015-08-12T17:18:15Z","updated_at":"2015-10-21T19:21:28Z","pushed_at":"2015-11-20T17:28:32Z","git_url":"git://github.com/harvard-cs205/cs205-homework.git","ssh_url":"git@github.com:harvard-cs205/cs205-homework.git","clone_url":"https://github.com/harvard-cs205/cs205-homework.git","svn_url":"https://github.com/harvard-cs205/cs205-homework","homepage":null,"size":162893,"stargazers_count":5,"watchers_count":5,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":99,"mirror_url":null,"open_issues_count":404,"forks":99,"open_issues":404,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/329"},"html":{"href":"https://github.com/harvard-cs205/cs205-homework/pull/329"},"issue":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/329"},"comments":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/issues/329/comments"},"review_comments":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/329/comments"},"review_comment":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/pulls/329/commits"},"statuses":{"href":"https://api.github.com/repos/harvard-cs205/cs205-homework/statuses/89acbca16b5cca0cb6142944a19c5a3e7ab4e223"}}}}