blob: 7da2a6589502b4375cfc8b9d608ed2aa43ae4667 (
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
|
local SoftMin, parent = torch.class('nn.SoftMin', 'nn.Module')
function SoftMin:updateOutput(input)
self.mininput = self.mininput or input.new()
self.mininput:resizeAs(input):copy(input):mul(-1)
input.THNN.SoftMax_updateOutput(
self.mininput:cdata(),
self.output:cdata()
)
return self.output
end
function SoftMin:updateGradInput(input, gradOutput)
self.mininput = self.mininput or input.new()
self.mininput:resizeAs(input):copy(input):mul(-1)
input.THNN.SoftMax_updateGradInput(
self.mininput:cdata(),
gradOutput:cdata(),
self.gradInput:cdata(),
self.output:cdata()
)
self.gradInput:mul(-1)
return self.gradInput
end
function SoftMin:clearState()
if self.mininput then self.mininput:set() end
return parent.clearState(self)
end
|