Skip to content

Commit 64d0ced

Browse files
committed
another 10% speed bump by getting rid of np.vstack
1 parent f32c800 commit 64d0ced

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

hexrd/core/material/unitcell.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ def _calclength(u, mat):
3232

3333
@njit(cache=True, nogil=True)
3434
def _calcstar(v, sym, mat):
35-
vsym = np.atleast_2d(v)
36-
for s in sym:
35+
# vsym = np.atleast_2d(v)
36+
vsym = np.empty((sym.shape[0], v.shape[0]))
37+
n = 0
38+
vsym[n,:] = v
39+
n = n + 1
40+
# the first element is always the identity
41+
# so we can safely skip that
42+
for s in sym[1:,:,:]:
3743
vp = np.dot(np.ascontiguousarray(s), v)
3844
# check if this is new
3945
isnew = True
@@ -43,10 +49,10 @@ def _calcstar(v, sym, mat):
4349
isnew = False
4450
break
4551
if isnew:
46-
vp = np.atleast_2d(vp)
47-
vsym = np.vstack((vsym, vp))
52+
vsym[n,:] = vp
53+
n = n + 1
4854

49-
return vsym
55+
return vsym[0:n,:]
5056

5157
class unitcell:
5258
'''

0 commit comments

Comments
 (0)