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:
Diffstat (limited to 'Narrow.lua')
-rw-r--r--Narrow.lua14
1 files changed, 12 insertions, 2 deletions
diff --git a/Narrow.lua b/Narrow.lua
index 0754d45..a6ebaa3 100644
--- a/Narrow.lua
+++ b/Narrow.lua
@@ -16,7 +16,12 @@ function Narrow:updateOutput(input)
if length < 0 then
length = input:size(dim) - self.index + self.length + 2
end
- local output=input:narrow(dim,self.index,length)
+ local index = self.index
+ if self.index < 0 then
+ index = 1
+ length = input:size(dim) - length
+ end
+ local output=input:narrow(dim, index, length)
self.output = self.output:typeAs(output)
self.output:resizeAs(output):copy(output)
return self.output
@@ -28,8 +33,13 @@ function Narrow:updateGradInput(input, gradOutput)
if length < 0 then
length = input:size(dim) - self.index + self.length + 2
end
+ local index = self.index
+ if self.index < 0 then
+ index = 1
+ length = input:size(dim) - length
+ end
self.gradInput = self.gradInput:typeAs(input)
self.gradInput:resizeAs(input):zero()
- self.gradInput:narrow(dim,self.index,length):copy(gradOutput)
+ self.gradInput:narrow(dim,index,length):copy(gradOutput)
return self.gradInput
end