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

github.com/torch/nn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon N <CodeRect@users.noreply.github.com>2016-05-16 05:09:47 +0300
committerSimon N <CodeRect@users.noreply.github.com>2016-05-16 05:09:47 +0300
commit4c56c19571b06aead938da67b80b281e9d467068 (patch)
treedf664813588be61b531ebad5253caa0f77fd138e /Narrow.lua
parent9f64ffa3e20c73ada3ab8c1564eb821e719f0155 (diff)
added support for negative lenghts to Narrow
Diffstat (limited to 'Narrow.lua')
-rw-r--r--Narrow.lua12
1 files changed, 10 insertions, 2 deletions
diff --git a/Narrow.lua b/Narrow.lua
index b6f4cb5..07322d8 100644
--- a/Narrow.lua
+++ b/Narrow.lua
@@ -11,15 +11,23 @@ function Narrow:__init(dimension,offset,length)
end
function Narrow:updateOutput(input)
- local output=input:narrow(self.dimension,self.index,self.length)
+ local length = self.length
+ if length < 0 then
+ length = input:size(self.dimension) - self.index + self.length + 2
+ end
+ local output=input:narrow(self.dimension,self.index,length)
self.output = self.output:typeAs(output)
self.output:resizeAs(output):copy(output)
return self.output
end
function Narrow:updateGradInput(input, gradOutput)
+ local length = self.length
+ if length < 0 then
+ length = input:size(self.dimension) - self.index + self.length + 2
+ end
self.gradInput = self.gradInput:typeAs(input)
self.gradInput:resizeAs(input):zero()
- self.gradInput:narrow(self.dimension,self.index,self.length):copy(gradOutput)
+ self.gradInput:narrow(self.dimension,self.index,length):copy(gradOutput)
return self.gradInput
end