[Yt-svn] commit/yt: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Wed Jun 1 10:04:20 PDT 2011


2 new changesets in yt:

http://bitbucket.org/yt_analysis/yt/changeset/3b98c3481420/
changeset:   3b98c3481420
branches:    
user:        MatthewTurk
date:        2011-06-01 18:34:45
summary:     Initial attempt at to/from buffer serialization for quadtrees.
affected #:  2 files (3.5 KB)

--- a/yt/frontends/ramses/setup.py	Mon May 30 12:41:45 2011 -0400
+++ b/yt/frontends/ramses/setup.py	Wed Jun 01 12:34:45 2011 -0400
@@ -9,6 +9,7 @@
         ["yt/frontends/ramses/_ramses_reader.pyx"],
         language="c++",
         include_dirs=["yt/frontends/ramses/ramses_headers/"],
+        libraries=["stdc++"],
         depends=glob.glob("yt/frontends/ramses/ramses_headers/*.hh")
         )
     config.make_config_py() # installs __config__.py


--- a/yt/utilities/_amr_utils/QuadTree.pyx	Mon May 30 12:41:45 2011 -0400
+++ b/yt/utilities/_amr_utils/QuadTree.pyx	Wed Jun 01 12:34:45 2011 -0400
@@ -31,6 +31,7 @@
 cimport cython
 
 from stdlib cimport malloc, free, abs
+from cython.operator cimport dereference as deref, preincrement as inc
 
 cdef extern from "stdlib.h":
     # NOTE that size_t might not be int
@@ -78,13 +79,14 @@
     node.nvals = nvals
     node.val = <np.float64_t *> malloc(
                 nvals * sizeof(np.float64_t))
-    for i in range(nvals):
-        node.val[i] = val[i]
-    node.weight_val = weight_val
     for i in range(2):
         for j in range(2):
             node.children[i][j] = NULL
     node.level = level
+    if val != NULL:
+        for i in range(nvals):
+            node.val[i] = val[i]
+        node.weight_val = weight_val
     return node
 
 cdef void QTN_free(QuadTreeNode *node):
@@ -136,6 +138,87 @@
                 self.root_nodes[i][j] = QTN_initialize(
                     pos, nvals, vals, weight_val, 0)
 
+    cdef int count_total_cells(self, QuadTreeNode *root):
+        cdef int total = 0
+        cdef int i, j
+        if root.children[0][0] == NULL: return 1
+        for i in range(2):
+            for j in range(2):
+                total += self.count_total_cells(root.children[i][j])
+        return total + 1
+
+    cdef int fill_buffer(self, QuadTreeNode *root, int curpos,
+                          np.ndarray[np.int32_t, ndim=1] refined,
+                          np.ndarray[np.float64_t, ndim=2] values,
+                          np.ndarray[np.float64_t, ndim=1] wval):
+        cdef int i, j
+        for i in range(self.nvals):
+            values[curpos, i] = root.val[i]
+        wval[curpos] = root.weight_val
+        if root.children[0][0] != NULL: refined[curpos] = 1
+        else: return curpos+1
+        curpos += 1
+        for i in range(2):
+            for j in range(2):
+                curpos = self.fill_buffer(root.children[i][j], curpos,
+                                 refined, values, wval)
+        return curpos
+
+    cdef int unfill_buffer(self, QuadTreeNode *root, int curpos,
+                          np.ndarray[np.int32_t, ndim=1] refined,
+                          np.ndarray[np.float64_t, ndim=2] values,
+                          np.ndarray[np.float64_t, ndim=1] wval):
+        cdef int i, j
+        for i in range(self.nvals):
+            root.val[i] = values[curpos, i]
+        root.weight_val = wval[curpos]
+        if refined[curpos] == 0: return curpos+1
+        curpos += 1
+        cdef QuadTreeNode *child
+        cdef np.int64_t pos[2]
+        for i in range(2):
+            for j in range(2):
+                pos[0] = root.pos[0]*2 + i
+                pos[1] = root.pos[1]*2 + j
+                child = QTN_initialize(pos, self.nvals, NULL, 0.0, root.level+1)
+                root.children[i][j] = child
+                curpos = self.unfill_buffer(child, curpos, refined, values, wval)
+        return curpos
+
+
+    def frombuffer(self, np.ndarray[np.int32_t, ndim=1] refined,
+                         np.ndarray[np.float64_t, ndim=2] values,
+                         np.ndarray[np.float64_t, ndim=1] wval):
+        self.merged = 1 # Just on the safe side
+        cdef int curpos = 0
+        cdef QuadTreeNode *root
+        for i in range(self.top_grid_dims[0]):
+            for j in range(self.top_grid_dims[1]):
+                curpos = self.unfill_buffer(self.root_nodes[i][j], curpos,
+                                 refined, values, wval)
+
+    def tobuffer(self):
+        cdef int total = 0
+        for i in range(self.top_grid_dims[0]):
+            for j in range(self.top_grid_dims[1]):
+                total += self.count_total_cells(self.root_nodes[i][j])
+        # We now have four buffers:
+        # Refined or not (total,) int32
+        # Values in each node (total, nvals) float64
+        # Weight values in each node (total,) float64
+        cdef np.ndarray[np.int32_t, ndim=1] refined 
+        refined = np.zeros(total, dtype='int32')
+        cdef np.ndarray[np.float64_t, ndim=2] values
+        values = np.zeros((total, self.nvals), dtype='float64')
+        cdef np.ndarray[np.float64_t, ndim=1] wval
+        wval = np.zeros(total, dtype='float64')
+        cdef int curpos = 0
+        for i in range(self.top_grid_dims[0]):
+            for j in range(self.top_grid_dims[1]):
+                curpos = self.fill_buffer(self.root_nodes[i][j], curpos,
+                                 refined, values, wval)
+        return (refined, values, wval)
+
     cdef void add_to_position(self,
                  int level, np.int64_t pos[2],
                  np.float64_t *val,


http://bitbucket.org/yt_analysis/yt/changeset/d7396cfdf180/
changeset:   d7396cfdf180
branches:    
user:        MatthewTurk
date:        2011-06-01 19:01:33
summary:     Fixed a subtle buffer-overrun and a bug that would have shown up when nvals >
1.

[to/from]buffer give correct results.
affected #:  1 file (10 bytes)

--- a/yt/utilities/_amr_utils/QuadTree.pyx	Wed Jun 01 12:34:45 2011 -0400
+++ b/yt/utilities/_amr_utils/QuadTree.pyx	Wed Jun 01 13:01:33 2011 -0400
@@ -293,11 +293,11 @@
         cdef np.float64_t *vdata = <np.float64_t *> nvals.data
         cdef np.float64_t *wdata = <np.float64_t *> nwvals.data
         cdef np.float64_t wtoadd
-        cdef np.float64_t *vtoadd = <np.float64_t *> \
-                alloca(sizeof(np.float64_t) * self.nvals)
+        cdef np.float64_t *vtoadd = <np.float64_t *> alloca(
+                sizeof(np.float64_t)*self.nvals)
         for i in range(self.top_grid_dims[0]):
             for j in range(self.top_grid_dims[1]):
-                for vi in range(self.nvals): vtoadd[i] = 0.0
+                for vi in range(self.nvals): vtoadd[vi] = 0.0
                 wtoadd = 0.0
                 curpos += self.fill_from_level(self.root_nodes[i][j],
                     level, curpos, pdata, vdata, wdata, vtoadd, wtoadd)
@@ -339,7 +339,7 @@
         if self.merged == 1:
             for i in range(self.nvals):
                 vtoadd[i] += node.val[i]
-                wtoadd += node.weight_val
+            wtoadd += node.weight_val
         for i in range(2):
             for j in range(2):
                 added += self.fill_from_level(node.children[i][j],
@@ -348,7 +348,7 @@
         if self.merged == 1:
             for i in range(self.nvals):
                 vtoadd[i] -= node.val[i]
-                wtoadd -= node.weight_val
+            wtoadd -= node.weight_val
         return added
 
     def __dealloc__(self):

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list