{"action":"created","issue":{"url":"https://api.github.com/repos/torch/nn/issues/483","labels_url":"https://api.github.com/repos/torch/nn/issues/483/labels{/name}","comments_url":"https://api.github.com/repos/torch/nn/issues/483/comments","events_url":"https://api.github.com/repos/torch/nn/issues/483/events","html_url":"https://github.com/torch/nn/issues/483","id":117714542,"number":483,"title":"calling :getParameters twice breaks references","user":{"login":"willwhitney","id":597829,"avatar_url":"https://avatars.githubusercontent.com/u/597829?v=3","gravatar_id":"","url":"https://api.github.com/users/willwhitney","html_url":"https://github.com/willwhitney","followers_url":"https://api.github.com/users/willwhitney/followers","following_url":"https://api.github.com/users/willwhitney/following{/other_user}","gists_url":"https://api.github.com/users/willwhitney/gists{/gist_id}","starred_url":"https://api.github.com/users/willwhitney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willwhitney/subscriptions","organizations_url":"https://api.github.com/users/willwhitney/orgs","repos_url":"https://api.github.com/users/willwhitney/repos","events_url":"https://api.github.com/users/willwhitney/events{/privacy}","received_events_url":"https://api.github.com/users/willwhitney/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-11-19T00:37:55Z","updated_at":"2015-11-19T01:23:10Z","closed_at":null,"body":"```\r\nth> lin = nn.Linear(2,2)\r\nth> p1, gp1 = lin:getParameters()\r\nth> p1\r\n 0.4611\r\n-0.6737\r\n-0.6769\r\n 0.3312\r\n-0.3065\r\n-0.0952\r\n[torch.DoubleTensor of size 6]\r\n```\r\n`getParameters` returns a reference so I can change the parameters directly. This is the behavior we want. \r\n```\r\nth> p1:fill(1)\r\n 1\r\n 1\r\n 1\r\n 1\r\n 1\r\n 1\r\n[torch.DoubleTensor of size 6]\r\n\r\nth> p2, gp2 = lin:getParameters()\r\nth> p2\r\n 1\r\n 1\r\n 1\r\n 1\r\n 1\r\n 1\r\n[torch.DoubleTensor of size 6]\r\n```\r\nBut now that we've called `getParameters` again, `p1` is no longer a reference to the real params.\r\n```\r\nth> p2:fill(2)\r\n 2\r\n 2\r\n 2\r\n 2\r\n 2\r\n 2\r\n[torch.DoubleTensor of size 6]\r\n\r\nth> p1\r\n 1\r\n 1\r\n 1\r\n 1\r\n 1\r\n 1\r\n[torch.DoubleTensor of size 6]\r\n```\r\n\r\nThis means that just by calling `getParameters` too often, you can break your code."},"comment":{"url":"https://api.github.com/repos/torch/nn/issues/comments/157916403","html_url":"https://github.com/torch/nn/issues/483#issuecomment-157916403","issue_url":"https://api.github.com/repos/torch/nn/issues/483","id":157916403,"user":{"login":"willwhitney","id":597829,"avatar_url":"https://avatars.githubusercontent.com/u/597829?v=3","gravatar_id":"","url":"https://api.github.com/users/willwhitney","html_url":"https://github.com/willwhitney","followers_url":"https://api.github.com/users/willwhitney/followers","following_url":"https://api.github.com/users/willwhitney/following{/other_user}","gists_url":"https://api.github.com/users/willwhitney/gists{/gist_id}","starred_url":"https://api.github.com/users/willwhitney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willwhitney/subscriptions","organizations_url":"https://api.github.com/users/willwhitney/orgs","repos_url":"https://api.github.com/users/willwhitney/repos","events_url":"https://api.github.com/users/willwhitney/events{/privacy}","received_events_url":"https://api.github.com/users/willwhitney/received_events","type":"User","site_admin":false},"created_at":"2015-11-19T01:23:10Z","updated_at":"2015-11-19T01:23:10Z","body":"Ah, OK. Makes sense.\r\n\r\nThat would be an A+ change."}}