From d30ab5a0f6871e8efc27f9cd833241ac32363dd7 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Mon, 4 May 2015 18:53:50 -0400 Subject: [PATCH] Rename unpack to table.unpack for Lua 5.2 Torch7 defines table.unpack to unpack if it is not defined. --- CriterionTable.lua | 4 ++-- Euclidean.lua | 4 ++-- MM.lua | 4 ++-- MixtureTable.lua | 6 +++--- Module.lua | 4 ++-- View.lua | 2 +- WeightedEuclidean.lua | 4 ++-- doc/table.md | 4 ++-- hessian.lua | 4 ++-- test.lua | 16 ++++++++-------- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/CriterionTable.lua b/CriterionTable.lua index be008374c..14c64aca7 100644 --- a/CriterionTable.lua +++ b/CriterionTable.lua @@ -7,11 +7,11 @@ function CriterionTable:__init(criterion) end function CriterionTable:updateOutput(input) - self.output = self.criterion:updateOutput(unpack(input)) + self.output = self.criterion:updateOutput(table.unpack(input)) return self.output end function CriterionTable:updateGradInput(input, gradOutput) - self.criterion:updateGradInput(unpack(input)) + self.criterion:updateGradInput(table.unpack(input)) return self.gradInput end diff --git a/Euclidean.lua b/Euclidean.lua index d5700a521..ae3fee907 100644 --- a/Euclidean.lua +++ b/Euclidean.lua @@ -35,9 +35,9 @@ end local function view(res, src, ...) local args = {...} if src:isContiguous() then - res:view(src, unpack(args)) + res:view(src, table.unpack(args)) else - res:reshape(src, unpack(args)) + res:reshape(src, table.unpack(args)) end end diff --git a/MM.lua b/MM.lua index a7bfd9433..35f02cd61 100644 --- a/MM.lua +++ b/MM.lua @@ -18,7 +18,7 @@ end function MM:updateOutput(input) assert(#input == 2, 'input must be a pair of minibatch matrices') - local a, b = unpack(input) + local a, b = table.unpack(input) assert(a:nDimension() == 2 or a:nDimension() == 3, 'input tensors must be 2D or 3D') if a:nDimension() == 2 then @@ -47,7 +47,7 @@ end function MM:updateGradInput(input, gradOutput) assert(#input == 2, 'input must be a pair of tensors') - local a, b = unpack(input) + local a, b = table.unpack(input) self.gradInput[1]:resizeAs(a) self.gradInput[2]:resizeAs(b) diff --git a/MixtureTable.lua b/MixtureTable.lua index 77a7d3e64..18a5a073b 100644 --- a/MixtureTable.lua +++ b/MixtureTable.lua @@ -18,7 +18,7 @@ function MixtureTable:__init(dim) end function MixtureTable:updateOutput(input) - local gaterInput, expertInputs = unpack(input) + local gaterInput, expertInputs = table.unpack(input) self.dimG = 2 local batchSize = gaterInput:size(1) @@ -79,8 +79,8 @@ function MixtureTable:updateOutput(input) end function MixtureTable:updateGradInput(input, gradOutput) - local gaterInput, expertInputs = unpack(input) - local gaterGradInput, expertGradInputs = unpack(self.gradInput) + local gaterInput, expertInputs = table.unpack(input) + local gaterGradInput, expertGradInputs = table.unpack(self.gradInput) if self.table then if not self.backwardSetup then diff --git a/Module.lua b/Module.lua index d6b16fbca..fce579076 100644 --- a/Module.lua +++ b/Module.lua @@ -157,7 +157,7 @@ function Module:getParameters() if storageAndOffset == nil then return nil end - local _, offset = unpack(storageAndOffset) + local _, offset = table.unpack(storageAndOffset) return offset end @@ -211,7 +211,7 @@ function Module:getParameters() end for _, storageAndOffset in pairs(storages) do - local k, v = unpack(storageAndOffset) + local k, v = table.unpack(storageAndOffset) flatParameters[{{v+1,v+k:size()}}]:copy(Tensor():set(k)) end diff --git a/View.lua b/View.lua index 766e14998..33ddb697f 100644 --- a/View.lua +++ b/View.lua @@ -74,7 +74,7 @@ end function View:updateOutput(input) local bsz = batchsize(input, self.size, self.numInputDims, self.numElements) if bsz then - self.output = input:view(bsz, unpack(self.size:totable())) + self.output = input:view(bsz, table.unpack(self.size:totable())) else self.output = input:view(self.size) end diff --git a/WeightedEuclidean.lua b/WeightedEuclidean.lua index 071203e34..8acd35147 100644 --- a/WeightedEuclidean.lua +++ b/WeightedEuclidean.lua @@ -26,9 +26,9 @@ end local function view(res, src, ...) local args = {...} if src:isContiguous() then - res:view(src, unpack(args)) + res:view(src, table.unpack(args)) else - res:reshape(src, unpack(args)) + res:reshape(src, table.unpack(args)) end end diff --git a/doc/table.md b/doc/table.md index d4725bbb8..b8cb3a9d7 100755 --- a/doc/table.md +++ b/doc/table.md @@ -610,7 +610,7 @@ Example 1: -0.2955 [torch.DoubleTensor of dimension 2x1] -> =unpack(nn.SelectTable(1):backward(input, torch.randn(2, 3))) +> =table.unpack(nn.SelectTable(1):backward(input, torch.randn(2, 3))) -0.4891 -0.3495 -0.3182 -2.0999 0.7381 -0.5312 [torch.DoubleTensor of dimension 2x3] @@ -634,7 +634,7 @@ Example 2: } } -> =unpack(nn.SelectTable(2):backward(input, {torch.randn(2, 1), {torch.randn(2, 2)}})) +> =table.unpack(nn.SelectTable(2):backward(input, {torch.randn(2, 1), {torch.randn(2, 2)}})) 0 0 0 0 0 0 [torch.DoubleTensor of dimension 2x3] diff --git a/hessian.lua b/hessian.lua index 21302cb09..d63c6a857 100644 --- a/hessian.lua +++ b/hessian.lua @@ -330,7 +330,7 @@ function nn.hessian.enable() if storageAndOffset == nil then return nil end - local _, offset = unpack(storageAndOffset) + local _, offset = table.unpack(storageAndOffset) return offset end @@ -373,7 +373,7 @@ function nn.hessian.enable() end for _, storageAndOffset in pairs(storages) do - local k, v = unpack(storageAndOffset) + local k, v = table.unpack(storageAndOffset) flatParameters[{{v+1,v+k:size()}}]:copy(torch.Tensor():set(k)) end for k = 1,flatUsedParameters:nElement() do diff --git a/test.lua b/test.lua index a28674a90..2f7857b86 100644 --- a/test.lua +++ b/test.lua @@ -2863,7 +2863,7 @@ function nntest.View() local target = template:size():totable() local module = nn.View(template:size()) mytester:assertTableEq(module:forward(input):size():totable(), target, "Error in forward (1)") - local module = nn.View(unpack(target)) + local module = nn.View(table.unpack(target)) mytester:assertTableEq(module:forward(input):size():totable(), target, "Error in forward (2)") -- Minibatch @@ -2919,7 +2919,7 @@ function nntest.Reshape() local target = template:size():totable() local module = nn.Reshape(template:size()) mytester:assertTableEq(module:forward(input):size():totable(), target, "Error in forward (1)") - local module = nn.View(unpack(target)) + local module = nn.View(table.unpack(target)) mytester:assertTableEq(module:forward(input):size():totable(), target, "Error in forward (2)") -- Minibatch @@ -2945,7 +2945,7 @@ function nntest.SpatialUpSamplingNearest() end -- Check that the gradient is correct by using finite elements - local input = torch.Tensor(unpack(shape)):zero() + local input = torch.Tensor(table.unpack(shape)):zero() local err = jac.testJacobian(m, input) mytester:assertlt(err, precision, ' error on state ') @@ -3190,7 +3190,7 @@ function nntest.MM() local gradOutput = torch.randn(M, P) local gradInput = mm:backward({A, B}, gradOutput) mytester:assert(#gradInput == 2, 'gradInput must be table of size 2') - local gradA, gradB = unpack(gradInput) + local gradA, gradB = table.unpack(gradInput) mytester:assertTableEq(gradA:size():totable(), A:size():totable(), 'Gradient for input A has wrong size') mytester:assertTableEq(gradB:size():totable(), B:size():totable(), @@ -3221,7 +3221,7 @@ function nntest.BatchMMNoTranspose() local gradOutput = torch.randn(bSize, M, P) local gradInput = mm:backward({A, B}, gradOutput) mytester:assert(#gradInput == 2, 'gradInput must be table of size 2') - local gradA, gradB = unpack(gradInput) + local gradA, gradB = table.unpack(gradInput) mytester:assertTableEq(gradA:size():totable(), A:size():totable(), 'Gradient for input A has wrong size') mytester:assertTableEq(gradB:size():totable(), B:size():totable(), @@ -3255,7 +3255,7 @@ function nntest.BatchMMTransposeA() local gradOutput = torch.randn(bSize, M, P) local gradInput = mm:backward({A, B}, gradOutput) mytester:assert(#gradInput == 2, 'gradInput must be table of size 2') - local gradA, gradB = unpack(gradInput) + local gradA, gradB = table.unpack(gradInput) mytester:assertTableEq(gradA:size():totable(), A:size():totable(), 'Gradient for input A has wrong size') mytester:assertTableEq(gradB:size():totable(), B:size():totable(), @@ -3289,7 +3289,7 @@ function nntest.BatchMMTransposeB() local gradOutput = torch.randn(bSize, M, P) local gradInput = mm:backward({A, B}, gradOutput) mytester:assert(#gradInput == 2, 'gradInput must be table of size 2') - local gradA, gradB = unpack(gradInput) + local gradA, gradB = table.unpack(gradInput) mytester:assertTableEq(gradA:size():totable(), A:size():totable(), 'Gradient for input A has wrong size') mytester:assertTableEq(gradB:size():totable(), B:size():totable(), @@ -3323,7 +3323,7 @@ function nntest.BatchMMTransposeBoth() local gradOutput = torch.randn(bSize, M, P) local gradInput = mm:backward({A, B}, gradOutput) mytester:assert(#gradInput == 2, 'gradInput must be table of size 2') - local gradA, gradB = unpack(gradInput) + local gradA, gradB = table.unpack(gradInput) mytester:assertTableEq(gradA:size():totable(), A:size():totable(), 'Gradient for input A has wrong size') mytester:assertTableEq(gradB:size():totable(), B:size():totable(),