-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 element from args
+-- (i.e. same keys) as second parameter to f when available; return
+-- the results from f, organized in a similarly nested table.
+function DAG:nestedApply(f, t, args)
+ if torch.type(t) == 'table' then
+ local result = {}
+ for k, s in pairs(t) do
+ result[k] = self:nestedApply(f, s, args and args[k])