Autojit - 如何提高旋转性能

时间:2014-10-21 12:44:16

标签: python anaconda numba numba-pro

我有以下代码:

def rotation_cpu(img, theta, dst):
    cosTheta = np.cos(theta)
    sinTheta = np.sin(theta)
    for i in range(512):
        for j in range(512):
            xpos = cosTheta * i - sinTheta * j
            ypos = sinTheta * i + cosTheta * j
            dst[xpos + 725/2, ypos ] = img[i,j]

我正在测试它,我得到1.7300620079秒。但是,当我使用@autojit装饰器时,它变得更糟。

from numbapro import autojit

@autojit
def rotation_cpu(img, theta, dst):
    cosTheta = np.cos(theta)
    sinTheta = np.sin(theta)
    for i in range(512):
        for j in range(512):
            xpos = cosTheta * i - sinTheta * j
            ypos = sinTheta * i + cosTheta * j
            dst[xpos + 725/2, ypos ] = img[i,j]

1.92721390724秒。我应该换一些东西来获得更好的表现吗?

测试代码是:

from timeit import default_timer as timer
from scipy.misc import imread

img = imread("pic.jpg") # it is a 512x512 pic.
theta = 45
ts = timer()
dst = np.zeros((725, 725)) # new boundaries
rotation_cpu(img, theta * np.pi / 180, dst)
te = timer()

print te - ts

0 个答案:

没有答案