From dc633c6d9a24b67809aba61fe86dfb64f0548bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Thu, 3 Aug 2017 08:11:28 +0000 Subject: [PATCH] nd generalisation of function for reciprocal basis Former-commit-id: a213a1198a65956eeafe0e3249beafc822131497 --- qpms/lattices2d.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/qpms/lattices2d.py b/qpms/lattices2d.py index fe43aa4..eb5f68b 100644 --- a/qpms/lattices2d.py +++ b/qpms/lattices2d.py @@ -49,7 +49,7 @@ def reduceBasisSingle(b1, b2): mu = np.sum(b1 * b2, axis=-1, keepdims=True) / B1 b2 = b2 - np.rint(mu) * b1 B2 = np.sum(b2*b2, axis=-1, keepdims=True) - return(b1,b2) + return np.array((b1,b2)) def shortestBase3(b1, b2): ''' @@ -212,13 +212,9 @@ def filledWS(b1, b2, density=10, scale=1.): return points -rot90_ = np.array([[0,1],[-1,0]]) -def reciprocalBasis1(a1, a2): - a1, a2 = reduceBasisSingle(a1,a2) # this can be replaced with the vector version of reduceBasis when it is made - prefac = np.sum(np.tensordot(a1, rot90_, axes=[-1,0]) * a2, axis=-1) - b1 = np.tensordot(rot90_, a2, axes=[-1,-1]) * prefac - b2 = np.tensordot(rot90_, a1, axes=[-1,-1]) * prefac - return np.array([b1, b2]) +def reciprocalBasis1(*pargs): + a = reduceBasisSingle(*pargs) + return np.linalg.inv(a).T def reciprocalBasis2pi(*pargs): return 2*np.pi*reciprocalBasis1(*pargs)