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

Copy.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7b6eeb341d35aac672dccaa32afe7e1cf6ae3f60 (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
27
28
29
30
31
32
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