DAG:addEdge now allows to add a bunch of edges in one shot. This allows to use anonym...
[dagnn.git] / dagnn.lua
index 7fc1018..9202932 100755 (executable)
--- a/dagnn.lua
+++ b/dagnn.lua
@@ -40,12 +40,19 @@ function DAG:createNode(nnm)
    end
 end
 
-function DAG:addEdge(nnma, nnmb)
+-- The main use should be to add an edge between two modules, but it
+-- can also add a full sequence of modules
+function DAG:addEdge(...)
    self.sorted = nil
-   self:createNode(nnma)
-   self:createNode(nnmb)
-   table.insert(self.node[nnmb].pred, nnma)
-   table.insert(self.node[nnma].succ, nnmb)
+   local prev
+   for _, nnm in pairs({...}) do
+      self:createNode(nnm)
+      if prev then
+         table.insert(self.node[nnm].pred, prev)
+         table.insert(self.node[prev].succ, nnm)
+      end
+      prev = nnm
+   end
 end
 
 -- Apply f on t recursively; use the corresponding element from args