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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Apr 5 15:43:10 PDT 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/179a73a7e7f4/
Changeset:   179a73a7e7f4
Branch:      yt
User:        ngoldbaum
Date:        2016-04-05 22:43:02+00:00
Summary:     Merged in xarthisius/yt (pull request #2109)

[opt] Precompute distances between bins in FieldInterpolationTables
Affected #:  2 files

diff -r 8445fdf5ae15434505312ef1616d910f1becb07b -r 179a73a7e7f479572d0b9039feee73f75360fd3d yt/utilities/lib/field_interpolation_tables.pxd
--- a/yt/utilities/lib/field_interpolation_tables.pxd
+++ b/yt/utilities/lib/field_interpolation_tables.pxd
@@ -16,6 +16,7 @@
 cimport cython
 cimport numpy as np
 from yt.utilities.lib.fp_utils cimport imax, fmax, imin, fmin, iclip, fclip, fabs
+from libc.stdlib cimport malloc
 
 DEF Nch = 4
 
@@ -26,6 +27,8 @@
     np.float64_t bounds[2]
     np.float64_t dbin
     np.float64_t idbin
+    np.float64_t *d0
+    np.float64_t *dy
     int field_id
     int weight_field_id
     int weight_table_id
@@ -41,12 +44,18 @@
 cdef inline void FIT_initialize_table(FieldInterpolationTable *fit, int nbins,
               np.float64_t *values, np.float64_t bounds1, np.float64_t bounds2,
               int field_id, int weight_field_id, int weight_table_id) nogil:
+    cdef int i
     fit.bounds[0] = bounds1; fit.bounds[1] = bounds2
     fit.nbins = nbins
     fit.dbin = (fit.bounds[1] - fit.bounds[0])/(fit.nbins-1)
     fit.idbin = 1.0/fit.dbin
     # Better not pull this out from under us, yo
     fit.values = values
+    fit.d0 = <np.float64_t *> malloc(sizeof(np.float64_t) * nbins)
+    fit.dy = <np.float64_t *> malloc(sizeof(np.float64_t) * nbins)
+    for i in range(nbins-1):
+        fit.d0[i] = fit.bounds[0] + i * fit.dbin
+        fit.dy[i] = (fit.values[i + 1] - fit.values[i]) * fit.idbin
     fit.field_id = field_id
     fit.weight_field_id = weight_field_id
     fit.weight_table_id = weight_table_id
@@ -56,18 +65,18 @@
 @cython.cdivision(True)
 cdef inline np.float64_t FIT_get_value(FieldInterpolationTable *fit,
                                        np.float64_t dvs[6]) nogil:
-    cdef np.float64_t bv, dy, dd
+    cdef np.float64_t dd, dout
     cdef int bin_id
     if dvs[fit.field_id] >= fit.bounds[1] or dvs[fit.field_id] <= fit.bounds[0]: return 0.0
     if not isnormal(dvs[fit.field_id]): return 0.0
     bin_id = <int> ((dvs[fit.field_id] - fit.bounds[0]) * fit.idbin)
     bin_id = iclip(bin_id, 0, fit.nbins-2)
-    dd = dvs[fit.field_id] - (fit.bounds[0] + bin_id * fit.dbin) # x - x0
-    bv = fit.values[bin_id]
-    dy = fit.values[bin_id + 1] - bv
+
+    dd = dvs[fit.field_id] - fit.d0[bin_id] # x - x0
+    dout = fit.values[bin_id] + dd * fit.dy[bin_id]
     if fit.weight_field_id != -1:
-        return dvs[fit.weight_field_id] * (bv + dd*dy*fit.idbin)
-    return (bv + dd*dy*fit.idbin)
+        dout *= dvs[fit.weight_field_id]
+    return dout 
 
 @cython.boundscheck(False)
 @cython.wraparound(False)

diff -r 8445fdf5ae15434505312ef1616d910f1becb07b -r 179a73a7e7f479572d0b9039feee73f75360fd3d yt/utilities/lib/grid_traversal.pyx
--- a/yt/utilities/lib/grid_traversal.pyx
+++ b/yt/utilities/lib/grid_traversal.pyx
@@ -844,9 +844,11 @@
             self.sampler = volume_render_stars_sampler
 
     def __dealloc__(self):
-        return
-        #free(self.vra.fits)
-        #free(self.vra)
+        for i in range(self.vra.n_fits):
+            free(self.vra.fits[i].d0)
+            free(self.vra.fits[i].dy)
+        free(self.vra.fits)
+        free(self.vra)
 
 cdef class LightSourceRenderSampler(ImageSampler):
     cdef VolumeRenderAccumulator *vra
@@ -905,11 +907,13 @@
         self.sampler = volume_render_gradient_sampler
 
     def __dealloc__(self):
-        return
-        #free(self.vra.fits)
-        #free(self.vra)
-        #free(self.light_dir)
-        #free(self.light_rgba)
+        for i in range(self.vra.n_fits):
+            free(self.vra.fits[i].d0)
+            free(self.vra.fits[i].dy)
+        free(self.vra.light_dir)
+        free(self.vra.light_rgba)
+        free(self.vra.fits)
+        free(self.vra)
 
 
 @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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-svn-spacepope.org/attachments/20160405/a1a4bfcf/attachment.htm>


More information about the yt-svn mailing list