{"action":"created","issue":{"url":"https://api.github.com/repos/torch/nn/issues/402","labels_url":"https://api.github.com/repos/torch/nn/issues/402/labels{/name}","comments_url":"https://api.github.com/repos/torch/nn/issues/402/comments","events_url":"https://api.github.com/repos/torch/nn/issues/402/events","html_url":"https://github.com/torch/nn/issues/402","id":108441257,"number":402,"title":"Parallel.lua local variable point to self.modules output reference, which means the outputs will only store calcuation result of final row/col for input","user":{"login":"nomadshark","id":2752299,"avatar_url":"https://avatars.githubusercontent.com/u/2752299?v=3","gravatar_id":"","url":"https://api.github.com/users/nomadshark","html_url":"https://github.com/nomadshark","followers_url":"https://api.github.com/users/nomadshark/followers","following_url":"https://api.github.com/users/nomadshark/following{/other_user}","gists_url":"https://api.github.com/users/nomadshark/gists{/gist_id}","starred_url":"https://api.github.com/users/nomadshark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nomadshark/subscriptions","organizations_url":"https://api.github.com/users/nomadshark/orgs","repos_url":"https://api.github.com/users/nomadshark/repos","events_url":"https://api.github.com/users/nomadshark/events{/privacy}","received_events_url":"https://api.github.com/users/nomadshark/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-26T05:14:15Z","updated_at":"2015-09-26T08:44:53Z","closed_at":null,"body":"Parallel.lua, line 17:\r\n\r\n---error code ----\r\nfunction Parallel:updateOutput(input)\r\n   local nModule=input:size(self.inputDimension)\r\n   local outputs = {}\r\n\r\n   for i=1,nModule do\r\n      local currentInput = input:select(self.inputDimension,i)\r\n      local currentOutput = self.modules[i]:updateOutput(currentInput)\r\n      table.insert(outputs, currentOutput)\r\n      local outputSize = currentOutput:size(self.outputDimension)\r\n      \r\n      if i == 1 then\r\n         self.size:resize(currentOutput:dim()):copy(currentOutput:size())\r\n      else\r\n         self.size[self.outputDimension] = self.size[self.outputDimension] + outputSize\r\n      end\r\n      \r\n   end\r\n   self.output:resize(self.size)\r\n   \r\n   local offset = 1\r\n   for i=1,nModule do\r\n      local currentOutput = outputs[i]\r\n      local outputSize = currentOutput:size(self.outputDimension)\r\n      self.output:narrow(self.outputDimension, offset, outputSize):copy(currentOutput)\r\n      offset = offset + currentOutput:size(self.outputDimension)\r\n   end \r\n   return self.output\r\nend\r\n\r\n\r\n---correct code ----\r\nfunction Parallel:updateOutput(input)\r\n   local nModule=input:size(self.inputDimension)\r\n   local outputs = {}\r\n\r\n   for i=1,nModule do\r\n      local currentInput = input:select(self.inputDimension,i)\r\n      local currentOutput = self.modules[i]:updateOutput(currentInput):clone()\r\n      table.insert(outputs, currentOutput)\r\n      local outputSize = currentOutput:size(self.outputDimension)\r\n      \r\n      if i == 1 then\r\n         self.size:resize(currentOutput:dim()):copy(currentOutput:size())\r\n      else\r\n         self.size[self.outputDimension] = self.size[self.outputDimension] + outputSize\r\n      end\r\n      \r\n   end\r\n   self.output:resize(self.size)\r\n   \r\n   local offset = 1\r\n   for i=1,nModule do\r\n      local currentOutput = outputs[i]\r\n      local outputSize = currentOutput:size(self.outputDimension)\r\n      self.output:narrow(self.outputDimension, offset, outputSize):copy(currentOutput)\r\n      offset = offset + currentOutput:size(self.outputDimension)\r\n   end \r\n   return self.output\r\nend"},"comment":{"url":"https://api.github.com/repos/torch/nn/issues/comments/143412306","html_url":"https://github.com/torch/nn/issues/402#issuecomment-143412306","issue_url":"https://api.github.com/repos/torch/nn/issues/402","id":143412306,"user":{"login":"fmassa","id":9110200,"avatar_url":"https://avatars.githubusercontent.com/u/9110200?v=3","gravatar_id":"","url":"https://api.github.com/users/fmassa","html_url":"https://github.com/fmassa","followers_url":"https://api.github.com/users/fmassa/followers","following_url":"https://api.github.com/users/fmassa/following{/other_user}","gists_url":"https://api.github.com/users/fmassa/gists{/gist_id}","starred_url":"https://api.github.com/users/fmassa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmassa/subscriptions","organizations_url":"https://api.github.com/users/fmassa/orgs","repos_url":"https://api.github.com/users/fmassa/repos","events_url":"https://api.github.com/users/fmassa/events{/privacy}","received_events_url":"https://api.github.com/users/fmassa/received_events","type":"User","site_admin":false},"created_at":"2015-09-26T08:44:53Z","updated_at":"2015-09-26T08:44:53Z","body":"I don't think there need to be a `:clone` in https://github.com/torch/nn/blob/master/Parallel.lua#L17 . As `self.modules` is a table of modules, each individual module has its own `self.output`, which means that the `outputs` table will store the correct references."}}