{"action":"created","comment":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/comments/146628372","pull_request_review_id":71588385,"id":146628372,"diff_hunk":"@@ -349,6 +349,81 @@ void THTensor_(indexCopy)(THTensor *tensor, int dim, THLongTensor *index, THTens\n   THLongTensor_free(index);\n }\n \n+static ptrdiff_t THTensor_(dataOffset)(THTensor* tensor, ptrdiff_t linearIndex) {\n+  int64_t *size = tensor->size;\n+  int64_t *stride = tensor->stride;\n+  int nDim = tensor->nDimension;\n+  ptrdiff_t dataOffset = 0;\n+  for (int i = nDim - 1; i >= 0; i--) {\n+    dataOffset += (linearIndex % size[i]) * stride[i];\n+    linearIndex /= size[i];\n+  }\n+  return dataOffset;\n+}\n+\n+static int64_t THTensor_(wrapLinearIndex)(int64_t linearIndex, int64_t numel) {\n+  THArgCheck(linearIndex < numel && linearIndex >= -numel, 2, \"out of range\");\n+  return linearIndex < 0 ? linearIndex + numel : linearIndex;\n+}\n+\n+void THTensor_(take)(THTensor *r_, THTensor *src, THLongTensor *index)\n+{\n+  THTensor_(resizeNd)(r_, index->nDimension, index->size, NULL);\n+  THTensor* dst = THTensor_(newContiguous)(r_);","path":"torch/lib/TH/generic/THTensorMath.c","position":24,"original_position":24,"commit_id":"51b1a7b14980b70e24c5cc88dbdc375558e9a055","original_commit_id":"51b1a7b14980b70e24c5cc88dbdc375558e9a055","user":{"login":"apaszke","id":4583066,"avatar_url":"https://avatars3.githubusercontent.com/u/4583066?v=4","gravatar_id":"","url":"https://api.github.com/users/apaszke","html_url":"https://github.com/apaszke","followers_url":"https://api.github.com/users/apaszke/followers","following_url":"https://api.github.com/users/apaszke/following{/other_user}","gists_url":"https://api.github.com/users/apaszke/gists{/gist_id}","starred_url":"https://api.github.com/users/apaszke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apaszke/subscriptions","organizations_url":"https://api.github.com/users/apaszke/orgs","repos_url":"https://api.github.com/users/apaszke/repos","events_url":"https://api.github.com/users/apaszke/events{/privacy}","received_events_url":"https://api.github.com/users/apaszke/received_events","type":"User","site_admin":false},"body":"Doesn't `resizeNd` ensure that `r_` is contiguous?","created_at":"2017-10-24T17:07:54Z","updated_at":"2017-10-24T17:14:51Z","html_url":"https://github.com/pytorch/pytorch/pull/3263#discussion_r146628372","pull_request_url":"https://api.github.com/repos/pytorch/pytorch/pulls/3263","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/comments/146628372"},"html":{"href":"https://github.com/pytorch/pytorch/pull/3263#discussion_r146628372"},"pull_request":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/3263"}}},"pull_request":{"url":"https://api.github.com/repos/pytorch/pytorch/pulls/3263","id":148441895,"html_url":"https://github.com/pytorch/pytorch/pull/3263","diff_url":"https://github.com/pytorch/pytorch/pull/3263.diff","patch_url":"https://github.com/pytorch/pytorch/pull/3263.patch","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/3263","number":3263,"state":"open","locked":false,"title":"Add torch.take and Tensor.put_","user":{"login":"colesbury","id":655866,"avatar_url":"https://avatars1.githubusercontent.com/u/655866?v=4","gravatar_id":"","url":"https://api.github.com/users/colesbury","html_url":"https://github.com/colesbury","followers_url":"https://api.github.com/users/colesbury/followers","following_url":"https://api.github.com/users/colesbury/following{/other_user}","gists_url":"https://api.github.com/users/colesbury/gists{/gist_id}","starred_url":"https://api.github.com/users/colesbury/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colesbury/subscriptions","organizations_url":"https://api.github.com/users/colesbury/orgs","repos_url":"https://api.github.com/users/colesbury/repos","events_url":"https://api.github.com/users/colesbury/events{/privacy}","received_events_url":"https://api.github.com/users/colesbury/received_events","type":"User","site_admin":false},"body":"These are similar to numpy.take and numpy.put. The take function allows\r\nyou to linearly index into a tensor without viewing it as a 1D tensor\r\nfirst. The output has the same shape as the indices. The put function\r\ncopies value into a tensor also using linear indices.\r\n\r\nI'll add these to ATen+Variable in a subsequent PR","created_at":"2017-10-24T16:02:38Z","updated_at":"2017-10-24T17:14:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32bbb852d85333bdc1cfc1039bddbea573294470","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/pytorch/pytorch/pulls/3263/commits","review_comments_url":"https://api.github.com/repos/pytorch/pytorch/pulls/3263/comments","review_comment_url":"https://api.github.com/repos/pytorch/pytorch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/3263/comments","statuses_url":"https://api.github.com/repos/pytorch/pytorch/statuses/51b1a7b14980b70e24c5cc88dbdc375558e9a055","head":{"label":"colesbury:take_put","ref":"take_put","sha":"51b1a7b14980b70e24c5cc88dbdc375558e9a055","user":{"login":"colesbury","id":655866,"avatar_url":"https://avatars1.githubusercontent.com/u/655866?v=4","gravatar_id":"","url":"https://api.github.com/users/colesbury","html_url":"https://github.com/colesbury","followers_url":"https://api.github.com/users/colesbury/followers","following_url":"https://api.github.com/users/colesbury/following{/other_user}","gists_url":"https://api.github.com/users/colesbury/gists{/gist_id}","starred_url":"https://api.github.com/users/colesbury/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colesbury/subscriptions","organizations_url":"https://api.github.com/users/colesbury/orgs","repos_url":"https://api.github.com/users/colesbury/repos","events_url":"https://api.github.com/users/colesbury/events{/privacy}","received_events_url":"https://api.github.com/users/colesbury/received_events","type":"User","site_admin":false},"repo":{"id":79366698,"name":"pytorch","full_name":"colesbury/pytorch","owner":{"login":"colesbury","id":655866,"avatar_url":"https://avatars1.githubusercontent.com/u/655866?v=4","gravatar_id":"","url":"https://api.github.com/users/colesbury","html_url":"https://github.com/colesbury","followers_url":"https://api.github.com/users/colesbury/followers","following_url":"https://api.github.com/users/colesbury/following{/other_user}","gists_url":"https://api.github.com/users/colesbury/gists{/gist_id}","starred_url":"https://api.github.com/users/colesbury/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colesbury/subscriptions","organizations_url":"https://api.github.com/users/colesbury/orgs","repos_url":"https://api.github.com/users/colesbury/repos","events_url":"https://api.github.com/users/colesbury/events{/privacy}","received_events_url":"https://api.github.com/users/colesbury/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/colesbury/pytorch","description":null,"fork":true,"url":"https://api.github.com/repos/colesbury/pytorch","forks_url":"https://api.github.com/repos/colesbury/pytorch/forks","keys_url":"https://api.github.com/repos/colesbury/pytorch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/colesbury/pytorch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/colesbury/pytorch/teams","hooks_url":"https://api.github.com/repos/colesbury/pytorch/hooks","issue_events_url":"https://api.github.com/repos/colesbury/pytorch/issues/events{/number}","events_url":"https://api.github.com/repos/colesbury/pytorch/events","assignees_url":"https://api.github.com/repos/colesbury/pytorch/assignees{/user}","branches_url":"https://api.github.com/repos/colesbury/pytorch/branches{/branch}","tags_url":"https://api.github.com/repos/colesbury/pytorch/tags","blobs_url":"https://api.github.com/repos/colesbury/pytorch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/colesbury/pytorch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/colesbury/pytorch/git/refs{/sha}","trees_url":"https://api.github.com/repos/colesbury/pytorch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/colesbury/pytorch/statuses/{sha}","languages_url":"https://api.github.com/repos/colesbury/pytorch/languages","stargazers_url":"https://api.github.com/repos/colesbury/pytorch/stargazers","contributors_url":"https://api.github.com/repos/colesbury/pytorch/contributors","subscribers_url":"https://api.github.com/repos/colesbury/pytorch/subscribers","subscription_url":"https://api.github.com/repos/colesbury/pytorch/subscription","commits_url":"https://api.github.com/repos/colesbury/pytorch/commits{/sha}","git_commits_url":"https://api.github.com/repos/colesbury/pytorch/git/commits{/sha}","comments_url":"https://api.github.com/repos/colesbury/pytorch/comments{/number}","issue_comment_url":"https://api.github.com/repos/colesbury/pytorch/issues/comments{/number}","contents_url":"https://api.github.com/repos/colesbury/pytorch/contents/{+path}","compare_url":"https://api.github.com/repos/colesbury/pytorch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/colesbury/pytorch/merges","archive_url":"https://api.github.com/repos/colesbury/pytorch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/colesbury/pytorch/downloads","issues_url":"https://api.github.com/repos/colesbury/pytorch/issues{/number}","pulls_url":"https://api.github.com/repos/colesbury/pytorch/pulls{/number}","milestones_url":"https://api.github.com/repos/colesbury/pytorch/milestones{/number}","notifications_url":"https://api.github.com/repos/colesbury/pytorch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/colesbury/pytorch/labels{/name}","releases_url":"https://api.github.com/repos/colesbury/pytorch/releases{/id}","deployments_url":"https://api.github.com/repos/colesbury/pytorch/deployments","created_at":"2017-01-18T17:47:38Z","updated_at":"2017-01-18T17:47:43Z","pushed_at":"2017-10-24T16:43:51Z","git_url":"git://github.com/colesbury/pytorch.git","ssh_url":"git@github.com:colesbury/pytorch.git","clone_url":"https://github.com/colesbury/pytorch.git","svn_url":"https://github.com/colesbury/pytorch","homepage":"http://pytorch.org","size":19095,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pytorch:master","ref":"master","sha":"0748ea56ebaddc44efcf5ff734bede6c14b7fb89","user":{"login":"pytorch","id":21003710,"avatar_url":"https://avatars3.githubusercontent.com/u/21003710?v=4","gravatar_id":"","url":"https://api.github.com/users/pytorch","html_url":"https://github.com/pytorch","followers_url":"https://api.github.com/users/pytorch/followers","following_url":"https://api.github.com/users/pytorch/following{/other_user}","gists_url":"https://api.github.com/users/pytorch/gists{/gist_id}","starred_url":"https://api.github.com/users/pytorch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pytorch/subscriptions","organizations_url":"https://api.github.com/users/pytorch/orgs","repos_url":"https://api.github.com/users/pytorch/repos","events_url":"https://api.github.com/users/pytorch/events{/privacy}","received_events_url":"https://api.github.com/users/pytorch/received_events","type":"Organization","site_admin":false},"repo":{"id":65600975,"name":"pytorch","full_name":"pytorch/pytorch","owner":{"login":"pytorch","id":21003710,"avatar_url":"https://avatars3.githubusercontent.com/u/21003710?v=4","gravatar_id":"","url":"https://api.github.com/users/pytorch","html_url":"https://github.com/pytorch","followers_url":"https://api.github.com/users/pytorch/followers","following_url":"https://api.github.com/users/pytorch/following{/other_user}","gists_url":"https://api.github.com/users/pytorch/gists{/gist_id}","starred_url":"https://api.github.com/users/pytorch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pytorch/subscriptions","organizations_url":"https://api.github.com/users/pytorch/orgs","repos_url":"https://api.github.com/users/pytorch/repos","events_url":"https://api.github.com/users/pytorch/events{/privacy}","received_events_url":"https://api.github.com/users/pytorch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pytorch/pytorch","description":"Tensors and Dynamic neural networks in Python  with strong GPU acceleration","fork":false,"url":"https://api.github.com/repos/pytorch/pytorch","forks_url":"https://api.github.com/repos/pytorch/pytorch/forks","keys_url":"https://api.github.com/repos/pytorch/pytorch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pytorch/pytorch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pytorch/pytorch/teams","hooks_url":"https://api.github.com/repos/pytorch/pytorch/hooks","issue_events_url":"https://api.github.com/repos/pytorch/pytorch/issues/events{/number}","events_url":"https://api.github.com/repos/pytorch/pytorch/events","assignees_url":"https://api.github.com/repos/pytorch/pytorch/assignees{/user}","branches_url":"https://api.github.com/repos/pytorch/pytorch/branches{/branch}","tags_url":"https://api.github.com/repos/pytorch/pytorch/tags","blobs_url":"https://api.github.com/repos/pytorch/pytorch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pytorch/pytorch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pytorch/pytorch/git/refs{/sha}","trees_url":"https://api.github.com/repos/pytorch/pytorch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pytorch/pytorch/statuses/{sha}","languages_url":"https://api.github.com/repos/pytorch/pytorch/languages","stargazers_url":"https://api.github.com/repos/pytorch/pytorch/stargazers","contributors_url":"https://api.github.com/repos/pytorch/pytorch/contributors","subscribers_url":"https://api.github.com/repos/pytorch/pytorch/subscribers","subscription_url":"https://api.github.com/repos/pytorch/pytorch/subscription","commits_url":"https://api.github.com/repos/pytorch/pytorch/commits{/sha}","git_commits_url":"https://api.github.com/repos/pytorch/pytorch/git/commits{/sha}","comments_url":"https://api.github.com/repos/pytorch/pytorch/comments{/number}","issue_comment_url":"https://api.github.com/repos/pytorch/pytorch/issues/comments{/number}","contents_url":"https://api.github.com/repos/pytorch/pytorch/contents/{+path}","compare_url":"https://api.github.com/repos/pytorch/pytorch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pytorch/pytorch/merges","archive_url":"https://api.github.com/repos/pytorch/pytorch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pytorch/pytorch/downloads","issues_url":"https://api.github.com/repos/pytorch/pytorch/issues{/number}","pulls_url":"https://api.github.com/repos/pytorch/pytorch/pulls{/number}","milestones_url":"https://api.github.com/repos/pytorch/pytorch/milestones{/number}","notifications_url":"https://api.github.com/repos/pytorch/pytorch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pytorch/pytorch/labels{/name}","releases_url":"https://api.github.com/repos/pytorch/pytorch/releases{/id}","deployments_url":"https://api.github.com/repos/pytorch/pytorch/deployments","created_at":"2016-08-13T05:26:41Z","updated_at":"2017-10-24T16:39:08Z","pushed_at":"2017-10-24T17:13:39Z","git_url":"git://github.com/pytorch/pytorch.git","ssh_url":"git@github.com:pytorch/pytorch.git","clone_url":"https://github.com/pytorch/pytorch.git","svn_url":"https://github.com/pytorch/pytorch","homepage":"http://pytorch.org","size":16534,"stargazers_count":8418,"watchers_count":8418,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1747,"mirror_url":null,"archived":false,"open_issues_count":439,"forks":1747,"open_issues":439,"watchers":8418,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/3263"},"html":{"href":"https://github.com/pytorch/pytorch/pull/3263"},"issue":{"href":"https://api.github.com/repos/pytorch/pytorch/issues/3263"},"comments":{"href":"https://api.github.com/repos/pytorch/pytorch/issues/3263/comments"},"review_comments":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/3263/comments"},"review_comment":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pytorch/pytorch/pulls/3263/commits"},"statuses":{"href":"https://api.github.com/repos/pytorch/pytorch/statuses/51b1a7b14980b70e24c5cc88dbdc375558e9a055"}},"author_association":"OWNER"}}
{"actor":{"display_login":"apaszke"}}