- for k = self.sorted, 1, -1 do
- local m = sorted[k]
- if self.succ[d] then
- if #self.succ[d] == 1 then
- d:updateGradInput(self.succ[d][1].gradInput)
- elseif #self.succ[d] > 1 then
- local sum
- for k = 1, #self.succ[d] do
- if sum then
- sum:add(self.succ[d][k].gradInput)
- else
- sum = self.succ[d][k].gradInput:clone()
- end
+ for _, node in pairs(self.node) do
+ node.gradInputSucc = {}
+ end
+
+ for k = #self.sorted, 1, -1 do
+ local m = self.sorted[k]
+ local node = self.node[m]
+ local pred, succ, gradInputSucc = node.pred, node.succ, node.gradInputSucc
+
+ -- We update m:gradInput
+ if #gradInputSucc == 1 then
+ m:updateGradInput(node.input, gradInputSucc[1])
+ elseif #gradInputSucc > 1 then
+ local sum
+ for k = 1, #succ do
+ if sum then
+ sum:add(succ[k].gradInput)
+ else
+ sum = succ[k].gradInput