1
我有實現二維拉普拉斯對於偏微分方程finite differences集成方法的代碼,使用roll method of Numpy:實現2D拉普拉斯在用Cython週期性邊界counditions
def lapOp(u):
"""
This is the laplacian operator on 2D array
of stencil of 4th accuracy terms
"""
lap = ((4.0/3.0)*np.roll(u,1,axis=0) + (4.0/3.0)*np.roll(u,-1,axis=0) + (4.0/3.0)*np.roll(u,1,axis=1) + (4.0/3.0)*np.roll(u,-1,axis=1) -5.0*u)
lap -= ((1.0/12.0)*np.roll(u,2,axis=0) + (1.0/12.0)*np.roll(u,-2,axis=0) + (1.0/12.0)*np.roll(u,2,axis=1) + (1.0/12.0)*np.roll(u,-2,axis=1))
lap = lap/hh
return lap
我想cythonize我的代碼 - 將滾動方法在pyx代碼中工作,還是應該使用C實現滾動方法?