次のコードがあります。
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