torch / nngraph

Graph Computation for nn
Other
299 stars 96 forks source link

Error for single input gModule #133

Closed tudor-berariu closed 8 years ago

tudor-berariu commented 8 years ago

I am trying to write a nn.gModule that works for an arbitrary number of inputs, but I get an error when there is only one. The following code works fine with inputsNo > 1, but fails for inputsNo = 1.

require("nn")
require("nngraph")

local` inputsNo = 1        -- it works for inputsNo >=2, but not for inputsNo = 1

local inputs, linInputs = {}, {}

for i = 1, inputsNo do
   inputs[i] = nn.Identity()()
   linInputs[i] = nn.Linear(i, i)(inputs[i])
end

local output = nn.JoinTable(1,1)(linInputs)
local rnn = nn.gModule(inputs, {output})

local X = {}
for i = 1, inputsNo do  X[i] = torch.rand(i)  end

rnn:forward(X)
tudor-berariu commented 8 years ago

Applying nngraph.nest on the value sent to nn.JoinTable solved my problem.