[yt-svn] commit/yt: qobilidop: Use `cython.floating` instead of `anyfloat`
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Fri Feb 17 08:10:13 PST 2017
1 new commit in yt:
https://bitbucket.org/yt_analysis/yt/commits/490469277e39/
Changeset: 490469277e39
Branch: yt
User: qobilidop
Date: 2017-02-17 06:32:11+00:00
Summary: Use `cython.floating` instead of `anyfloat`
Cython has a built-in fused type `floating` representing both `float` and `double`. It's the same as the custom-defined `anyfloat`. I think it's better to use the built-in so we don't need to define `anyfloat` here and there.
See http://cython.readthedocs.io/en/latest/src/userguide/fusedtypes.html#built-in-fused-types for reference.
Affected #: 6 files
diff -r bd8fa3c828d7ef0e439ca5527982a65f7817507b -r 490469277e393449dd04255a900f75103d683abe yt/analysis_modules/halo_finding/rockstar/rockstar_groupies.pyx
--- a/yt/analysis_modules/halo_finding/rockstar/rockstar_groupies.pyx
+++ b/yt/analysis_modules/halo_finding/rockstar/rockstar_groupies.pyx
@@ -2,14 +2,11 @@
import os, sys
cimport numpy as np
cimport cython
+from cython cimport floating
#from cpython.mem cimport PyMem_Malloc
from libc.stdlib cimport malloc, free
import sys
-ctypedef fused anyfloat:
- np.float32_t
- np.float64_t
-
# Importing relevant rockstar data types particle, fof halo, halo
cdef import from "particle.h":
@@ -366,8 +363,8 @@
@cython.wraparound(False)
def make_rockstar_fof(self, np.ndarray[np.int64_t, ndim=1] pind,
np.ndarray[np.int64_t, ndim=1] fof_tags,
- np.ndarray[anyfloat, ndim=2] pos,
- np.ndarray[anyfloat, ndim=2] vel):
+ np.ndarray[floating, ndim=2] pos,
+ np.ndarray[floating, ndim=2] vel):
verbose = False
# Define fof object
diff -r bd8fa3c828d7ef0e439ca5527982a65f7817507b -r 490469277e393449dd04255a900f75103d683abe yt/geometry/particle_oct_container.pyx
--- a/yt/geometry/particle_oct_container.pyx
+++ b/yt/geometry/particle_oct_container.pyx
@@ -23,6 +23,7 @@
import numpy as np
from selection_routines cimport SelectorObject
cimport cython
+from cython cimport floating
cdef class ParticleOctreeContainer(OctreeContainer):
cdef Oct** oct_list
@@ -261,10 +262,6 @@
self.visit(o.children[cind(i,j,k)], counts, level + 1)
return
-ctypedef fused anyfloat:
- np.float32_t
- np.float64_t
-
cdef np.uint64_t ONEBIT=1
cdef class ParticleRegions:
@@ -299,7 +296,7 @@
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
- cdef void _mask_positions(self, np.ndarray[anyfloat, ndim=2] pos,
+ cdef void _mask_positions(self, np.ndarray[floating, ndim=2] pos,
np.uint64_t file_id, int filter):
# TODO: Replace with the bitarray
cdef np.int64_t no = pos.shape[0]
diff -r bd8fa3c828d7ef0e439ca5527982a65f7817507b -r 490469277e393449dd04255a900f75103d683abe yt/geometry/selection_routines.pxd
--- a/yt/geometry/selection_routines.pxd
+++ b/yt/geometry/selection_routines.pxd
@@ -19,10 +19,6 @@
from grid_visitors cimport GridTreeNode, GridVisitorData, \
grid_visitor_function, check_child_masked
-ctypedef fused anyfloat:
- np.float32_t
- np.float64_t
-
cdef inline _ensure_code(arr):
if hasattr(arr, "units"):
if "code_length" == str(arr.units):
diff -r bd8fa3c828d7ef0e439ca5527982a65f7817507b -r 490469277e393449dd04255a900f75103d683abe yt/geometry/selection_routines.pyx
--- a/yt/geometry/selection_routines.pyx
+++ b/yt/geometry/selection_routines.pyx
@@ -17,6 +17,7 @@
import numpy as np
cimport numpy as np
cimport cython
+from cython cimport floating
from libc.stdlib cimport malloc, free
from yt.utilities.lib.fp_utils cimport fclip, iclip, fmax, fmin, imin, imax
from .oct_container cimport OctreeContainer, Oct
@@ -96,7 +97,7 @@
cdef _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[anyfloat, ndim=3] vals):
+ np.ndarray[floating, ndim=3] vals):
cdef np.int64_t count = 0
cdef int i, j, k
for i in range(mask.shape[0]):
@@ -550,9 +551,9 @@
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
- def count_points(self, np.ndarray[anyfloat, ndim=1] x,
- np.ndarray[anyfloat, ndim=1] y,
- np.ndarray[anyfloat, ndim=1] z,
+ def count_points(self, np.ndarray[floating, ndim=1] x,
+ np.ndarray[floating, ndim=1] y,
+ np.ndarray[floating, ndim=1] z,
np.float64_t radius):
cdef int count = 0
cdef int i
@@ -578,9 +579,9 @@
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
- def select_points(self, np.ndarray[anyfloat, ndim=1] x,
- np.ndarray[anyfloat, ndim=1] y,
- np.ndarray[anyfloat, ndim=1] z,
+ def select_points(self, np.ndarray[floating, ndim=1] x,
+ np.ndarray[floating, ndim=1] y,
+ np.ndarray[floating, ndim=1] z,
np.float64_t radius):
cdef int count = 0
cdef int i
diff -r bd8fa3c828d7ef0e439ca5527982a65f7817507b -r 490469277e393449dd04255a900f75103d683abe yt/utilities/lib/contour_finding.pyx
--- a/yt/utilities/lib/contour_finding.pyx
+++ b/yt/utilities/lib/contour_finding.pyx
@@ -16,10 +16,10 @@
import numpy as np
cimport numpy as np
cimport cython
+from cython cimport floating
from libc.stdlib cimport malloc, free, realloc
from yt.geometry.selection_routines cimport \
- SelectorObject, AlwaysSelector, OctreeSubsetSelector, \
- anyfloat
+ SelectorObject, AlwaysSelector, OctreeSubsetSelector
from yt.utilities.lib.fp_utils cimport imax
from yt.geometry.oct_container cimport \
OctreeContainer, OctInfo
@@ -522,7 +522,7 @@
@cython.wraparound(False)
def identify_contours(self, OctreeContainer octree,
np.ndarray[np.int64_t, ndim=1] dom_ind,
- np.ndarray[anyfloat, ndim=2] positions,
+ np.ndarray[floating, ndim=2] positions,
np.ndarray[np.int64_t, ndim=1] particle_ids,
int domain_id, int domain_offset):
cdef np.ndarray[np.int64_t, ndim=1] pdoms, pcount, pind, doff
@@ -560,7 +560,7 @@
pdoms[i] = offset
pind = np.argsort(pdoms)
cdef np.int64_t *ipind = <np.int64_t*> pind.data
- cdef anyfloat *fpos = <anyfloat*> positions.data
+ cdef floating *fpos = <floating*> positions.data
# pind is now the pointer into the position and particle_ids array.
for i in range(positions.shape[0]):
offset = pdoms[pind[i]]
@@ -642,7 +642,7 @@
@cython.boundscheck(False)
@cython.wraparound(False)
cdef void link_particles(self, ContourID **container,
- anyfloat *positions,
+ floating *positions,
np.int64_t *pind,
np.int64_t pcount,
np.int64_t noffset,
diff -r bd8fa3c828d7ef0e439ca5527982a65f7817507b -r 490469277e393449dd04255a900f75103d683abe yt/utilities/lib/geometry_utils.pyx
--- a/yt/utilities/lib/geometry_utils.pyx
+++ b/yt/utilities/lib/geometry_utils.pyx
@@ -16,6 +16,7 @@
import numpy as np
cimport numpy as np
cimport cython
+from cython cimport floating
from libc.stdlib cimport malloc, free
from yt.utilities.lib.fp_utils cimport fclip, i64clip
from libc.math cimport copysign, fabs
@@ -348,16 +349,12 @@
morton_indices[i] = mi
return morton_indices
-ctypedef fused anyfloat:
- np.float32_t
- np.float64_t
-
@cython.cdivision(True)
@cython.boundscheck(False)
@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,
+cdef np.int64_t position_to_morton(np.ndarray[floating, ndim=1] pos_x,
+ np.ndarray[floating, ndim=1] pos_y,
+ np.ndarray[floating, 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,
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