-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathZeroModule.lua
More file actions
14 lines (10 loc) · 949 Bytes
/
ZeroModule.lua
File metadata and controls
14 lines (10 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
local ZeroModule, parent = torch.class('nn.ZeroModule', 'nn.Module')
-- Throw away the input. Used in conjunction with a Criteria in a ParallelDistributingTable. A Criterion returns the loss value, but this should not be passed on to the rest of the network; a Criterion requires no gradOutput to updateGradInput. Since ParallelDistributingTable sets the elements of the output array according to the outputs of each stream, and setting an array value to nil makes it as if it isn't there, this just eliminates the output from the array (and reduces the size of the array by one). Be careful when the ignored element is in the middle of the array, since the length operator and the ipairs iterator stop at the first nil entry.
function ZeroModule:updateOutput(input)
self.output = nil
return self.output
end
function ZeroModule:updateGradInput(input, gradOutput)
self.gradInput:resizeAs(input):zero()
return self.gradInput
end