You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CSubTable.lua 696B

1234567891011121314151617181920212223242526
  1. local CSubTable, parent = torch.class('nn.CSubTable', 'nn.Module')
  2. function CSubTable:__init()
  3. parent.__init(self)
  4. self.gradInput = {}
  5. end
  6. function CSubTable:updateOutput(input)
  7. self.output:resizeAs(input[1]):copy(input[1])
  8. self.output:add(-1,input[2])
  9. return self.output
  10. end
  11. function CSubTable:updateGradInput(input, gradOutput)
  12. self.gradInput[1] = self.gradInput[1] or input[1].new()
  13. self.gradInput[2] = self.gradInput[2] or input[1].new()
  14. self.gradInput[1]:resizeAs(input[1]):copy(gradOutput)
  15. self.gradInput[2]:resizeAs(input[2]):copy(gradOutput):mul(-1)
  16. for i=#input+1, #self.gradInput do
  17. self.gradInput[i] = nil
  18. end
  19. return self.gradInput
  20. end