[Numpy-discussion] Faster way to generate a rotation matrix?
Wed Mar 4 17:02:18 CST 2009
Just for other peoples reference I eventually went with a cython
version that goes about twice as fast as my old post. Here it is:
import numpy as np
cimport numpy as np
cdef extern from "math.h":
def rotation(np.ndarray[double] theta):
cdef np.ndarray[double, ndim=2] R = np.zeros((3,3))
cdef double cx = cos(theta), cy = cos(theta), cz = cos(theta)
cdef double sx = sin(theta), sy = sin(theta), sz = sin(theta)
R[0,0] = cx*cz - sx*cy*sz
R[0,1] = cx*sz + sx*cy*cz
R[0,2] = sx*sy
R[1,0] = -sx*cz - cx*cy*sz
R[1,1] = -sx*sz + cx*cy*cz
R[1,2] = cx*sy
R[2,0] = sy*sz
R[2,1] = -sy*cz
R[2,2] = cy
On Wed, Mar 4, 2009 at 10:28 AM, Lou Pecora <firstname.lastname@example.org> wrote:
> Whoops. I see you have profiled your code. Sorry to re-suggest that.
> But I agree with those who suggest a C speed up using ctypes or cthyon.
> However, thanks for posting your question. It caused a LOT of very useful responses that I didn't know about. Thanks to all who replied.
> -- Lou Pecora, my views are my own.
> Numpy-discussion mailing list
More information about the Numpy-discussion