-function Graph:setInput(i)
- if torch.type(i) == 'table' then
- self.inputModules = i
- for _, m in ipairs(i) do
- if not self.pred[m] and not self.succ[m] then
- self:add(m)
- end
+function DAG:addEdge(nnma, nnmb)
+ self.sorted = nil
+ self:createNode(nnma)
+ self:createNode(nnmb)
+ table.insert(self.node[nnmb].pred, nnma)
+ table.insert(self.node[nnma].succ, nnmb)
+end
+
+-- Apply f on t recursively; use the corresponding a1 and a2 elements
+-- (i.e. same keys) as second and third parameters to f when
+-- available; return the results from f, organized in a similarly
+-- nested table.
+function DAG:nestApply(f, t, a1, a2)
+ if torch.type(t) == 'table' then
+ local result = {}
+ for k, s in pairs(t) do
+ result[k] = self:nestApply(f, s, a1 and a1[k], a2 and a2[k])