diff options
author | Ronan Collobert <ronan@collobert.com> | 2012-01-25 17:55:20 +0400 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2012-01-25 17:55:20 +0400 |
commit | 4df3893abd1b9f840f1d9a8c1859799ccbf941de (patch) | |
tree | e8a1e1cc1b6ea6e47855347b157eaf419fdb357b /Copy.lua |
initial revamp of torch7 tree
Diffstat (limited to 'Copy.lua')
-rw-r--r-- | Copy.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Copy.lua b/Copy.lua new file mode 100644 index 0000000..7b6eeb3 --- /dev/null +++ b/Copy.lua @@ -0,0 +1,33 @@ +local Copy, parent = torch.class('nn.Copy', 'nn.Module') + +function Copy:__init(intype, outtype) + intype = intype or torch.getmetatable(torch.Tensor.__typename) + outtype = outtype or torch.getmetatable(torch.Tensor.__typename) + + parent.__init(self) + self.gradInput = torch.getmetatable(intype).new() + self.output = torch.getmetatable(outtype).new() + + if intype == outtype then + + self.updateOutput = function(self, input) + self.output = input + return input + end + + self.updateGradInput = function(self, input, gradOutput) + self.gradInput = gradOutput + return gradOutput + end + end +end + +function Copy:updateOutput(input) + self.output:resize(input:size()):copy(input) + return self.output +end + +function Copy:updateGradInput(input, gradOutput) + self.gradInput:resize(gradOutput:size()):copy(gradOutput) + return self.gradInput +end |