Commits

Matthew Turk committed 32db5f1

Considerable speedup in OWLS IO. Slight Smoothing Kernel speedup.

By reading the data from disk *before* getting the mask, we can perform the
subselection in memory, rather than creating the HDF5 H5S objects.
Additionally, we can do all three vector field components at once inside Cython
for even further speedup.

Comments (0)

Files changed (3)

yt/frontends/sph/io.py

 import numpy as np
 from yt.funcs import *
 from yt.utilities.exceptions import *
+from yt.geometry.selection_routines import particle_mask_fill
 
 from yt.utilities.io_handler import \
     BaseIOHandler
                     del coords
                     if mask is None: continue
                     for field in field_list:
-                        data = g[field][mask,...]
                         my_ind = ind[ptype, field]
-                        mylog.debug("Filling from %s to %s with %s",
-                            my_ind, my_ind+data.shape[0], field)
-                        rv[ptype, field][my_ind:my_ind + data.shape[0],...] = data
-                        ind[ptype, field] += data.shape[0]
+                        if field in _vector_fields:
+                            mylog.debug("Filling (vectors) from %s with %s",
+                                my_ind, field)
+                            data = g[field][:].astype("float64")
+                            ind[ptype, field] = particle_mask_fill(
+                                mask, data, rv[ptype, field], my_ind)
+                        else:
+                            data = g[field][:][mask]
+                            mylog.debug("Filling (scalars) from %s to %s with %s",
+                                my_ind, my_ind+data.shape[0], field)
+                            rv[ptype, field][my_ind:my_ind + data.shape[0]] = data
+                            ind[ptype, field] += data.shape[0]
                 f.close()
         return rv
 

yt/frontends/sph/smoothing_kernel.pyx

     cdef np.int64_t ngas
     cdef np.float64_t dds[3], sdds[3], pos[3], idist[3], kern
     cdef int p, i, j, k, d, ind[3], ib0[3], ib1[3], dims[3]
-    cdef int nf, half_len, skip
+    cdef int nf, half_len, skip, gi
     cdef np.float64_t dist
     cdef np.ndarray[np.float64_t, ndim=1] gas_arr
     cdef np.ndarray[np.float64_t, ndim=3] grid_arr
 
 ##############################################
 #Standard SPH kernel for use with the Grid method
-cdef float sph_kernel(float x) nogil:
-    cdef float kernel
+cdef np.float64_t sph_kernel(np.float64_t x) nogil:
+    cdef np.float64_t kernel
     if x <= 0.5:
         kernel = 1.-6.*x*x*(1.-x)
     elif x>0.5 and x<=1.0:

yt/geometry/selection_routines.pyx

     else:
         raise RuntimeError
 
+@cython.boundscheck(False)
+@cython.wraparound(False)
+@cython.cdivision(True)
+def particle_mask_fill(np.ndarray[np.uint8_t, ndim=1, cast=True] mask,
+                       np.ndarray[np.float64_t, ndim=2] input,
+                       np.ndarray[np.float64_t, ndim=2] output,
+                       np.int64_t offset):
+    cdef np.int64_t i, j
+    for i in range(mask.shape[0]):
+        if mask[i] == 0: continue
+        for j in range(3):
+            output[offset, j] = input[i, j]
+        offset += 1
+    return offset
+
 # Inclined Box
 
 cdef class SelectorObject: