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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Apr 6 11:25:58 PDT 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/47bf935396cb/
Changeset:   47bf935396cb
Branch:      yt
User:        ngoldbaum
Date:        2016-04-06 18:25:44+00:00
Summary:     Merged in atmyers/yt (pull request #2091)

Use Cython fused types to avoid duplicating functions for float and double.
Affected #:  3 files

diff -r 0157f4cbca3c05129132f83fb1a8ad9d61084b8d -r 47bf935396cbd394791ae4c838d48f3e3a453c92 yt/utilities/lib/mesh_intersection.pyx
--- a/yt/utilities/lib/mesh_intersection.pyx
+++ b/yt/utilities/lib/mesh_intersection.pyx
@@ -21,6 +21,7 @@
 cimport cython
 from libc.math cimport fabs, fmin, fmax, sqrt
 from yt.utilities.lib.mesh_samplers cimport sample_hex20
+from vec3_ops cimport dot, subtract, cross, distance
 
 
 @cython.boundscheck(False)
@@ -80,30 +81,6 @@
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
-cdef float dot(const float* a, 
-               const float* b,
-               size_t N) nogil:
-    cdef int i
-    cdef float rv = 0.0
-    for i in range(N):
-        rv += a[i]*b[i]
-    return rv
-
-
- at cython.boundscheck(False)
- at cython.wraparound(False)
- at cython.cdivision(True)
-cdef void cross(const float* a, 
-                const float* b,
-                float* c) nogil:
-    c[0] = a[1]*b[2] - a[2]*b[1]
-    c[1] = a[2]*b[0] - a[0]*b[2]
-    c[2] = a[0]*b[1] - a[1]*b[0]
-
-
- at cython.boundscheck(False)
- at cython.wraparound(False)
- at cython.cdivision(True)
 cdef void patchBoundsFunc(Patch* patches, 
                           size_t item,
                           rtcg.RTCBounds* bounds_o) nogil:
@@ -146,7 +123,7 @@
 
     # first we compute the two planes that define the ray.
     cdef float[3] n, N1, N2
-    cdef float A = dot(ray.dir, ray.dir, 3)
+    cdef float A = dot(ray.dir, ray.dir)
     for i in range(3):
         n[i] = ray.dir[i] / A
 
@@ -160,16 +137,16 @@
         N1[2] =-n[1]
     cross(N1, n, N2)
 
-    cdef float d1 = -dot(N1, ray.org, 3)
-    cdef float d2 = -dot(N2, ray.org, 3)
+    cdef float d1 = -dot(N1, ray.org)
+    cdef float d2 = -dot(N2, ray.org)
 
     # the initial guess is set to zero
     cdef float u = 0.0
     cdef float v = 0.0
     cdef float[3] S
     patchSurfaceFunc(patch, u, v, S)
-    cdef float fu = dot(N1, S, 3) + d1
-    cdef float fv = dot(N2, S, 3) + d2
+    cdef float fu = dot(N1, S) + d1
+    cdef float fv = dot(N2, S) + d2
     cdef float err = fmax(fabs(fu), fabs(fv))
     
     # begin Newton interation
@@ -183,10 +160,10 @@
         # compute the Jacobian
         patchSurfaceDerivU(patch, u, v, Su)
         patchSurfaceDerivV(patch, u, v, Sv)
-        J11 = dot(N1, Su, 3)
-        J12 = dot(N1, Sv, 3)
-        J21 = dot(N2, Su, 3)
-        J22 = dot(N2, Sv, 3)
+        J11 = dot(N1, Su)
+        J12 = dot(N1, Sv)
+        J21 = dot(N2, Su)
+        J22 = dot(N2, Sv)
         det = (J11*J22 - J12*J21)
         
         # update the u, v values
@@ -194,17 +171,14 @@
         v -= (-J21*fu + J11*fv) / det
         
         patchSurfaceFunc(patch, u, v, S)
-        fu = dot(N1, S, 3) + d1
-        fv = dot(N2, S, 3) + d2
+        fu = dot(N1, S) + d1
+        fv = dot(N2, S) + d2
 
         err = fmax(fabs(fu), fabs(fv))
         iterations += 1
 
     # t is the distance along the ray to this hit
-    cdef float t = 0.0
-    for i in range(3):
-        t += (S[i] - ray.org[i])**2
-    t = sqrt(t)
+    cdef float t = distance(S, ray.org)
 
     # only count this is it's the closest hit
     if (t < ray.tnear or t > ray.Ng[0]):

diff -r 0157f4cbca3c05129132f83fb1a8ad9d61084b8d -r 47bf935396cbd394791ae4c838d48f3e3a453c92 yt/utilities/lib/pixelization_routines.pyx
--- a/yt/utilities/lib/pixelization_routines.pyx
+++ b/yt/utilities/lib/pixelization_routines.pyx
@@ -20,6 +20,7 @@
 from yt.utilities.lib.fp_utils cimport fmin, fmax, i64min, i64max, imin, imax, fabs
 from yt.utilities.exceptions import YTPixelizeError, \
     YTElementTypeNotRecognized
+from vec3_ops cimport dot, cross, subtract
 from yt.utilities.lib.element_mappings cimport \
     ElementSampler, \
     P1Sampler3D, \
@@ -520,17 +521,11 @@
         vi2a = faces[n][1][0]
         vi2b = faces[n][1][1]
         # Shared vertex is vi1a and vi2a
-        for i in range(3):
-            vec1[i] = vertices[vi1b][i] - vertices[vi1a][i]
-            vec2[i] = vertices[vi2b][i] - vertices[vi2a][i]
-            npoint[i] = point[i] - vertices[vi1b][i]
-        # Now the cross product of vec1 x vec2
-        cp_vec[0] = vec1[1] * vec2[2] - vec1[2] * vec2[1]
-        cp_vec[1] = vec1[2] * vec2[0] - vec1[0] * vec2[2]
-        cp_vec[2] = vec1[0] * vec2[1] - vec1[1] * vec2[0]
-        dp = 0.0
-        for j in range(3):
-            dp += cp_vec[j] * npoint[j]
+        subtract(vertices[vi1b], vertices[vi1a], vec1)
+        subtract(vertices[vi2b], vertices[vi2a], vec2)
+        subtract(point, vertices[vi1b], npoint)
+        cross(vec1, vec2, cp_vec)
+        dp = dot(cp_vec, npoint)
         if match == 0:
             if dp < 0:
                 signs[n] = -1

diff -r 0157f4cbca3c05129132f83fb1a8ad9d61084b8d -r 47bf935396cbd394791ae4c838d48f3e3a453c92 yt/utilities/lib/vec3_ops.pxd
--- a/yt/utilities/lib/vec3_ops.pxd
+++ b/yt/utilities/lib/vec3_ops.pxd
@@ -1,22 +1,22 @@
 cimport cython 
-import numpy as np
-cimport numpy as np
+cimport cython.floating
 from libc.math cimport sqrt
 
+
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
-cdef inline np.float64_t dot(const np.float64_t a[3], 
-                             const np.float64_t b[3]) nogil:
+cdef inline cython.floating dot(const cython.floating[3] a, 
+                                const cython.floating[3] b) nogil:
     return a[0]*b[0] + a[1]*b[1] + a[2]*b[2] 
 
 
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
-cdef inline void cross(const np.float64_t a[3], 
-                       const np.float64_t b[3],
-                       np.float64_t c[3]) nogil:
+cdef inline void cross(const cython.floating[3] a,
+                       const cython.floating[3] b,
+                       cython.floating c[3]) nogil:
     c[0] = a[1]*b[2] - a[2]*b[1]
     c[1] = a[2]*b[0] - a[0]*b[2]
     c[2] = a[0]*b[1] - a[1]*b[0]
@@ -25,26 +25,36 @@
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
-cdef inline void subtract(const np.float64_t a[3], 
-                          const np.float64_t b[3],
-                          np.float64_t c[3]) nogil:
+cdef inline void subtract(const cython.floating[3] a, 
+                          const cython.floating[3] b,
+                          cython.floating c[3]) nogil:
     c[0] = a[0] - b[0]
     c[1] = a[1] - b[1]
     c[2] = a[2] - b[2]
 
+
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
-cdef inline void fma(const np.float64_t f,
-                     const np.float64_t a[3], 
-                     const np.float64_t b[3],
-                     np.float64_t c[3]) nogil:
+cdef inline cython.floating distance(const cython.floating[3] a,
+                                     const cython.floating[3] b) nogil:
+    return sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2 +(a[2] - b[2])**2)
+
+
+ at cython.boundscheck(False)
+ at cython.wraparound(False)
+ at cython.cdivision(True)
+cdef inline void fma(const cython.floating f,
+                     const cython.floating[3] a, 
+                     const cython.floating[3] b,
+                     cython.floating[3] c) nogil:
     c[0] = f * a[0] + b[0]
     c[1] = f * a[1] + b[1]
     c[2] = f * a[2] + b[2]
 
+
 @cython.boundscheck(False)
 @cython.wraparound(False)
 @cython.cdivision(True)
-cdef inline np.float64_t L2_norm(const np.float64_t a[3]) nogil:
+cdef inline cython.floating L2_norm(const cython.floating[3] a) nogil:
     return sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2])

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/20160406/9d434edc/attachment.htm>


More information about the yt-svn mailing list