[yt-svn] commit/yt: 13 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Jun 18 17:47:58 PDT 2014


13 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/da8137856fef/
Changeset:   da8137856fef
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-13 16:14:15
Summary:     Remove python-level domain checks, move them into compute_morton.
Affected #:  2 files

diff -r ea182fc68faeecd6c8b189da3a145811f9cb150a -r da8137856fefdfd521500e2774705dcbb5af17b9 yt/frontends/sph/io.py
--- a/yt/frontends/sph/io.py
+++ b/yt/frontends/sph/io.py
@@ -134,12 +134,6 @@
             dt = ds.dtype.newbyteorder("N") # Native
             pos = np.empty(ds.shape, dtype=dt)
             pos[:] = ds
-            if np.any(pos.min(axis=0) < self.pf.domain_left_edge) or \
-               np.any(pos.max(axis=0) > self.pf.domain_right_edge):
-                raise YTDomainOverflow(pos.min(axis=0),
-                                       pos.max(axis=0),
-                                       self.pf.domain_left_edge,
-                                       self.pf.domain_right_edge)
             regions.add_data_file(pos, data_file.file_id)
             morton[ind:ind+pos.shape[0]] = compute_morton(
                 pos[:,0], pos[:,1], pos[:,2],
@@ -322,12 +316,6 @@
             # The first total_particles * 3 values are positions
             pp = np.fromfile(f, dtype = 'float32', count = count*3)
             pp.shape = (count, 3)
-            if np.any(pp.min(axis=0) < self.pf.domain_left_edge) or \
-               np.any(pp.max(axis=0) > self.pf.domain_right_edge):
-                raise YTDomainOverflow(pp.min(axis=0),
-                                       pp.max(axis=0),
-                                       self.pf.domain_left_edge,
-                                       self.pf.domain_right_edge)
         regions.add_data_file(pp, data_file.file_id)
         morton = compute_morton(pp[:,0], pp[:,1], pp[:,2], DLE, DRE)
         return morton
@@ -614,17 +602,10 @@
                         mylog.debug("Spanning: %0.3e .. %0.3e in %s", mi, ma, ax)
                         mis[axi] = mi
                         mas[axi] = ma
-                    if np.any(mis < pf.domain_left_edge) or \
-                       np.any(mas > pf.domain_right_edge):
-                        raise YTDomainOverflow(mis, mas,
-                                               pf.domain_left_edge,
-                                               pf.domain_right_edge)
                     pos = np.empty((pp.size, 3), dtype="float64")
                     for i, ax in enumerate("xyz"):
                         eps = np.finfo(pp["Coordinates"][ax].dtype).eps
-                        pos[:,i] = np.clip(pp["Coordinates"][ax],
-                                    self.domain_left_edge[i] + eps,
-                                    self.domain_right_edge[i] - eps)
+                        pos[:,i] = pp["Coordinates"][ax]
                     regions.add_data_file(pos, data_file.file_id)
                     morton[ind:ind+c] = compute_morton(
                         pos[:,0], pos[:,1], pos[:,2],

diff -r ea182fc68faeecd6c8b189da3a145811f9cb150a -r da8137856fefdfd521500e2774705dcbb5af17b9 yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -17,8 +17,9 @@
 cimport numpy as np
 cimport cython
 from libc.stdlib cimport malloc, free
-from fp_utils cimport fclip
+from fp_utils cimport fclip, i64clip
 from libc.math cimport copysign
+from yt.utilities.exceptions import YTDomainOverflow
 
 cdef extern from "math.h":
     double exp(double x) nogil
@@ -348,25 +349,33 @@
     np.float32_t
     np.float64_t
 
-cdef position_to_morton(np.ndarray[anyfloat, ndim=1] pos_x,
+cdef np.int64_t position_to_morton(np.ndarray[anyfloat, ndim=1] pos_x,
                         np.ndarray[anyfloat, ndim=1] pos_y,
                         np.ndarray[anyfloat, ndim=1] pos_z,
                         np.float64_t dds[3], np.float64_t DLE[3],
+                        np.float64_t DRE[3],
                         np.ndarray[np.uint64_t, ndim=1] ind):
     cdef np.uint64_t mi, ii[3]
     cdef np.float64_t p[3]
     cdef np.int64_t i, j
+    cdef np.uint64_t DD[3]
+    for i in range(3):
+        DD[i] = <np.uint64_t> ((DRE[i] - DLE[i]) / dds[i])
     for i in range(pos_x.shape[0]):
         p[0] = <np.float64_t> pos_x[i]
         p[1] = <np.float64_t> pos_y[i]
         p[2] = <np.float64_t> pos_z[i]
         for j in range(3):
+            if p[j] < DLE[j] or p[j] > DRE[j]:
+                return i
             ii[j] = <np.uint64_t> ((p[j] - DLE[j])/dds[j])
+            ii[j] = i64clip(ii[j], 0, DD[j] - 1)
         mi = 0
         mi |= spread_bits(ii[2])<<0
         mi |= spread_bits(ii[1])<<1
         mi |= spread_bits(ii[0])<<2
         ind[i] = mi
+    return pos_x.shape[0]
 
 DEF ORDER_MAX=20
         
@@ -380,13 +389,21 @@
         dds[i] = (DRE[i] - DLE[i]) / (1 << ORDER_MAX)
     cdef np.ndarray[np.uint64_t, ndim=1] ind
     ind = np.zeros(pos_x.shape[0], dtype="uint64")
+    cdef np.int64_t rv
     if pos_x.dtype == np.float32:
-        position_to_morton[np.float32_t](pos_x, pos_y, pos_z, dds, DLE, ind)
+        rv = position_to_morton[np.float32_t](
+                pos_x, pos_y, pos_z, dds, DLE, DRE, ind)
     elif pos_x.dtype == np.float64:
-        position_to_morton[np.float64_t](pos_x, pos_y, pos_z, dds, DLE, ind)
+        rv = position_to_morton[np.float64_t](
+                pos_x, pos_y, pos_z, dds, DLE, DRE, ind)
     else:
         print "Could not identify dtype.", pos_x.dtype
         raise NotImplementedError
+    if rv < pos_x.shape[0]:
+        mis = (pos_x.min(), pos_y.min(), pos_z.min())
+        mas = (pos_x.max(), pos_y.max(), pos_z.max())
+        raise YTDomainOverflow(mis, mas,
+                               domain_left_edge, domain_right_edge)
     return ind
 
 @cython.boundscheck(False)


https://bitbucket.org/yt_analysis/yt/commits/59f17ca0d0e2/
Changeset:   59f17ca0d0e2
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-13 16:22:06
Summary:     We now do our own bounds checks, so we can avoid python-level checks.
Affected #:  1 file

diff -r da8137856fefdfd521500e2774705dcbb5af17b9 -r 59f17ca0d0e2e5cf30e936c3bc66c978d0c78586 yt/geometry/particle_oct_container.pyx
--- a/yt/geometry/particle_oct_container.pyx
+++ b/yt/geometry/particle_oct_container.pyx
@@ -288,6 +288,9 @@
         elif pos.dtype == np.float64:
             self._mask_positions[np.float64_t](pos, file_id)
 
+    @cython.boundscheck(False)
+    @cython.wraparound(False)
+    @cython.cdivision(True)
     cdef void _mask_positions(self, np.ndarray[anyfloat, ndim=2] pos,
                               np.uint64_t file_id):
         cdef np.int64_t no = pos.shape[0]
@@ -302,6 +305,7 @@
                 ind[i] = <int> ((pos[p, i] - self.left_edge[i])*self.idds[i])
                 ind[i] = iclip(ind[i], 0, self.dims[i])
             mask[ind[0],ind[1],ind[2]] |= val
+        return
 
     def identify_data_files(self, SelectorObject selector):
         # This is relatively cheap to iterate over.


https://bitbucket.org/yt_analysis/yt/commits/113f6e67d8a6/
Changeset:   113f6e67d8a6
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-13 16:38:53
Summary:     Adding Cython opts for morton
Affected #:  1 file

diff -r 59f17ca0d0e2e5cf30e936c3bc66c978d0c78586 -r 113f6e67d8a68b9ed4129fbe031315ea82a07a54 yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -349,6 +349,9 @@
     np.float32_t
     np.float64_t
 
+ at cython.cdivision(True)
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
 cdef np.int64_t position_to_morton(np.ndarray[anyfloat, ndim=1] pos_x,
                         np.ndarray[anyfloat, ndim=1] pos_y,
                         np.ndarray[anyfloat, ndim=1] pos_z,


https://bitbucket.org/yt_analysis/yt/commits/645f65c3c3dd/
Changeset:   645f65c3c3dd
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-14 03:54:42
Summary:     Add declarations for prefix1, prefix2.
Affected #:  1 file

diff -r 113f6e67d8a68b9ed4129fbe031315ea82a07a54 -r 645f65c3c3ddb84810b2f935bc754b77f1035a57 yt/geometry/particle_oct_container.pyx
--- a/yt/geometry/particle_oct_container.pyx
+++ b/yt/geometry/particle_oct_container.pyx
@@ -218,10 +218,12 @@
         # Now we look at the last nref particles to decide where they go.
         cdef int n = imin(p, self.n_ref)
         cdef np.uint64_t *arr = data + imax(p - self.n_ref, 0)
+        cdef np.uint64_t prefix1, prefix2
         # Now we figure out our prefix, which is the oct address at this level.
         # As long as we're actually in Morton order, we do not need to worry
         # about *any* of the other children of the oct.
         prefix1 = data[p] >> (ORDER_MAX - level)*3
+        cdef np.uint64_t prefix1, prefix2
         for i in range(n):
             prefix2 = arr[i] >> (ORDER_MAX - level)*3
             if (prefix1 == prefix2):


https://bitbucket.org/yt_analysis/yt/commits/5e10df2912fb/
Changeset:   5e10df2912fb
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-14 04:04:02
Summary:     Adding first pass at bbox filtering for particles.
Affected #:  4 files

diff -r 645f65c3c3ddb84810b2f935bc754b77f1035a57 -r 5e10df2912fbe983db769e6a8ffb362c9a081b45 yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -76,6 +76,7 @@
 class ParticleDataset(Dataset):
     _unit_base = None
     over_refine_factor = 1
+    filter_bbox = False
 
 
 class GadgetDataset(ParticleDataset):
@@ -312,8 +313,9 @@
 
         # Set standard values
         self.current_time = hvals["Time_GYR"] * sec_conversion["Gyr"]
-        self.domain_left_edge = np.zeros(3, "float64")
-        self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
+        if self.domain_left_edge is None:
+            self.domain_left_edge = np.zeros(3, "float64")
+            self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
         nz = 1 << self.over_refine_factor
         self.domain_dimensions = np.ones(3, "int32") * nz
         self.cosmological_simulation = 1

diff -r 645f65c3c3ddb84810b2f935bc754b77f1035a57 -r 5e10df2912fbe983db769e6a8ffb362c9a081b45 yt/frontends/sph/io.py
--- a/yt/frontends/sph/io.py
+++ b/yt/frontends/sph/io.py
@@ -134,11 +134,13 @@
             dt = ds.dtype.newbyteorder("N") # Native
             pos = np.empty(ds.shape, dtype=dt)
             pos[:] = ds
-            regions.add_data_file(pos, data_file.file_id)
+            regions.add_data_file(pos, data_file.file_id,
+                                  data_file.pf.filter_bbox)
             morton[ind:ind+pos.shape[0]] = compute_morton(
                 pos[:,0], pos[:,1], pos[:,2],
                 data_file.pf.domain_left_edge,
-                data_file.pf.domain_right_edge)
+                data_file.pf.domain_right_edge,
+                data_file.pf.filter_bbox)
             ind += pos.shape[0]
         f.close()
         return morton
@@ -316,8 +318,9 @@
             # The first total_particles * 3 values are positions
             pp = np.fromfile(f, dtype = 'float32', count = count*3)
             pp.shape = (count, 3)
-        regions.add_data_file(pp, data_file.file_id)
-        morton = compute_morton(pp[:,0], pp[:,1], pp[:,2], DLE, DRE)
+        regions.add_data_file(pp, data_file.file_id, data_file.pf.filter_bbox)
+        morton = compute_morton(pp[:,0], pp[:,1], pp[:,2], DLE, DRE,
+                                data_file.pf.filter_bbox)
         return morton
 
     def _count_particles(self, data_file):
@@ -606,10 +609,11 @@
                     for i, ax in enumerate("xyz"):
                         eps = np.finfo(pp["Coordinates"][ax].dtype).eps
                         pos[:,i] = pp["Coordinates"][ax]
-                    regions.add_data_file(pos, data_file.file_id)
+                    regions.add_data_file(pos, data_file.file_id,
+                                          data_file.pf.filter_bbbox)
                     morton[ind:ind+c] = compute_morton(
                         pos[:,0], pos[:,1], pos[:,2],
-                        DLE, DRE)
+                        DLE, DRE, data_file.pf.filter_bbox)
                     ind += c
         mylog.info("Adding %0.3e particles", morton.size)
         return morton
@@ -753,11 +757,13 @@
             s = self._open_stream(data_file, (ptype, "Coordinates"))
             c = np.frombuffer(s, dtype="float64")
             c.shape = (c.shape[0]/3.0, 3)
-            regions.add_data_file(c, data_file.file_id)
+            regions.add_data_file(c, data_file.file_id,
+                                  data_file.pf.filter_bbox)
             morton[ind:ind+c.shape[0]] = compute_morton(
                 c[:,0], c[:,1], c[:,2],
                 data_file.pf.domain_left_edge,
-                data_file.pf.domain_right_edge)
+                data_file.pf.domain_right_edge,
+                data_filter.pf.filter_bbox)
             ind += c.shape[0]
         return morton
 

diff -r 645f65c3c3ddb84810b2f935bc754b77f1035a57 -r 5e10df2912fbe983db769e6a8ffb362c9a081b45 yt/geometry/particle_oct_container.pyx
--- a/yt/geometry/particle_oct_container.pyx
+++ b/yt/geometry/particle_oct_container.pyx
@@ -170,6 +170,10 @@
             # looking at (MAX_ORDER - level) & with the values 1, 2, 4.
             level = 0
             index = indices[p]
+            if index == -1:
+                # This is a marker for the index not being inside the domain
+                # we're interested in.
+                continue
             for i in range(3):
                 ind[i] = (index >> ((ORDER_MAX - level)*3 + (2 - i))) & 1
             cur = self.root_mesh[ind[0]][ind[1]][ind[2]]
@@ -223,7 +227,6 @@
         # As long as we're actually in Morton order, we do not need to worry
         # about *any* of the other children of the oct.
         prefix1 = data[p] >> (ORDER_MAX - level)*3
-        cdef np.uint64_t prefix1, prefix2
         for i in range(n):
             prefix2 = arr[i] >> (ORDER_MAX - level)*3
             if (prefix1 == prefix2):
@@ -265,6 +268,7 @@
 
 cdef class ParticleRegions:
     cdef np.float64_t left_edge[3]
+    cdef np.float64_t right_edge[3]
     cdef np.float64_t dds[3]
     cdef np.float64_t idds[3]
     cdef np.int32_t dims[3]
@@ -276,6 +280,7 @@
         self.nfiles = nfiles
         for i in range(3):
             self.left_edge[i] = left_edge[i]
+            self.right_edge[i] = right_edge[i]
             self.dims[i] = dims[i]
             self.dds[i] = (right_edge[i] - left_edge[i])/dims[i]
             self.idds[i] = 1.0/self.dds[i]
@@ -284,29 +289,35 @@
         for i in range(nfiles/64 + 1):
             self.masks.append(np.zeros(dims, dtype="uint64"))
 
-    def add_data_file(self, np.ndarray pos, int file_id):
+    def add_data_file(self, np.ndarray pos, int file_id, int filter):
         if pos.dtype == np.float32:
-            self._mask_positions[np.float32_t](pos, file_id)
+            self._mask_positions[np.float32_t](pos, file_id, filter)
         elif pos.dtype == np.float64:
-            self._mask_positions[np.float64_t](pos, file_id)
+            self._mask_positions[np.float64_t](pos, file_id, filter)
 
     @cython.boundscheck(False)
     @cython.wraparound(False)
     @cython.cdivision(True)
     cdef void _mask_positions(self, np.ndarray[anyfloat, ndim=2] pos,
-                              np.uint64_t file_id):
+                              np.uint64_t file_id, int filter):
         cdef np.int64_t no = pos.shape[0]
         cdef np.int64_t p
-        cdef int ind[3], i
+        cdef int ind[3], i, use
         cdef np.ndarray[np.uint64_t, ndim=3] mask
         mask = self.masks[file_id/64]
         cdef np.uint64_t val = ONEBIT << (file_id - (file_id/64)*64)
         for p in range(no):
             # Now we locate the particle
+            use = 1
             for i in range(3):
+                if filter and (pos[p,i] < self.left_edge[i]
+                            or pos[p,i] > self.right_edge[i]):
+                    use = 0
+                    break
                 ind[i] = <int> ((pos[p, i] - self.left_edge[i])*self.idds[i])
                 ind[i] = iclip(ind[i], 0, self.dims[i])
-            mask[ind[0],ind[1],ind[2]] |= val
+            if use == 1:
+                mask[ind[0],ind[1],ind[2]] |= val
         return
 
     def identify_data_files(self, SelectorObject selector):

diff -r 645f65c3c3ddb84810b2f935bc754b77f1035a57 -r 5e10df2912fbe983db769e6a8ffb362c9a081b45 yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -357,7 +357,8 @@
                         np.ndarray[anyfloat, ndim=1] pos_z,
                         np.float64_t dds[3], np.float64_t DLE[3],
                         np.float64_t DRE[3],
-                        np.ndarray[np.uint64_t, ndim=1] ind):
+                        np.ndarray[np.uint64_t, ndim=1] ind,
+                        int filter):
     cdef np.uint64_t mi, ii[3]
     cdef np.float64_t p[3]
     cdef np.int64_t i, j
@@ -370,6 +371,10 @@
         p[2] = <np.float64_t> pos_z[i]
         for j in range(3):
             if p[j] < DLE[j] or p[j] > DRE[j]:
+                if filter == 1:
+                    # We only allow 20 levels, so this is inaccessible
+                    ind[i] = -1 
+                    continue
                 return i
             ii[j] = <np.uint64_t> ((p[j] - DLE[j])/dds[j])
             ii[j] = i64clip(ii[j], 0, DD[j] - 1)
@@ -383,8 +388,13 @@
 DEF ORDER_MAX=20
         
 def compute_morton(np.ndarray pos_x, np.ndarray pos_y, np.ndarray pos_z,
-                   domain_left_edge, domain_right_edge):
+                   domain_left_edge, domain_right_edge, filter_bbox):
     cdef int i
+    cdef int filter
+    if filter_bbox:
+        filter = 1
+    else:
+        filter = 0
     cdef np.float64_t dds[3], DLE[3], DRE[3]
     for i in range(3):
         DLE[i] = domain_left_edge[i]
@@ -395,10 +405,12 @@
     cdef np.int64_t rv
     if pos_x.dtype == np.float32:
         rv = position_to_morton[np.float32_t](
-                pos_x, pos_y, pos_z, dds, DLE, DRE, ind)
+                pos_x, pos_y, pos_z, dds, DLE, DRE, ind,
+                filter)
     elif pos_x.dtype == np.float64:
         rv = position_to_morton[np.float64_t](
-                pos_x, pos_y, pos_z, dds, DLE, DRE, ind)
+                pos_x, pos_y, pos_z, dds, DLE, DRE, ind,
+                filter)
     else:
         print "Could not identify dtype.", pos_x.dtype
         raise NotImplementedError


https://bitbucket.org/yt_analysis/yt/commits/f359167a8fc0/
Changeset:   f359167a8fc0
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-14 20:03:29
Summary:     More clearly skip some morton indices.
Affected #:  2 files

diff -r 5e10df2912fbe983db769e6a8ffb362c9a081b45 -r f359167a8fc08f68b6cb4008155cd7cbf22213ac yt/geometry/particle_oct_container.pyx
--- a/yt/geometry/particle_oct_container.pyx
+++ b/yt/geometry/particle_oct_container.pyx
@@ -165,12 +165,13 @@
         cdef int i, level, ind[3]
         if self.root_mesh[0][0][0] == NULL: self.allocate_root()
         cdef np.uint64_t *data = <np.uint64_t *> indices.data
+        cdef np.uint64_t FLAG = ~(<np.uint64_t>0)
         for p in range(no):
             # We have morton indices, which means we choose left and right by
             # looking at (MAX_ORDER - level) & with the values 1, 2, 4.
             level = 0
             index = indices[p]
-            if index == -1:
+            if index == FLAG:
                 # This is a marker for the index not being inside the domain
                 # we're interested in.
                 continue

diff -r 5e10df2912fbe983db769e6a8ffb362c9a081b45 -r f359167a8fc08f68b6cb4008155cd7cbf22213ac yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -361,11 +361,13 @@
                         int filter):
     cdef np.uint64_t mi, ii[3]
     cdef np.float64_t p[3]
-    cdef np.int64_t i, j
+    cdef np.int64_t i, j, use
     cdef np.uint64_t DD[3]
+    cdef np.uint64_t FLAG = ~(<np.uint64_t>0)
     for i in range(3):
         DD[i] = <np.uint64_t> ((DRE[i] - DLE[i]) / dds[i])
     for i in range(pos_x.shape[0]):
+        use = 1
         p[0] = <np.float64_t> pos_x[i]
         p[1] = <np.float64_t> pos_y[i]
         p[2] = <np.float64_t> pos_z[i]
@@ -373,11 +375,14 @@
             if p[j] < DLE[j] or p[j] > DRE[j]:
                 if filter == 1:
                     # We only allow 20 levels, so this is inaccessible
-                    ind[i] = -1 
-                    continue
+                    use = 0
+                    break
                 return i
             ii[j] = <np.uint64_t> ((p[j] - DLE[j])/dds[j])
             ii[j] = i64clip(ii[j], 0, DD[j] - 1)
+        if use == 0: 
+            ind[i] = FLAG
+            continue
         mi = 0
         mi |= spread_bits(ii[2])<<0
         mi |= spread_bits(ii[1])<<1


https://bitbucket.org/yt_analysis/yt/commits/6bca5315d2a5/
Changeset:   6bca5315d2a5
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-14 22:33:23
Summary:     Merged
Affected #:  1 file

diff -r f359167a8fc08f68b6cb4008155cd7cbf22213ac -r 6bca5315d2a560afb16335c2e9863d348edbe8cb yt/data_objects/octree_subset.py
--- a/yt/data_objects/octree_subset.py
+++ b/yt/data_objects/octree_subset.py
@@ -102,10 +102,11 @@
             new_shape = (nz, nz, nz, n_oct, 3)
         else:
             raise RuntimeError
-        # This will retain units now.
-        arr.shape = new_shape
-        if not arr.flags["F_CONTIGUOUS"]:
-            arr = arr.reshape(new_shape, order="F")
+        # Note that if arr is already F-contiguous, this *shouldn't* copy the
+        # data.  But, it might.  However, I can't seem to figure out how to
+        # make the assignment to .shape, which *won't* copy the data, make the
+        # resultant array viewed in Fortran order.
+        arr = arr.reshape(new_shape, order="F")
         return arr
 
     _domain_ind = None


https://bitbucket.org/yt_analysis/yt/commits/845e74427bdb/
Changeset:   845e74427bdb
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-14 23:09:18
Summary:     Make regions not modify in place, and fix their right_shift in non-periodic
domains.
Affected #:  1 file

diff -r 6bca5315d2a560afb16335c2e9863d348edbe8cb -r 845e74427bdb73274b3c2b6ebc1770f0399c9db1 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -625,6 +625,8 @@
         for i in range(3):
             region_width = dobj.right_edge[i] - dobj.left_edge[i]
             domain_width = DW[i]
+            dleft_edge = dobj.left_edge[i]
+            dright_edge = dobj.right_edge[i]
 
             if region_width <= 0:
                 raise RuntimeError(
@@ -633,27 +635,31 @@
 
             if dobj.pf.periodicity[i]:
                 # shift so left_edge guaranteed in domain
-                if dobj.left_edge[i] < dobj.pf.domain_left_edge[i]:
-                    dobj.left_edge[i] += domain_width
-                    dobj.right_edge[i] += domain_width
-                elif dobj.left_edge[i] > dobj.pf.domain_right_edge[i]:
-                    dobj.left_edge[i] += domain_width
-                    dobj.right_edge[i] += domain_width
+                if dleft_edge < dobj.pf.domain_left_edge[i]:
+                    dleft_edge += domain_width
+                    dright_edge += domain_width
+                elif dleft_edge > dobj.pf.domain_right_edge[i]:
+                    dleft_edge += domain_width
+                    dright_edge += domain_width
             else:
-                if dobj.left_edge[i] < dobj.pf.domain_left_edge[i] or \
-                   dobj.right_edge[i] > dobj.pf.domain_right_edge[i]:
+                if dleft_edge < dobj.pf.domain_left_edge[i] or \
+                   dright_edge > dobj.pf.domain_right_edge[i]:
                     raise RuntimeError(
                         "Error: bad Region in non-periodic domain along dimension %s. "
                         "Region left edge = %s, Region right edge = %s"
                         "Dataset left edge = %s, Dataset right edge = %s" % \
-                        (i, dobj.left_edge[i], dobj.right_edge[i],
+                        (i, dleft_edge, dright_edge,
                          dobj.pf.domain_left_edge[i], dobj.pf.domain_right_edge[i])
                     )
             # Already ensured in code
-            self.left_edge[i] = dobj.left_edge[i]
-            self.right_edge[i] = dobj.right_edge[i]
-            self.right_edge_shift[i] = \
-                (dobj.right_edge).to_ndarray()[i] - domain_width.to_ndarray()
+            self.left_edge[i] = dleft_edge
+            self.right_edge[i] = dright_edge
+            if not self.periodicity[i]:
+                self.right_edge_shift[i] = -np.inf
+            else:
+                self.right_edge_shift[i] = \
+                    ((dobj.right_edge).to_ndarray()[i] 
+                    - domain_width.to_ndarray())
 
     @cython.boundscheck(False)
     @cython.wraparound(False)


https://bitbucket.org/yt_analysis/yt/commits/c4a74635333f/
Changeset:   c4a74635333f
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-15 04:23:23
Summary:     Indexed octrees need to filter DLE/DRE.
Affected #:  1 file

diff -r 845e74427bdb73274b3c2b6ebc1770f0399c9db1 -r c4a74635333f4be24f8f2c180e8a66a2e8e9f101 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -1528,6 +1528,9 @@
     cdef np.uint64_t min_ind
     cdef np.uint64_t max_ind
     cdef SelectorObject base_selector
+    cdef int filter_bbox
+    cdef np.float64_t DLE[3]
+    cdef np.float64_t DRE[3]
 
     def __init__(self, dobj):
         self.min_ind = dobj.min_ind
@@ -1535,6 +1538,12 @@
         self.base_selector = dobj.base_selector
         self.min_level = self.base_selector.min_level
         self.max_level = self.base_selector.max_level
+        self.filter_bbox = 0
+        if getattr(dobj.pf, "filter_bbox", False):
+            self.filter_bbox = 1
+        for i in range(3):
+            self.DLE[i] = dobj.pf.domain_left_edge[i]
+            self.DRE[i] = dobj.pf.domain_right_edge[i]
 
     @cython.boundscheck(False)
     @cython.wraparound(False)
@@ -1561,6 +1570,12 @@
     @cython.wraparound(False)
     @cython.cdivision(True)
     cdef int select_point(self, np.float64_t pos[3]) nogil:
+        cdef int i
+        if self.filter_bbox == 0:
+            return 1
+        for i in range(3):
+            if pos[i] < self.DLE[i] or pos[i] > self.DRE[i]:
+                return 0
         return 1
 
     @cython.boundscheck(False)


https://bitbucket.org/yt_analysis/yt/commits/ef602935b52e/
Changeset:   ef602935b52e
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-16 17:49:59
Summary:     Backing out 845e74427bdb
Affected #:  1 file

diff -r c4a74635333f4be24f8f2c180e8a66a2e8e9f101 -r ef602935b52e3e984a333318cb774b6a76ef8500 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -625,8 +625,6 @@
         for i in range(3):
             region_width = dobj.right_edge[i] - dobj.left_edge[i]
             domain_width = DW[i]
-            dleft_edge = dobj.left_edge[i]
-            dright_edge = dobj.right_edge[i]
 
             if region_width <= 0:
                 raise RuntimeError(
@@ -635,31 +633,27 @@
 
             if dobj.pf.periodicity[i]:
                 # shift so left_edge guaranteed in domain
-                if dleft_edge < dobj.pf.domain_left_edge[i]:
-                    dleft_edge += domain_width
-                    dright_edge += domain_width
-                elif dleft_edge > dobj.pf.domain_right_edge[i]:
-                    dleft_edge += domain_width
-                    dright_edge += domain_width
+                if dobj.left_edge[i] < dobj.pf.domain_left_edge[i]:
+                    dobj.left_edge[i] += domain_width
+                    dobj.right_edge[i] += domain_width
+                elif dobj.left_edge[i] > dobj.pf.domain_right_edge[i]:
+                    dobj.left_edge[i] += domain_width
+                    dobj.right_edge[i] += domain_width
             else:
-                if dleft_edge < dobj.pf.domain_left_edge[i] or \
-                   dright_edge > dobj.pf.domain_right_edge[i]:
+                if dobj.left_edge[i] < dobj.pf.domain_left_edge[i] or \
+                   dobj.right_edge[i] > dobj.pf.domain_right_edge[i]:
                     raise RuntimeError(
                         "Error: bad Region in non-periodic domain along dimension %s. "
                         "Region left edge = %s, Region right edge = %s"
                         "Dataset left edge = %s, Dataset right edge = %s" % \
-                        (i, dleft_edge, dright_edge,
+                        (i, dobj.left_edge[i], dobj.right_edge[i],
                          dobj.pf.domain_left_edge[i], dobj.pf.domain_right_edge[i])
                     )
             # Already ensured in code
-            self.left_edge[i] = dleft_edge
-            self.right_edge[i] = dright_edge
-            if not self.periodicity[i]:
-                self.right_edge_shift[i] = -np.inf
-            else:
-                self.right_edge_shift[i] = \
-                    ((dobj.right_edge).to_ndarray()[i] 
-                    - domain_width.to_ndarray())
+            self.left_edge[i] = dobj.left_edge[i]
+            self.right_edge[i] = dobj.right_edge[i]
+            self.right_edge_shift[i] = \
+                (dobj.right_edge).to_ndarray()[i] - domain_width.to_ndarray()
 
     @cython.boundscheck(False)
     @cython.wraparound(False)


https://bitbucket.org/yt_analysis/yt/commits/4846d94bb451/
Changeset:   4846d94bb451
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-16 17:52:21
Summary:     Turn off right_edge_shift for non-periodict domains.
Affected #:  1 file

diff -r ef602935b52e3e984a333318cb774b6a76ef8500 -r 4846d94bb451a131d6a1124e2671b36b281d8de7 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -654,6 +654,8 @@
             self.right_edge[i] = dobj.right_edge[i]
             self.right_edge_shift[i] = \
                 (dobj.right_edge).to_ndarray()[i] - domain_width.to_ndarray()
+            if not self.periodicity[i]:
+                self.right_edge_shift[i] = -np.inf
 
     @cython.boundscheck(False)
     @cython.wraparound(False)


https://bitbucket.org/yt_analysis/yt/commits/c7782d391d4f/
Changeset:   c7782d391d4f
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-16 18:58:41
Summary:     Adding default arguments.
Affected #:  2 files

diff -r 4846d94bb451a131d6a1124e2671b36b281d8de7 -r c7782d391d4f2ab96bcc8cdb3a2ee0ab4e6bf5d8 yt/geometry/particle_oct_container.pyx
--- a/yt/geometry/particle_oct_container.pyx
+++ b/yt/geometry/particle_oct_container.pyx
@@ -290,7 +290,7 @@
         for i in range(nfiles/64 + 1):
             self.masks.append(np.zeros(dims, dtype="uint64"))
 
-    def add_data_file(self, np.ndarray pos, int file_id, int filter):
+    def add_data_file(self, np.ndarray pos, int file_id, int filter = 0):
         if pos.dtype == np.float32:
             self._mask_positions[np.float32_t](pos, file_id, filter)
         elif pos.dtype == np.float64:

diff -r 4846d94bb451a131d6a1124e2671b36b281d8de7 -r c7782d391d4f2ab96bcc8cdb3a2ee0ab4e6bf5d8 yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -393,7 +393,7 @@
 DEF ORDER_MAX=20
         
 def compute_morton(np.ndarray pos_x, np.ndarray pos_y, np.ndarray pos_z,
-                   domain_left_edge, domain_right_edge, filter_bbox):
+                   domain_left_edge, domain_right_edge, filter_bbox = False):
     cdef int i
     cdef int filter
     if filter_bbox:


https://bitbucket.org/yt_analysis/yt/commits/c6e1bd5989e2/
Changeset:   c6e1bd5989e2
Branch:      yt-3.0
User:        MatthewTurk
Date:        2014-06-19 02:47:51
Summary:     Merged in MatthewTurk/yt/yt-3.0 (pull request #949)

Some speedups for particle octree instantiations
Affected #:  5 files

diff -r 1d4b798712da4baa056d633ee73bd6b6b7e89cc1 -r c6e1bd5989e247913d02bb4cb767f55855f9ceb9 yt/frontends/sph/data_structures.py
--- a/yt/frontends/sph/data_structures.py
+++ b/yt/frontends/sph/data_structures.py
@@ -76,6 +76,7 @@
 class ParticleDataset(Dataset):
     _unit_base = None
     over_refine_factor = 1
+    filter_bbox = False
 
 
 class GadgetDataset(ParticleDataset):
@@ -312,8 +313,9 @@
 
         # Set standard values
         self.current_time = hvals["Time_GYR"] * sec_conversion["Gyr"]
-        self.domain_left_edge = np.zeros(3, "float64")
-        self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
+        if self.domain_left_edge is None:
+            self.domain_left_edge = np.zeros(3, "float64")
+            self.domain_right_edge = np.ones(3, "float64") * hvals["BoxSize"]
         nz = 1 << self.over_refine_factor
         self.domain_dimensions = np.ones(3, "int32") * nz
         self.cosmological_simulation = 1

diff -r 1d4b798712da4baa056d633ee73bd6b6b7e89cc1 -r c6e1bd5989e247913d02bb4cb767f55855f9ceb9 yt/frontends/sph/io.py
--- a/yt/frontends/sph/io.py
+++ b/yt/frontends/sph/io.py
@@ -134,17 +134,13 @@
             dt = ds.dtype.newbyteorder("N") # Native
             pos = np.empty(ds.shape, dtype=dt)
             pos[:] = ds
-            if np.any(pos.min(axis=0) < self.pf.domain_left_edge) or \
-               np.any(pos.max(axis=0) > self.pf.domain_right_edge):
-                raise YTDomainOverflow(pos.min(axis=0),
-                                       pos.max(axis=0),
-                                       self.pf.domain_left_edge,
-                                       self.pf.domain_right_edge)
-            regions.add_data_file(pos, data_file.file_id)
+            regions.add_data_file(pos, data_file.file_id,
+                                  data_file.pf.filter_bbox)
             morton[ind:ind+pos.shape[0]] = compute_morton(
                 pos[:,0], pos[:,1], pos[:,2],
                 data_file.pf.domain_left_edge,
-                data_file.pf.domain_right_edge)
+                data_file.pf.domain_right_edge,
+                data_file.pf.filter_bbox)
             ind += pos.shape[0]
         f.close()
         return morton
@@ -322,14 +318,9 @@
             # The first total_particles * 3 values are positions
             pp = np.fromfile(f, dtype = 'float32', count = count*3)
             pp.shape = (count, 3)
-            if np.any(pp.min(axis=0) < self.pf.domain_left_edge) or \
-               np.any(pp.max(axis=0) > self.pf.domain_right_edge):
-                raise YTDomainOverflow(pp.min(axis=0),
-                                       pp.max(axis=0),
-                                       self.pf.domain_left_edge,
-                                       self.pf.domain_right_edge)
-        regions.add_data_file(pp, data_file.file_id)
-        morton = compute_morton(pp[:,0], pp[:,1], pp[:,2], DLE, DRE)
+        regions.add_data_file(pp, data_file.file_id, data_file.pf.filter_bbox)
+        morton = compute_morton(pp[:,0], pp[:,1], pp[:,2], DLE, DRE,
+                                data_file.pf.filter_bbox)
         return morton
 
     def _count_particles(self, data_file):
@@ -614,21 +605,15 @@
                         mylog.debug("Spanning: %0.3e .. %0.3e in %s", mi, ma, ax)
                         mis[axi] = mi
                         mas[axi] = ma
-                    if np.any(mis < pf.domain_left_edge) or \
-                       np.any(mas > pf.domain_right_edge):
-                        raise YTDomainOverflow(mis, mas,
-                                               pf.domain_left_edge,
-                                               pf.domain_right_edge)
                     pos = np.empty((pp.size, 3), dtype="float64")
                     for i, ax in enumerate("xyz"):
                         eps = np.finfo(pp["Coordinates"][ax].dtype).eps
-                        pos[:,i] = np.clip(pp["Coordinates"][ax],
-                                    self.domain_left_edge[i] + eps,
-                                    self.domain_right_edge[i] - eps)
-                    regions.add_data_file(pos, data_file.file_id)
+                        pos[:,i] = pp["Coordinates"][ax]
+                    regions.add_data_file(pos, data_file.file_id,
+                                          data_file.pf.filter_bbbox)
                     morton[ind:ind+c] = compute_morton(
                         pos[:,0], pos[:,1], pos[:,2],
-                        DLE, DRE)
+                        DLE, DRE, data_file.pf.filter_bbox)
                     ind += c
         mylog.info("Adding %0.3e particles", morton.size)
         return morton
@@ -772,11 +757,13 @@
             s = self._open_stream(data_file, (ptype, "Coordinates"))
             c = np.frombuffer(s, dtype="float64")
             c.shape = (c.shape[0]/3.0, 3)
-            regions.add_data_file(c, data_file.file_id)
+            regions.add_data_file(c, data_file.file_id,
+                                  data_file.pf.filter_bbox)
             morton[ind:ind+c.shape[0]] = compute_morton(
                 c[:,0], c[:,1], c[:,2],
                 data_file.pf.domain_left_edge,
-                data_file.pf.domain_right_edge)
+                data_file.pf.domain_right_edge,
+                data_filter.pf.filter_bbox)
             ind += c.shape[0]
         return morton
 

diff -r 1d4b798712da4baa056d633ee73bd6b6b7e89cc1 -r c6e1bd5989e247913d02bb4cb767f55855f9ceb9 yt/geometry/particle_oct_container.pyx
--- a/yt/geometry/particle_oct_container.pyx
+++ b/yt/geometry/particle_oct_container.pyx
@@ -165,11 +165,16 @@
         cdef int i, level, ind[3]
         if self.root_mesh[0][0][0] == NULL: self.allocate_root()
         cdef np.uint64_t *data = <np.uint64_t *> indices.data
+        cdef np.uint64_t FLAG = ~(<np.uint64_t>0)
         for p in range(no):
             # We have morton indices, which means we choose left and right by
             # looking at (MAX_ORDER - level) & with the values 1, 2, 4.
             level = 0
             index = indices[p]
+            if index == FLAG:
+                # This is a marker for the index not being inside the domain
+                # we're interested in.
+                continue
             for i in range(3):
                 ind[i] = (index >> ((ORDER_MAX - level)*3 + (2 - i))) & 1
             cur = self.root_mesh[ind[0]][ind[1]][ind[2]]
@@ -218,6 +223,7 @@
         # Now we look at the last nref particles to decide where they go.
         cdef int n = imin(p, self.n_ref)
         cdef np.uint64_t *arr = data + imax(p - self.n_ref, 0)
+        cdef np.uint64_t prefix1, prefix2
         # Now we figure out our prefix, which is the oct address at this level.
         # As long as we're actually in Morton order, we do not need to worry
         # about *any* of the other children of the oct.
@@ -263,6 +269,7 @@
 
 cdef class ParticleRegions:
     cdef np.float64_t left_edge[3]
+    cdef np.float64_t right_edge[3]
     cdef np.float64_t dds[3]
     cdef np.float64_t idds[3]
     cdef np.int32_t dims[3]
@@ -274,6 +281,7 @@
         self.nfiles = nfiles
         for i in range(3):
             self.left_edge[i] = left_edge[i]
+            self.right_edge[i] = right_edge[i]
             self.dims[i] = dims[i]
             self.dds[i] = (right_edge[i] - left_edge[i])/dims[i]
             self.idds[i] = 1.0/self.dds[i]
@@ -282,26 +290,36 @@
         for i in range(nfiles/64 + 1):
             self.masks.append(np.zeros(dims, dtype="uint64"))
 
-    def add_data_file(self, np.ndarray pos, int file_id):
+    def add_data_file(self, np.ndarray pos, int file_id, int filter = 0):
         if pos.dtype == np.float32:
-            self._mask_positions[np.float32_t](pos, file_id)
+            self._mask_positions[np.float32_t](pos, file_id, filter)
         elif pos.dtype == np.float64:
-            self._mask_positions[np.float64_t](pos, file_id)
+            self._mask_positions[np.float64_t](pos, file_id, filter)
 
+    @cython.boundscheck(False)
+    @cython.wraparound(False)
+    @cython.cdivision(True)
     cdef void _mask_positions(self, np.ndarray[anyfloat, ndim=2] pos,
-                              np.uint64_t file_id):
+                              np.uint64_t file_id, int filter):
         cdef np.int64_t no = pos.shape[0]
         cdef np.int64_t p
-        cdef int ind[3], i
+        cdef int ind[3], i, use
         cdef np.ndarray[np.uint64_t, ndim=3] mask
         mask = self.masks[file_id/64]
         cdef np.uint64_t val = ONEBIT << (file_id - (file_id/64)*64)
         for p in range(no):
             # Now we locate the particle
+            use = 1
             for i in range(3):
+                if filter and (pos[p,i] < self.left_edge[i]
+                            or pos[p,i] > self.right_edge[i]):
+                    use = 0
+                    break
                 ind[i] = <int> ((pos[p, i] - self.left_edge[i])*self.idds[i])
                 ind[i] = iclip(ind[i], 0, self.dims[i])
-            mask[ind[0],ind[1],ind[2]] |= val
+            if use == 1:
+                mask[ind[0],ind[1],ind[2]] |= val
+        return
 
     def identify_data_files(self, SelectorObject selector):
         # This is relatively cheap to iterate over.

diff -r 1d4b798712da4baa056d633ee73bd6b6b7e89cc1 -r c6e1bd5989e247913d02bb4cb767f55855f9ceb9 yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -654,6 +654,8 @@
             self.right_edge[i] = dobj.right_edge[i]
             self.right_edge_shift[i] = \
                 (dobj.right_edge).to_ndarray()[i] - domain_width.to_ndarray()
+            if not self.periodicity[i]:
+                self.right_edge_shift[i] = -np.inf
 
     @cython.boundscheck(False)
     @cython.wraparound(False)
@@ -1522,6 +1524,9 @@
     cdef np.uint64_t min_ind
     cdef np.uint64_t max_ind
     cdef SelectorObject base_selector
+    cdef int filter_bbox
+    cdef np.float64_t DLE[3]
+    cdef np.float64_t DRE[3]
 
     def __init__(self, dobj):
         self.min_ind = dobj.min_ind
@@ -1529,6 +1534,12 @@
         self.base_selector = dobj.base_selector
         self.min_level = self.base_selector.min_level
         self.max_level = self.base_selector.max_level
+        self.filter_bbox = 0
+        if getattr(dobj.pf, "filter_bbox", False):
+            self.filter_bbox = 1
+        for i in range(3):
+            self.DLE[i] = dobj.pf.domain_left_edge[i]
+            self.DRE[i] = dobj.pf.domain_right_edge[i]
 
     @cython.boundscheck(False)
     @cython.wraparound(False)
@@ -1555,6 +1566,12 @@
     @cython.wraparound(False)
     @cython.cdivision(True)
     cdef int select_point(self, np.float64_t pos[3]) nogil:
+        cdef int i
+        if self.filter_bbox == 0:
+            return 1
+        for i in range(3):
+            if pos[i] < self.DLE[i] or pos[i] > self.DRE[i]:
+                return 0
         return 1
 
     @cython.boundscheck(False)

diff -r 1d4b798712da4baa056d633ee73bd6b6b7e89cc1 -r c6e1bd5989e247913d02bb4cb767f55855f9ceb9 yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -17,8 +17,9 @@
 cimport numpy as np
 cimport cython
 from libc.stdlib cimport malloc, free
-from fp_utils cimport fclip
+from fp_utils cimport fclip, i64clip
 from libc.math cimport copysign
+from yt.utilities.exceptions import YTDomainOverflow
 
 cdef extern from "math.h":
     double exp(double x) nogil
@@ -348,31 +349,57 @@
     np.float32_t
     np.float64_t
 
-cdef position_to_morton(np.ndarray[anyfloat, ndim=1] pos_x,
+ at cython.cdivision(True)
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+cdef np.int64_t position_to_morton(np.ndarray[anyfloat, ndim=1] pos_x,
                         np.ndarray[anyfloat, ndim=1] pos_y,
                         np.ndarray[anyfloat, ndim=1] pos_z,
                         np.float64_t dds[3], np.float64_t DLE[3],
-                        np.ndarray[np.uint64_t, ndim=1] ind):
+                        np.float64_t DRE[3],
+                        np.ndarray[np.uint64_t, ndim=1] ind,
+                        int filter):
     cdef np.uint64_t mi, ii[3]
     cdef np.float64_t p[3]
-    cdef np.int64_t i, j
+    cdef np.int64_t i, j, use
+    cdef np.uint64_t DD[3]
+    cdef np.uint64_t FLAG = ~(<np.uint64_t>0)
+    for i in range(3):
+        DD[i] = <np.uint64_t> ((DRE[i] - DLE[i]) / dds[i])
     for i in range(pos_x.shape[0]):
+        use = 1
         p[0] = <np.float64_t> pos_x[i]
         p[1] = <np.float64_t> pos_y[i]
         p[2] = <np.float64_t> pos_z[i]
         for j in range(3):
+            if p[j] < DLE[j] or p[j] > DRE[j]:
+                if filter == 1:
+                    # We only allow 20 levels, so this is inaccessible
+                    use = 0
+                    break
+                return i
             ii[j] = <np.uint64_t> ((p[j] - DLE[j])/dds[j])
+            ii[j] = i64clip(ii[j], 0, DD[j] - 1)
+        if use == 0: 
+            ind[i] = FLAG
+            continue
         mi = 0
         mi |= spread_bits(ii[2])<<0
         mi |= spread_bits(ii[1])<<1
         mi |= spread_bits(ii[0])<<2
         ind[i] = mi
+    return pos_x.shape[0]
 
 DEF ORDER_MAX=20
         
 def compute_morton(np.ndarray pos_x, np.ndarray pos_y, np.ndarray pos_z,
-                   domain_left_edge, domain_right_edge):
+                   domain_left_edge, domain_right_edge, filter_bbox = False):
     cdef int i
+    cdef int filter
+    if filter_bbox:
+        filter = 1
+    else:
+        filter = 0
     cdef np.float64_t dds[3], DLE[3], DRE[3]
     for i in range(3):
         DLE[i] = domain_left_edge[i]
@@ -380,13 +407,23 @@
         dds[i] = (DRE[i] - DLE[i]) / (1 << ORDER_MAX)
     cdef np.ndarray[np.uint64_t, ndim=1] ind
     ind = np.zeros(pos_x.shape[0], dtype="uint64")
+    cdef np.int64_t rv
     if pos_x.dtype == np.float32:
-        position_to_morton[np.float32_t](pos_x, pos_y, pos_z, dds, DLE, ind)
+        rv = position_to_morton[np.float32_t](
+                pos_x, pos_y, pos_z, dds, DLE, DRE, ind,
+                filter)
     elif pos_x.dtype == np.float64:
-        position_to_morton[np.float64_t](pos_x, pos_y, pos_z, dds, DLE, ind)
+        rv = position_to_morton[np.float64_t](
+                pos_x, pos_y, pos_z, dds, DLE, DRE, ind,
+                filter)
     else:
         print "Could not identify dtype.", pos_x.dtype
         raise NotImplementedError
+    if rv < pos_x.shape[0]:
+        mis = (pos_x.min(), pos_y.min(), pos_z.min())
+        mas = (pos_x.max(), pos_y.max(), pos_z.max())
+        raise YTDomainOverflow(mis, mas,
+                               domain_left_edge, domain_right_edge)
     return ind
 
 @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