{"action":"created","comment":{"url":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/comments/76539835","id":76539835,"diff_hunk":"@@ -182,17 +182,39 @@ def ruby_array_to_c(array, type)\n   #   - Value of the element contained in the specified position in the tensor.\n   #\n   def getval(dimension)\n-    raise(\"Invalid dimension array passed as input.\",ShapeError) if dimension.length != dimensions.length\n+    raise(\"Invalid dimension array passed as input.\",ShapeError) if dimension.length != shape.length\n     (0..dimension.length-1).each do |i|\n-      raise(\"Invalid dimension array passed as input.\",ShapeError) if dimension[i] > dimensions[i] || dimension[i] < 1 || !(dimension[i].is_a? Integer)\n+      raise(\"Invalid dimension array passed as input.\",ShapeError) if dimension[i] > shape[i] || dimension[i] < 1 || !(dimension[i].is_a? Integer)\n     end\n-    sum = dimension[dimension.length - 1]  - 1\n-    prod = dimensions[dimensions.length - 1]\n+    sum = dimension.last - 1\n+    prod = shape.last\n     (0..dimension.length - 2).each do |i|\n        sum += (dimension[dimension.length - 2 - i] - 1) * prod\n-       prod *= dimensions[dimensions.length - 2 - i]\n+       prod *= shape[shape.length - 2 - i]\n     end\n \n     flatten[sum]\n   end\n+\n+  private\n+\n+  #\n+  # Recursively finds the shape of the input array.\n+  #\n+  # * *Returns* :\n+  #   - Dimension array `[[2], [4]].shape` => `[2, 1]`\n+  #\n+  # TODO: Handle non-rectangular arrays and raise error if mixed data types\n+  def self.set_shape(value)","path":"lib/tensorflow/tensor.rb","position":105,"original_position":105,"commit_id":"ff755790011d0db463911ae2767c573da0108047","original_commit_id":"ff755790011d0db463911ae2767c573da0108047","user":{"login":"chrhansen","id":1741737,"avatar_url":"https://avatars.githubusercontent.com/u/1741737?v=3","gravatar_id":"","url":"https://api.github.com/users/chrhansen","html_url":"https://github.com/chrhansen","followers_url":"https://api.github.com/users/chrhansen/followers","following_url":"https://api.github.com/users/chrhansen/following{/other_user}","gists_url":"https://api.github.com/users/chrhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/chrhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrhansen/subscriptions","organizations_url":"https://api.github.com/users/chrhansen/orgs","repos_url":"https://api.github.com/users/chrhansen/repos","events_url":"https://api.github.com/users/chrhansen/events{/privacy}","received_events_url":"https://api.github.com/users/chrhansen/received_events","type":"User","site_admin":false},"body":"Hi @zverok, thanks I'm familiar with the Ruby conventions and I guess it could also be called `shape_of()` instead. There's already a bare `.shape`-method (the one renamed from `.dimensions`) which is the getter for the tensor-shape. So the reason to prefix `set_`, is that if you look in the [Python-implementation](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/framework/ops.py#L378) the shape is inferred and _set_ when the tensor is initialized, or when someone later explicitly calls `set_shape`, and the result is held in a private variable. My idea was to follow the Tensorflow team's own design implementation and move [Line 45](https://github.com/somaticio/tensorflow.rb/blob/master/lib/tensorflow/tensor.rb#L45)\r\n\r\n```ruby\r\n# lib/tensorflow/tensor.rb#L45\r\nself.shape = self.class.set_shape(value)\r\n```\r\ninto the `set_shape` method. Thereby the shape would be _set_ only when this method was called during initialization or when someone _later_ wanted to overwrite the shape value.","created_at":"2016-08-28T21:49:25Z","updated_at":"2016-08-28T21:49:25Z","html_url":"https://github.com/somaticio/tensorflow.rb/pull/65#discussion_r76539835","pull_request_url":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/65","_links":{"self":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/comments/76539835"},"html":{"href":"https://github.com/somaticio/tensorflow.rb/pull/65#discussion_r76539835"},"pull_request":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/65"}}},"pull_request":{"url":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/65","id":83004921,"html_url":"https://github.com/somaticio/tensorflow.rb/pull/65","diff_url":"https://github.com/somaticio/tensorflow.rb/pull/65.diff","patch_url":"https://github.com/somaticio/tensorflow.rb/pull/65.patch","issue_url":"https://api.github.com/repos/somaticio/tensorflow.rb/issues/65","number":65,"state":"closed","locked":false,"title":"Move shape-method to Tensor-class","user":{"login":"chrhansen","id":1741737,"avatar_url":"https://avatars.githubusercontent.com/u/1741737?v=3","gravatar_id":"","url":"https://api.github.com/users/chrhansen","html_url":"https://github.com/chrhansen","followers_url":"https://api.github.com/users/chrhansen/followers","following_url":"https://api.github.com/users/chrhansen/following{/other_user}","gists_url":"https://api.github.com/users/chrhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/chrhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrhansen/subscriptions","organizations_url":"https://api.github.com/users/chrhansen/orgs","repos_url":"https://api.github.com/users/chrhansen/repos","events_url":"https://api.github.com/users/chrhansen/events{/privacy}","received_events_url":"https://api.github.com/users/chrhansen/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-28T03:15:27Z","updated_at":"2016-08-28T21:49:25Z","closed_at":"2016-08-28T06:52:29Z","merged_at":"2016-08-28T06:52:29Z","merge_commit_sha":"3b2509a34191ea9840f93ff58c8856a4cdb70604","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/65/commits","review_comments_url":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/65/comments","review_comment_url":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/somaticio/tensorflow.rb/issues/65/comments","statuses_url":"https://api.github.com/repos/somaticio/tensorflow.rb/statuses/ff755790011d0db463911ae2767c573da0108047","head":{"label":"chrhansen:shape-refactor","ref":"shape-refactor","sha":"ff755790011d0db463911ae2767c573da0108047","user":{"login":"chrhansen","id":1741737,"avatar_url":"https://avatars.githubusercontent.com/u/1741737?v=3","gravatar_id":"","url":"https://api.github.com/users/chrhansen","html_url":"https://github.com/chrhansen","followers_url":"https://api.github.com/users/chrhansen/followers","following_url":"https://api.github.com/users/chrhansen/following{/other_user}","gists_url":"https://api.github.com/users/chrhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/chrhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrhansen/subscriptions","organizations_url":"https://api.github.com/users/chrhansen/orgs","repos_url":"https://api.github.com/users/chrhansen/repos","events_url":"https://api.github.com/users/chrhansen/events{/privacy}","received_events_url":"https://api.github.com/users/chrhansen/received_events","type":"User","site_admin":false},"repo":{"id":63084256,"name":"tensorflow.rb","full_name":"chrhansen/tensorflow.rb","owner":{"login":"chrhansen","id":1741737,"avatar_url":"https://avatars.githubusercontent.com/u/1741737?v=3","gravatar_id":"","url":"https://api.github.com/users/chrhansen","html_url":"https://github.com/chrhansen","followers_url":"https://api.github.com/users/chrhansen/followers","following_url":"https://api.github.com/users/chrhansen/following{/other_user}","gists_url":"https://api.github.com/users/chrhansen/gists{/gist_id}","starred_url":"https://api.github.com/users/chrhansen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrhansen/subscriptions","organizations_url":"https://api.github.com/users/chrhansen/orgs","repos_url":"https://api.github.com/users/chrhansen/repos","events_url":"https://api.github.com/users/chrhansen/events{/privacy}","received_events_url":"https://api.github.com/users/chrhansen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chrhansen/tensorflow.rb","description":null,"fork":true,"url":"https://api.github.com/repos/chrhansen/tensorflow.rb","forks_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/forks","keys_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/teams","hooks_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/hooks","issue_events_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/issues/events{/number}","events_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/events","assignees_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/assignees{/user}","branches_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/branches{/branch}","tags_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/tags","blobs_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/git/refs{/sha}","trees_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/statuses/{sha}","languages_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/languages","stargazers_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/stargazers","contributors_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/contributors","subscribers_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/subscribers","subscription_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/subscription","commits_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/commits{/sha}","git_commits_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/git/commits{/sha}","comments_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/comments{/number}","issue_comment_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/issues/comments{/number}","contents_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/contents/{+path}","compare_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/merges","archive_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/downloads","issues_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/issues{/number}","pulls_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/pulls{/number}","milestones_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/milestones{/number}","notifications_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/labels{/name}","releases_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/releases{/id}","deployments_url":"https://api.github.com/repos/chrhansen/tensorflow.rb/deployments","created_at":"2016-07-11T16:28:18Z","updated_at":"2016-07-13T06:02:12Z","pushed_at":"2016-08-28T21:29:02Z","git_url":"git://github.com/chrhansen/tensorflow.rb.git","ssh_url":"git@github.com:chrhansen/tensorflow.rb.git","clone_url":"https://github.com/chrhansen/tensorflow.rb.git","svn_url":"https://github.com/chrhansen/tensorflow.rb","homepage":null,"size":2624,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"somaticio:master","ref":"master","sha":"c7d6b7412b66d8dccd45a0f46b465755d7e3ee6b","user":{"login":"somaticio","id":14168819,"avatar_url":"https://avatars.githubusercontent.com/u/14168819?v=3","gravatar_id":"","url":"https://api.github.com/users/somaticio","html_url":"https://github.com/somaticio","followers_url":"https://api.github.com/users/somaticio/followers","following_url":"https://api.github.com/users/somaticio/following{/other_user}","gists_url":"https://api.github.com/users/somaticio/gists{/gist_id}","starred_url":"https://api.github.com/users/somaticio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/somaticio/subscriptions","organizations_url":"https://api.github.com/users/somaticio/orgs","repos_url":"https://api.github.com/users/somaticio/repos","events_url":"https://api.github.com/users/somaticio/events{/privacy}","received_events_url":"https://api.github.com/users/somaticio/received_events","type":"Organization","site_admin":false},"repo":{"id":61302869,"name":"tensorflow.rb","full_name":"somaticio/tensorflow.rb","owner":{"login":"somaticio","id":14168819,"avatar_url":"https://avatars.githubusercontent.com/u/14168819?v=3","gravatar_id":"","url":"https://api.github.com/users/somaticio","html_url":"https://github.com/somaticio","followers_url":"https://api.github.com/users/somaticio/followers","following_url":"https://api.github.com/users/somaticio/following{/other_user}","gists_url":"https://api.github.com/users/somaticio/gists{/gist_id}","starred_url":"https://api.github.com/users/somaticio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/somaticio/subscriptions","organizations_url":"https://api.github.com/users/somaticio/orgs","repos_url":"https://api.github.com/users/somaticio/repos","events_url":"https://api.github.com/users/somaticio/events{/privacy}","received_events_url":"https://api.github.com/users/somaticio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/somaticio/tensorflow.rb","description":"","fork":false,"url":"https://api.github.com/repos/somaticio/tensorflow.rb","forks_url":"https://api.github.com/repos/somaticio/tensorflow.rb/forks","keys_url":"https://api.github.com/repos/somaticio/tensorflow.rb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/somaticio/tensorflow.rb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/somaticio/tensorflow.rb/teams","hooks_url":"https://api.github.com/repos/somaticio/tensorflow.rb/hooks","issue_events_url":"https://api.github.com/repos/somaticio/tensorflow.rb/issues/events{/number}","events_url":"https://api.github.com/repos/somaticio/tensorflow.rb/events","assignees_url":"https://api.github.com/repos/somaticio/tensorflow.rb/assignees{/user}","branches_url":"https://api.github.com/repos/somaticio/tensorflow.rb/branches{/branch}","tags_url":"https://api.github.com/repos/somaticio/tensorflow.rb/tags","blobs_url":"https://api.github.com/repos/somaticio/tensorflow.rb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/somaticio/tensorflow.rb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/somaticio/tensorflow.rb/git/refs{/sha}","trees_url":"https://api.github.com/repos/somaticio/tensorflow.rb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/somaticio/tensorflow.rb/statuses/{sha}","languages_url":"https://api.github.com/repos/somaticio/tensorflow.rb/languages","stargazers_url":"https://api.github.com/repos/somaticio/tensorflow.rb/stargazers","contributors_url":"https://api.github.com/repos/somaticio/tensorflow.rb/contributors","subscribers_url":"https://api.github.com/repos/somaticio/tensorflow.rb/subscribers","subscription_url":"https://api.github.com/repos/somaticio/tensorflow.rb/subscription","commits_url":"https://api.github.com/repos/somaticio/tensorflow.rb/commits{/sha}","git_commits_url":"https://api.github.com/repos/somaticio/tensorflow.rb/git/commits{/sha}","comments_url":"https://api.github.com/repos/somaticio/tensorflow.rb/comments{/number}","issue_comment_url":"https://api.github.com/repos/somaticio/tensorflow.rb/issues/comments{/number}","contents_url":"https://api.github.com/repos/somaticio/tensorflow.rb/contents/{+path}","compare_url":"https://api.github.com/repos/somaticio/tensorflow.rb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/somaticio/tensorflow.rb/merges","archive_url":"https://api.github.com/repos/somaticio/tensorflow.rb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/somaticio/tensorflow.rb/downloads","issues_url":"https://api.github.com/repos/somaticio/tensorflow.rb/issues{/number}","pulls_url":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls{/number}","milestones_url":"https://api.github.com/repos/somaticio/tensorflow.rb/milestones{/number}","notifications_url":"https://api.github.com/repos/somaticio/tensorflow.rb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/somaticio/tensorflow.rb/labels{/name}","releases_url":"https://api.github.com/repos/somaticio/tensorflow.rb/releases{/id}","deployments_url":"https://api.github.com/repos/somaticio/tensorflow.rb/deployments","created_at":"2016-06-16T14:59:51Z","updated_at":"2016-08-25T06:39:41Z","pushed_at":"2016-08-28T07:06:39Z","git_url":"git://github.com/somaticio/tensorflow.rb.git","ssh_url":"git@github.com:somaticio/tensorflow.rb.git","clone_url":"https://github.com/somaticio/tensorflow.rb.git","svn_url":"https://github.com/somaticio/tensorflow.rb","homepage":null,"size":2646,"stargazers_count":28,"watchers_count":28,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":8,"forks":9,"open_issues":8,"watchers":28,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/65"},"html":{"href":"https://github.com/somaticio/tensorflow.rb/pull/65"},"issue":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/issues/65"},"comments":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/issues/65/comments"},"review_comments":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/65/comments"},"review_comment":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/pulls/65/commits"},"statuses":{"href":"https://api.github.com/repos/somaticio/tensorflow.rb/statuses/ff755790011d0db463911ae2767c573da0108047"}}}}
{"actor":{"display_login":"chrhansen"}}