[yt-svn] commit/yt: ngoldbaum: Merged in MatthewTurk/yt (pull request #1180)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Sep 2 15:49:07 PDT 2014


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/1998e420f9eb/
Changeset:   1998e420f9eb
Branch:      yt
User:        ngoldbaum
Date:        2014-09-03 00:48:57
Summary:     Merged in MatthewTurk/yt (pull request #1180)

Adding quadtree overflow check.
Affected #:  3 files

diff -r f25f41eb4304ada81288cad3ce022e5e9214eed1 -r 1998e420f9eb51687cb44d529a2053bd6dcfd29d yt/frontends/stream/tests/test_stream_amrgrids.py
--- /dev/null
+++ b/yt/frontends/stream/tests/test_stream_amrgrids.py
@@ -0,0 +1,28 @@
+from yt.testing import *
+import numpy as np
+from yt.utilities.exceptions import YTIntDomainOverflow
+
+from yt import load_amr_grids, ProjectionPlot
+
+def test_qt_overflow():
+    grid_data = []
+
+    grid_dict = {}
+
+    grid_dict['left_edge'] = [-1.0, -1.0, -1.0]
+    grid_dict['right_edge'] = [1.0, 1.0, 1.0]
+    grid_dict['dimensions'] = [8, 8, 8]
+    grid_dict['level'] = 0
+
+    grid_dict['density'] = np.ones((8,8,8))
+
+    grid_data.append(grid_dict)
+
+    domain_dimensions = np.array([8, 8, 8])
+
+    spf = load_amr_grids(grid_data, domain_dimensions)
+
+    def make_proj():
+        p = ProjectionPlot(spf, 'x', ["density"], center='c', origin='native')
+        return p
+    yield assert_raises, YTIntDomainOverflow, make_proj

diff -r f25f41eb4304ada81288cad3ce022e5e9214eed1 -r 1998e420f9eb51687cb44d529a2053bd6dcfd29d yt/utilities/exceptions.py
--- a/yt/utilities/exceptions.py
+++ b/yt/utilities/exceptions.py
@@ -313,6 +313,15 @@
         return "Particle bounds %s and %s exceed domain bounds %s and %s" % (
             self.mi, self.ma, self.dle, self.dre)
 
+class YTIntDomainOverflow(YTException):
+    def __init__(self, dims, dd):
+        self.dims = dims
+        self.dd = dd
+
+    def __str__(self):
+        return "Integer domain overflow: %s in %s" % (
+            self.dims, self.dd)
+
 class YTIllDefinedFilter(YTException):
     def __init__(self, filter, s1, s2):
         self.filter = filter
@@ -415,4 +424,4 @@
         self.filename = filename
 
     def __str__(self):
-        return "A file already exists at %s and clobber=False." % self.filename
\ No newline at end of file
+        return "A file already exists at %s and clobber=False." % self.filename

diff -r f25f41eb4304ada81288cad3ce022e5e9214eed1 -r 1998e420f9eb51687cb44d529a2053bd6dcfd29d yt/utilities/lib/QuadTree.pyx
--- a/yt/utilities/lib/QuadTree.pyx
+++ b/yt/utilities/lib/QuadTree.pyx
@@ -25,6 +25,8 @@
 from cython.operator cimport dereference as deref, preincrement as inc
 from fp_utils cimport fmax
 
+from yt.utilities.exceptions import YTIntDomainOverflow
+
 cdef extern from "stdlib.h":
     # NOTE that size_t might not be int
     void *alloca(int)
@@ -108,6 +110,7 @@
     cdef QTN_combine *combine
     cdef np.float64_t bounds[4]
     cdef np.float64_t dds[2]
+    cdef np.int64_t last_dims[2]
 
     def __cinit__(self, np.ndarray[np.int64_t, ndim=1] top_grid_dims,
                   int nvals, bounds, style = "integrate"):
@@ -246,13 +249,15 @@
     def get_args(self):
         return (self.top_grid_dims[0], self.top_grid_dims[1], self.nvals)
 
-    cdef void add_to_position(self,
+    cdef int add_to_position(self,
                  int level, np.int64_t pos[2],
                  np.float64_t *val,
                  np.float64_t weight_val, skip = 0):
         cdef int i, j, L
         cdef QuadTreeNode *node
         node = self.find_on_root_level(pos, level)
+        if node == NULL:
+            return -1
         cdef np.int64_t fac
         for L in range(level):
             if node.children[0][0] == NULL:
@@ -263,8 +268,9 @@
             i = (pos[0] >= fac*(2*node.pos[0]+1))
             j = (pos[1] >= fac*(2*node.pos[1]+1))
             node = node.children[i][j]
-        if skip == 1: return
+        if skip == 1: return 0
         self.combine(node, val, weight_val, self.nvals)
+        return 0
             
     @cython.cdivision(True)
     cdef QuadTreeNode *find_on_root_level(self, np.int64_t pos[2], int level):
@@ -273,8 +279,12 @@
         cdef np.int64_t i, j
         i = <np.int64_t> (pos[0] / self.po2[level])
         j = <np.int64_t> (pos[1] / self.po2[level])
+        if i > self.top_grid_dims[0] or i < 0 or \
+           j > self.top_grid_dims[1] or j < 0:
+            self.last_dims[0] = i
+            self.last_dims[1] = j
+            return NULL
         return self.root_nodes[i][j]
-        
     
     @cython.boundscheck(False)
     @cython.wraparound(False)
@@ -322,13 +332,17 @@
             np.ndarray[np.int64_t, ndim=1] pys,
             np.ndarray[np.int64_t, ndim=1] level):
         cdef int num = pxs.shape[0]
-        cdef int p
+        cdef int p, rv
         cdef cnp.float64_t *vals
         cdef cnp.int64_t pos[2]
         for p in range(num):
             pos[0] = pxs[p]
             pos[1] = pys[p]
-            self.add_to_position(level[p], pos, NULL, 0.0, 1)
+            rv = self.add_to_position(level[p], pos, NULL, 0.0, 1)
+            if rv == -1:
+                raise YTIntDomainOverflow(
+                    (self.last_dims[0], self.last_dims[1]),
+                    (self.top_grid_dims[0], self.top_grid_dims[1]))
         return
 
     @cython.boundscheck(False)

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