Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CSubTable.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eb7492055a5330a1ef058f8f987a437dc548d756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

local CSubTable, parent = torch.class('nn.CSubTable', 'nn.Module')

function CSubTable:__init()
   parent.__init(self)
   self.gradInput = {}
end

function CSubTable:updateOutput(input)
   self.output:resizeAs(input[1]):copy(input[1])
   self.output:add(-1,input[2])
   return self.output
end

function CSubTable:updateGradInput(input, gradOutput)
   self.gradInput[1] = self.gradInput[1] or input[1].new()
   self.gradInput[2] = self.gradInput[2] or input[1].new()
   self.gradInput[1]:resizeAs(input[1]):copy(gradOutput)
   self.gradInput[2]:resizeAs(input[2]):copy(gradOutput):mul(-1)

   for i=#input+1, #self.gradInput do
       self.gradInput[i] = nil
   end

   return self.gradInput
end