我正在尝试加快python3函数的速度,该函数获取一些数据,这是一个索引数组,如果它们满足某个条件,就保存它们。我试着用“cython-a”来加快速度脚本.py但瓶颈似乎是h5py I/O切片数据集。在
我对cython比较陌生,所以我想知道是有什么方法可以加快速度,还是我只是受到了h5py I/O的限制?在
以下是我要改进的功能:import numpy as np
import h5py
cimport numpy as np
cimport cython
from libc.math cimport sqrt
DTYPE64 = np.int64
ctypedef np.int64_t DTYPE64_t
DTYPE32 = np.int32
ctypedef np.int32_t DTYPE32_t
@cython.boundscheck(False)
@cython.wraparound(False)
def tag_subhalo_branch(np.ndarray[DTYPE64_t] halos_z0_treeindxs,
np.ndarray[DTYPE64_t] tree_pindx,
np.ndarray[DTYPE32_t] tree_psnapnum,
np.ndarray[DTYPE64_t] tree_psnapid,
np.ndarray[DTYPE64_t] tree_hsnapid, hf,
int size):
cdef int i
cdef double radial, progen_x, progen_y, progen_z
cdef doub