<commit_before>local C = ccn2.C

local SpatialCrossResponseNormalization, parent = torch.class('ccn2.SpatialCrossResponseNormalization', 'nn.Module')

function SpatialCrossResponseNormalization:__init(size, addScale, powScale, minDiv)
  parent.__init(self)
  
  self.size = size
  self.addScale = addScale or 0.0001
  -- dic['scale'] /= dic['size'] if self.norm_type == self.CROSSMAP_RESPONSE_NORM else dic['size']**2
  self.addScale = self.addScale / self.size
  self.powScale = powScale or 0.75
  self.minDiv = minDiv or 1.0
  -- TODO: check layer.py:1333

  self.output = torch.Tensor()
  self.gradInput = torch.Tensor()
  
  self:cuda()
end


function SpatialCrossResponseNormalization:updateOutput(input)
  ccn2.typecheck(input)
  ccn2.inputcheck(input)
  local nBatch = input:size(4)
  local inputC = input:view(input:size(1) * input:size(2) * input:size(3), input:size(4))
  self.output:resize(inputC:size())
  
  C['convResponseNormCrossMap'](inputC:cdata(), self.output:cdata(), 
                                input:size(1), self.size, 
                                self.addScale, self.powScale, self.minDiv, true)
  
  self.output = self.output:view(input:size(1), input:size(2), input:size(3), input:size(4))
  return self.output
end


function SpatialCrossResponseNormalization:updateGradInput(input, gradOutput)
  ccn2.typecheck(input); ccn2.typecheck(gradOutput);
  ccn2.inputcheck(input); ccn2.inputcheck(gradOutput);
  local nBatch = input:size(4)
  local inputC = input:view(input:size(1) * input:size(2) * input:size(3), input:size(4))
  local gradOutputC = gradOutput:view(gradOutput:size(1) * gradOutput:size(2) * gradOutput:size(3), gradOutput:size(4))
  local outputC = self.output:view(gradOutput:size(1) * gradOutput:size(2) * gradOutput:size(3), gradOutput:size(4))
  
  self.gradInput:resize(inputC:size())
 
  C['convResponseNormCrossMapUndo'](gradOutputC:cdata(), inputC:cdata(), outputC:cdata(), 
                                    self.gradInput:cdata(), input:size(1), self.size, 
                                    self.addScale, self.powScale, self.minDiv, true, 0, 1)
  self.gradInput = self.gradInput:view(input:size(1), input:size(2), input:size(3), input:size(4))
  return self.gradInput
end<commit_msg>set 'blocked' to false by default and pass as an option<commit_after>local C = ccn2.C

local SpatialCrossResponseNormalization, parent = torch.class('ccn2.SpatialCrossResponseNormalization', 'nn.Module')

function SpatialCrossResponseNormalization:__init(size, addScale, powScale, minDiv, blocked)
  parent.__init(self)
  
  self.size = size
  self.addScale = addScale or 0.0001
  -- dic['scale'] /= dic['size'] if self.norm_type == self.CROSSMAP_RESPONSE_NORM else dic['size']**2
  self.addScale = self.addScale / self.size
  self.powScale = powScale or 0.75
  self.minDiv = minDiv or 1.0
  self.blocked = blocked or false
  -- TODO: check layer.py:1333

  self.output = torch.Tensor()
  self.gradInput = torch.Tensor()
  
  self:cuda()
end


function SpatialCrossResponseNormalization:updateOutput(input)
  ccn2.typecheck(input)
  ccn2.inputcheck(input)
  local nBatch = input:size(4)
  local inputC = input:view(input:size(1) * input:size(2) * input:size(3), input:size(4))
  self.output:resize(inputC:size())
  
  C['convResponseNormCrossMap'](inputC:cdata(), self.output:cdata(), 
                                input:size(1), self.size, 
                                self.addScale, self.powScale, self.minDiv, self.blocked)
  
  self.output = self.output:view(input:size(1), input:size(2), input:size(3), input:size(4))
  return self.output
end


function SpatialCrossResponseNormalization:updateGradInput(input, gradOutput)
  ccn2.typecheck(input); ccn2.typecheck(gradOutput);
  ccn2.inputcheck(input); ccn2.inputcheck(gradOutput);
  local nBatch = input:size(4)
  local inputC = input:view(input:size(1) * input:size(2) * input:size(3), input:size(4))
  local gradOutputC = gradOutput:view(gradOutput:size(1) * gradOutput:size(2) * gradOutput:size(3), gradOutput:size(4))
  local outputC = self.output:view(gradOutput:size(1) * gradOutput:size(2) * gradOutput:size(3), gradOutput:size(4))
  
  self.gradInput:resize(inputC:size())
 
  C['convResponseNormCrossMapUndo'](gradOutputC:cdata(), inputC:cdata(), outputC:cdata(), 
                                    self.gradInput:cdata(), input:size(1), self.size, 
                                    self.addScale, self.powScale, self.minDiv, self.blocked, 0, 1)
  self.gradInput = self.gradInput:view(input:size(1), input:size(2), input:size(3), input:size(4))
  return self.gradInput
end
{'fraction_non_alphanumeric': 0.13993471164309032, 'fraction_numerical': 0.02306855277475517, 'mean_word_length': 4.210884353741497, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5308487', 'n_tokens_mistral': 1618, 'n_tokens_neox': 1559, 'n_words': 266}