Commit 1fd1478
committed
Micro-optimize rotation transform.
The following test script shows a ~3x speedup.
```python
import math, numpy as np
mtx = np.array([[.1, .2, .3], [.4, .5, .6], [0, 0, 1]])
theta = np.pi / 4
def rotate(mtx, theta):
a = math.cos(theta)
b = math.sin(theta)
rotate_mtx = np.array([[a, -b, 0.0], [b, a, 0.0], [0.0, 0.0, 1.0]],
float)
return np.dot(rotate_mtx, mtx)
def rfast(mtx, theta):
a = math.cos(theta)
b = math.sin(theta)
(xx, xy, x0), (yx, yy, y0), _ = mtx.tolist()
# mtx = [[a -b 0], [b a 0], [0 0 1]] * mtx
mtx[0, 0] = a * xx - b * yx
mtx[0, 1] = a * xy - b * yy
mtx[0, 2] = a * x0 - b * y0
mtx[1, 0] = b * xx + a * yx
mtx[1, 1] = b * xy + a * yy
mtx[1, 2] = b * x0 + a * y0
return mtx
%timeit rotate(mtx, theta)
%timeit rfast(mtx, theta)
```1 parent 68d6b79 commit 1fd1478
1 file changed
+10
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2002 | 2002 | | |
2003 | 2003 | | |
2004 | 2004 | | |
2005 | | - | |
2006 | | - | |
2007 | | - | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
2008 | 2015 | | |
2009 | 2016 | | |
2010 | 2017 | | |
| |||
0 commit comments