outputs = None
chxs = []
if self.debug:
viz = []
read_vectors = [last_read] * max_length
// outs = [input[:, x, :] for x in range(max_length)]
outs = [T.cat([input[:, x, :], last_read], 1) for x in range(max_length)]
for layer in range(self.num_layers):
// this layer"s hidden states
chx = controller_hidden[layer]
m = mem_hidden if self.share_memory else mem_hidden[layer]
// pass through controller
if self.debug:
outs, _, mem_debug, (chx, m) = self._layer_forward(outs,layer,(chx, m))
else:
outs, _, (chx, m) = self._layer_forward(outs, layer, (chx, m))
// debug memory
if self.debug:
viz.append(mem_debug)
// store the memory back (per layer or shared)
if self.share_memory:
mem_hidden = m
else:
mem_hidden[layer] = m
chxs.append(chx)
if layer == self.num_layers - 1:
// final outputs
outputs = T.stack(outs, 1)
else:
// the controller output + read vectors go into next layer
outs = [T.cat([o, r], 1) for o, r in zip(outs, read_vectors)]
// outs = [o for o in outs]
if self.debug:
viz = np.array(viz)s = list(viz.shape)viz = viz.reshape(s[0]*s[1], s[2]*s[3])
controller_hidden = chxs
if not self.batch_first: