Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parameters() uses torch.type instead of type #1258

Merged
merged 1 commit into from
Jul 11, 2017

Conversation

nicholas-leonard
Copy link
Member

This allows you to pass custom tensors created with torch.class as parameters.

@pavanky
Copy link
Contributor

pavanky commented Jul 10, 2017

There are other places torch.type(foo) == 'table' is being used.

$ grep -e "torch.type(" *.lua | grep table
Concat.lua:      if (torch.type(v) == "table") then
Concat.lua:   local isTable = torch.type(input) == 'table'
Concat.lua:   local wasTable = torch.type(self.gradInput) == 'table'
Concat.lua:         if torch.type(currentGradInput) ~= 'table' then
ConcatTable.lua:      if (torch.type(v) == "table") then
ConcatTable.lua:   local isTable = torch.type(input) == 'table'
ConcatTable.lua:   local wasTable = torch.type(self.gradInput) == 'table'
ConcatTable.lua:         if torch.type(currentGradInput) ~= 'table' then
DontCast.lua:   if torch.type(src) == 'table' then
DontCast.lua:      dst = (torch.type(dst) == 'table') and dst or {}
DontCast.lua:      dst = (torch.type(dst) == type_str) and dst or torch.getmetatable(type_str).new()
GPU.lua:   elseif torch.type(proto) == 'table' then
GPU.lua:   if torch.type(src) == 'table' then
GPU.lua:      dst = torch.type(dst) == 'table' and dst or {}
MixtureTable.lua:   if self.table or torch.type(expertInputs) == 'table' then 
Module.lua:    if (torch.type(self.modules) == 'table') then
Module.lua:      if torch.type(from) == 'table' then
NaN.lua:   if torch.type(tensor) == 'table' then
PrintSize.lua:   if torch.type(input) == 'table' then
PrintSize.lua:   if torch.type(gradOutput) == 'table' then
SelectTable.lua:      if (torch.type(v) == "table") then
SpatialUpSamplingBilinear.lua:   if torch.type(params) == 'table' then
test.lua:   if (torch.type(t1) == "table") then
test.lua:   mytester:assert(torch.type(linear.output) == 'table')
utils.lua:   if torch.type(param) == 'table' then
utils.lua:   if torch.type(t2) == 'table' then
utils.lua:      t1 = (torch.type(t1) == 'table') and t1 or {t1}
utils.lua:   if torch.type(t2) == 'table' then
utils.lua:   if torch.type(t2) == 'table' then
utils.lua:      t1 = (torch.type(t1) == 'table') and t1 or {t1}
utils.lua:   if torch.type(t2) == 'table' then
utils.lua:      t1 = (torch.type(t1) == 'table') and t1 or {t1}
View.lua:   return torch.type(self)..'('..table.concat(self.size:totable(), ', ')..')'

I am not sure if all of them require changing to type, but at least some of them do. Can you see if this can be fixed more comprehensively ?

@nicholas-leonard
Copy link
Member Author

nicholas-leonard commented Jul 10, 2017

This issue replaces a type with torch.type. You are asking for replacing torch.type with type. Typically, the issue is with people using type instead of torch.type to detect tables.

@pavanky
Copy link
Contributor

pavanky commented Jul 10, 2017

Ah nevermind the previous comment then, but here's the new search:

$ grep -e "type(" *.lua | grep table | grep -v torch
Bilinear.lua:   assert(input and type(input) == 'table' and #input == 2,
Container.lua:        if type(from) == 'table' then
Container.lua:         elseif type(self[f]) == 'table' then
DontCast.lua:   if type(src) == 'table' then
FlattenTable.lua:  if type(input) == 'table' then
FlattenTable.lua:  if type(input) == 'table' then
FlattenTable.lua:    if type(input_map) ~= 'table' then
FlattenTable.lua:  if type(input_map) == 'table' then
FlattenTable.lua:  assert(type(input) == 'table', 'input must be a table')
FlattenTable.lua:  assert(type(input) == 'table', 'input must be a table')
FlattenTable.lua:  assert(type(input) == 'table', 'gradOutput must be a table')
hessian.lua:         if type(from) == 'table' then
Identity.lua:         elseif type(self[f]) == 'table' then
IndexLinear.lua:   assert(type(input) == 'table')
IndexLinear.lua:   if type(keys) == 'table' and type(values) == 'table' then
SparseLinear.lua:   if type(input) == 'table' then
SpatialFullConvolution.lua:  if type(inputTensor) == 'table' then
SpatialFullConvolution.lua:    if type(inputTensor) == 'table' then
SpatialFullConvolution.lua:      if type(self.gradInput) == 'table' then
SpatialFullConvolution.lua:    if type(input) == 'table' then
SpatialFullConvolution.lua:  if type(inputTensor) == 'table' then
utils.lua:   if #arg > 0 and type(arg[1]) == 'table' then
utils.lua:         elseif type(self[f]) == 'table' then
VolumetricFullConvolution.lua:  if type(inputTensor) == 'table' then
VolumetricFullConvolution.lua:    if type(inputTensor) == 'table' then
VolumetricFullConvolution.lua:      if type(self.gradInput) == 'table' then
VolumetricFullConvolution.lua:    if type(input) == 'table' then
VolumetricFullConvolution.lua:  if type(inputTensor) == 'table' then

@nicholas-leonard
Copy link
Member Author

@pavanky I changed all of them to torch.type except for one.

@nicholas-leonard nicholas-leonard merged commit 649f392 into torch:master Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants