Skip to content

Commit

Permalink
Merge pull request torch#256 from colesbury/lua52
Browse files Browse the repository at this point in the history
Rename unpack to table.unpack for Lua 5.2
  • Loading branch information
soumith committed May 13, 2015
2 parents 905ea8c + d30ab5a commit 8b9b5cd
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions CriterionTable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Euclidean.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions MM.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions MixtureTable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function Module:getParameters()
if storageAndOffset == nil then
return nil
end
local _, offset = unpack(storageAndOffset)
local _, offset = table.unpack(storageAndOffset)
return offset
end

Expand Down Expand Up @@ -200,7 +200,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

Expand Down
2 changes: 1 addition & 1 deletion View.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions WeightedEuclidean.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions doc/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions hessian.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,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
Expand Down Expand Up @@ -2979,7 +2979,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
Expand All @@ -3005,7 +3005,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 ')
Expand Down Expand Up @@ -3250,7 +3250,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(),
Expand Down Expand Up @@ -3281,7 +3281,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(),
Expand Down Expand Up @@ -3315,7 +3315,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(),
Expand Down Expand Up @@ -3349,7 +3349,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(),
Expand Down Expand Up @@ -3383,7 +3383,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(),
Expand Down

0 comments on commit 8b9b5cd

Please sign in to comment.