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

MulConstant.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 982ab4173db029313a1a511f2047e6774cdc39ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local MulConstant, parent = torch.class('nn.MulConstant', 'nn.Module')

function MulConstant:__init(constant_scalar)
  parent.__init(self)
  assert(type(constant_scalar) == 'number', 'input is not scalar!')
  self.constant_scalar = constant_scalar
end

function MulConstant:updateOutput(input)
  self.output:resizeAs(input)
  self.output:copy(input)
  self.output:mul(self.constant_scalar)
  return self.output
end 

function MulConstant:updateGradInput(input, gradOutput)
  self.gradInput:resizeAs(gradOutput)
  self.gradInput:copy(gradOutput)
  self.gradInput:mul(self.constant_scalar)
  return self.gradInput
end