我正在尝试通过在Cython中实现它来优化
Python算法.我的问题是关于以下代码中存在的某个性能瓶颈:
@cython.boundscheck(False) # turn off bounds-checking for entire function
def anglesToRGB( np.ndarray[double, ndim=2] y, np.ndarray[double, ndim=2] x ):
cdef double angle
cdef double Hp
cdef double C
cdef double X
cdef np.ndarray[double, ndim=3] res = np.zeros([y.shape[0], y.shape[1], 3], dtype=np.float64)
for i in xrange(y.shape[0]):
for j in xrange(y.shape[1]):
angle = atan2( y[i,j], x[i,j] )*180.0/PI+180
C = sqrt(pow(y[i,j],2)+pow(x[i,j],2))/360.0 #Chroma
Hp = angle/60.0
X = C*(1-fabs( Hp%2-1))
C *= 255
X *= 255
if (0. <= Hp < 1.):
res[i,j,:] = [C,X,0]
elif (1. <= Hp < 2.):
res[i,j,:] = [X,C,0]
elif (2. <= Hp <