Matthew Turk avatar Matthew Turk committed 2ac1017

A few more optimizations. Now dd[Something] is 30% faster than 2.x.

Comments (0)

Files changed (3)


             raise YTGeometryNotSupported(self.geometry)
-    _last_freq = None
+    _last_freq = (None, None)
     _last_finfo = None
     def _get_field_info(self, ftype, fname):
         field = (ftype, fname)
-        if field == self._last_freq:
+        if field == self._last_freq or fname == self._last_freq[1]:
             return self._last_finfo
         if field in self.field_info:
             self._last_freq = field


 from yt.utilities.io_handler import \
     BaseIOHandler, _axis_ids
 from yt.utilities.logger import ytLogger as mylog
+from yt.geometry.selection_routines import mask_fill
 import h5py
 import numpy as np
             for g in chunk.objs:
                 mask =
                 if mask is None: continue
+                nd = mask.sum()
                 for field in fields:
                     ftype, fname = field
-                    gdata = data[].pop(fname).swapaxes(0,2)[mask]
-                    rv[field][ind:ind+gdata.size] = gdata
-                ind += gdata.size
+                    gdata = data[].pop(fname).swapaxes(0,2)
+                    nd = mask_fill(rv[field], ind, mask, gdata)
+                ind += nd
         return rv


                     cpos += 1
     return indices
+def mask_fill(np.ndarray[np.float64_t, ndim=1] out,
+              np.int64_t offset,
+              np.ndarray[np.uint8_t, ndim=3, cast=True] mask,
+              np.ndarray[np.float64_t, ndim=3] vals):
+    cdef np.int64_t count = 0
+    cdef int i, j, k
+    for i in range(mask.shape[0]):
+        for j in range(mask.shape[1]):
+            for k in range(mask.shape[2]):
+                if mask[i,j,k] == 1:
+                    out[offset + count] = vals[i,j,k]
+                    count += 1
+    return count
 # Inclined Box
 cdef class SelectorObject:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.