{"action":"created","issue":{"url":"https://api.github.com/repos/torch/torch7/issues/170","labels_url":"https://api.github.com/repos/torch/torch7/issues/170/labels{/name}","comments_url":"https://api.github.com/repos/torch/torch7/issues/170/comments","events_url":"https://api.github.com/repos/torch/torch7/issues/170/events","html_url":"https://github.com/torch/torch7/issues/170","id":61757897,"number":170,"title":"torch Tensor breaks canonical Lua object definition","user":{"login":"ubasu","id":11484117,"avatar_url":"https://avatars.githubusercontent.com/u/11484117?v=3","gravatar_id":"","url":"https://api.github.com/users/ubasu","html_url":"https://github.com/ubasu","followers_url":"https://api.github.com/users/ubasu/followers","following_url":"https://api.github.com/users/ubasu/following{/other_user}","gists_url":"https://api.github.com/users/ubasu/gists{/gist_id}","starred_url":"https://api.github.com/users/ubasu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubasu/subscriptions","organizations_url":"https://api.github.com/users/ubasu/orgs","repos_url":"https://api.github.com/users/ubasu/repos","events_url":"https://api.github.com/users/ubasu/events{/privacy}","received_events_url":"https://api.github.com/users/ubasu/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-15T05:56:17Z","updated_at":"2015-03-15T15:39:42Z","closed_at":"2015-03-15T15:39:42Z","body":"The canonical way to create an object in Lua, as given in the PIL books, is as follows:\r\n\r\n```lua\r\nObj={v=0,t=torch.Tensor(1):zero()}\r\nfunction Obj:new(t)\r\n   t = t or {}\r\n   self.__index = self\r\n   return setmetatable(t,self)\r\nend\r\n```\r\n\r\nHowever, the tensor component of the object does not behave as expected. If we do\r\n\r\n```lua\r\nfunction Obj:update(n)\r\n   self.v=n\r\n   self.t[1]=n\r\nend\r\n\r\nfunction Obj:print()\r\n   print(self.v,self.t[1])\r\nend\r\n\r\na=Obj:new()\r\nb=Obj:new()\r\n\r\na:update(2)\r\nb:update(3)\r\n\r\na:print()\r\nb:print()\r\n```\r\n\r\nthen we get \r\n\r\n```lua\r\n2\t3\t\r\n3\t3\t\r\n```\r\n\r\nWe get the expected answer only if we define the object as\r\n```lua\r\nObj={}\r\nfunction Obj:new(t)\r\n   t = t or {v=0,t=torch.Tensor(1):zero()}\r\n   self.__index = self\r\n   return setmetatable(t,self)\r\nend\r\n```\r\n\r\nNot sure if this is a known issue and if it can be fixed.\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/torch/torch7/issues/comments/81106392","html_url":"https://github.com/torch/torch7/issues/170#issuecomment-81106392","issue_url":"https://api.github.com/repos/torch/torch7/issues/170","id":81106392,"user":{"login":"ubasu","id":11484117,"avatar_url":"https://avatars.githubusercontent.com/u/11484117?v=3","gravatar_id":"","url":"https://api.github.com/users/ubasu","html_url":"https://github.com/ubasu","followers_url":"https://api.github.com/users/ubasu/followers","following_url":"https://api.github.com/users/ubasu/following{/other_user}","gists_url":"https://api.github.com/users/ubasu/gists{/gist_id}","starred_url":"https://api.github.com/users/ubasu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubasu/subscriptions","organizations_url":"https://api.github.com/users/ubasu/orgs","repos_url":"https://api.github.com/users/ubasu/repos","events_url":"https://api.github.com/users/ubasu/events{/privacy}","received_events_url":"https://api.github.com/users/ubasu/received_events","type":"User","site_admin":false},"created_at":"2015-03-15T15:39:42Z","updated_at":"2015-03-15T15:39:42Z","body":"OK, thanks for clarifying. ;-)"}}