[Yt-svn] yt: Faster MergerTreeDotOutput SQL queries.

hg at spacepope.org hg at spacepope.org
Wed Mar 31 17:35:52 PDT 2010


hg Repository: yt
details:   yt/rev/fca725332306
changeset: 1507:fca725332306
user:      Stephen Skory <stephenskory at yahoo.com>
date:
Wed Mar 31 17:35:44 2010 -0700
description:
Faster MergerTreeDotOutput SQL queries.

diffstat:

 yt/extensions/MergerTree.py |  40 +++++++++++++++++++++++-----------------
 1 files changed, 23 insertions(+), 17 deletions(-)

diffs (51 lines):

diff -r ce261b18ec2c -r fca725332306 yt/extensions/MergerTree.py
--- a/yt/extensions/MergerTree.py	Wed Mar 31 15:51:34 2010 -0700
+++ b/yt/extensions/MergerTree.py	Wed Mar 31 17:35:44 2010 -0700
@@ -694,24 +694,30 @@
         # This stores the newly discovered parent halos.
         newhalos = set([])
         for halo in halos:
-            for i in range(5):
-                line = 'SELECT GlobalHaloID, ChildHaloFrac%d from Halos\
-                where ChildHaloID%d=?;' % (i, i)
-                values = (halo,)
-                self.cursor.execute(line, values)
+            line = "SELECT GlobalHaloID, ChildHaloFrac0,\
+                ChildHaloFrac1, ChildHaloFrac2,ChildHaloFrac3, ChildHaloFrac4,\
+                ChildHaloID0, ChildHaloID1, ChildHaloID2, \
+                ChildHaloID3, ChildHaloID4 \
+                FROM Halos WHERE\
+                ChildHaloID0=? or ChildHaloID1=? or ChildHaloID2=? or\
+                ChildHaloID3=? or ChildHaloID4=?;"
+            values = (halo, halo, halo, halo, halo)
+            self.cursor.execute(line, values)
+            result = self.cursor.fetchone()
+            while result:
+                res = list(result)
+                pID = result[0]
+                pfracs = res[1:6]
+                cIDs = res[6:11]
+                for pair in zip(cIDs, pfracs):
+                    if pair[1] <= self.link_min or pair[0] != halo:
+                        continue
+                    else:
+                        self.nodes[halo].parentIDs.append(pID)
+                        self.links[pID].childIDs.append(halo)
+                        self.links[pID].fractions.append(pair[1])
+                        newhalos.add(pID)
                 result = self.cursor.fetchone()
-                while result:
-                    pID = result[0]
-                    pfrac = result[1]
-                    if pfrac <= self.link_min:
-                        result = self.cursor.fetchone()
-                        continue
-                    # Store this.
-                    self.nodes[halo].parentIDs.append(pID)
-                    self.links[pID].childIDs.append(halo)
-                    self.links[pID].fractions.append(pfrac)
-                    newhalos.add(pID)
-                    result = self.cursor.fetchone()
         return newhalos
     
     def _add_nodes(self, newhalos):



More information about the yt-svn mailing list