Commits

Martin Alnæs  committed 0147ef5

Bugfix in graph rebuilding after factorization.

  • Participants
  • Parent commits 5e7318d

Comments (0)

Files changed (2)

File site-packages/uflacs/analysis/factorization.py

 
 def rebuild_scalar_graph_from_factorization(AV, FV, IM):
     # TODO: What about multiple target_variables?
+
+    # Build initial graph
     SV = []
     SV.extend(AV)
     SV.extend(FV)
-    g = 0
-    for argkey in sorted(IM.keys()):
+    se2i = { s: i for i, s in enumerate(SV) }
+
+    def add_vertex(h):
+        # Avoid adding vertices twice
+        i = se2i.get(h)
+        if i is None:
+            se2i[h] = len(SV)
+            SV.append(h)
+
+    # Add factorization monomials
+    argkeys = sorted(IM.keys())
+    fs = []
+    for argkey in argkeys:
         # Add each subproduct of this monomial
         f = FV[IM[argkey]]
         for argindex in argkey:
             f = f*AV[argindex]
-            SV.append(f)
-        # f is now the full monomial, add it as a term to g
+            add_vertex(f)
+        # f is now the full monomial, store it as a term for sum below
+        fs.append(f)
+
+    # Add sum of factorization monomials
+    g = 0
+    for f in fs:
         g = g + f
-        if g != f: # avoid adding first term twice
-            SV.append(g)
+        add_vertex(g)
 
     # Rebuild dependencies
-    se2i = { s: i for i, s in enumerate(SV) }
     dependencies = compute_dependencies(se2i, SV)
 
     if 0:

File site-packages/uflacs/utils/tictoc.py

 
 import time
-from uflacs.utils.log import info
+from uflacs.utils.log import debug
 
 class TicToc(object):
     def __init__(self, name, showinfo=None, gettime=None):
         self.name = name
-        self.info = showinfo or info
+        self.info = showinfo or debug
         self.time = gettime or time.time
         self._ticdata = []