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

DistKLDivCriterion.lua - github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bfad575671270d2b247ed47e0c83fbb938d39ba9 (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
34
local DistKLDivCriterion, parent = torch.class('nn.DistKLDivCriterion', 'nn.Criterion')

function DistKLDivCriterion:__init()
   parent.__init(self)
   self.sizeAverage = true
end

function DistKLDivCriterion:updateOutput(input, target)
   assert(input:dim() == target:dim() and
      torch.LongTensor(input:size()):eq(torch.LongTensor(target:size())):all(),
      'input and target should have the same size')
   self.output_tensor = self.output_tensor or input.new(1)
   input.THNN.DistKLDivCriterion_updateOutput(
      input:cdata(),
      target:cdata(),
      self.output_tensor:cdata(),
      self.sizeAverage
   )
   self.output = self.output_tensor[1]
   return self.output
end

function DistKLDivCriterion:updateGradInput(input, target)
   assert(input:dim() == target:dim() and
      torch.LongTensor(input:size()):eq(torch.LongTensor(target:size())):all(),
      'input and target should have the same size')
   input.THNN.DistKLDivCriterion_updateGradInput(
      input:cdata(),
      target:cdata(),
      self.gradInput:cdata(),
      self.sizeAverage
   )
   return self.gradInput
end