I have the following code:
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]
I'm testing it, and I get 1.7300620079
seconds. But, when I use the @autojit
decorator it get worse.
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]
with 1.92721390724
seconds. Should I change something to get better performances?
The code for testing is:
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