torch/nn — pull request #46 by jonathantompson (2014-07-22 18:55:58+00:00)
Title: Made module type conversion for member variables recursive

This has been annoying me forever. Modules that have internal tables of tensors do not get type casted properly... Which actually results in runtime bugs. This is true for MANY modules. Try this:

```lua
require 'cunn'
x = torch.rand(4,4)
y = torch.rand(4,4)
m = nn.CDivTable()
m:forward({x,y})
m:backward({x,y}, m.output)
m:cuda() -- FAILS!
```

This is true for all of the C***Table modules as well as many of the parallel container modules. I think the easiest and cleanest solution is to modify Module to do a recursive type conversion on it's member variables. However, I do understand that this may have side effects that will make this PR less appealing to the moderators... specifically, I think Clement won't like this :-) Even still, I think this is a necessary change and if it does have consequences I think those modules should be fixed. The nn and cunn tests all pass and as far as I can tell no existing modules are broken by this change.

I think the only case where this change would break existing code is if If someone WAS hiding tensors that they didn't want type-casted in tables. However, I think if they were doing this in the first place it's incredibly hacky and probably should be changed regardless.

Anyway, that's my 2 cents... What do you guys think?

Pretty please accept this pull request :-)