Skip to content

Commit c4d4718

Browse files
committed
Add documentation and test for ga.ReciprocalFrame
Also deprecates passing `mode="nonsense"`.
1 parent f87a513 commit c4d4718

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

galgebra/ga.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,17 @@ def connection(self, rbase, key_base, mode, left):
19791979
return C
19801980

19811981
def ReciprocalFrame(self, basis, mode='norm'):
1982+
"""
1983+
Compute the reciprocal frame of a set of vectors
1984+
1985+
The `mode` argument must be either:
1986+
1987+
* ``"norm"``, indicating the reciprocal vectors should be normalized
1988+
such that their product with the input vectors is 1
1989+
* ``"append"``, indicating that instead of normalizing, the
1990+
normalization coefficient should be appended to the returned tuple.
1991+
One can divide by this coefficient to normalize the vectors.
1992+
"""
19821993
dim = len(basis)
19831994

19841995
indexes = tuple(range(dim))
@@ -2011,11 +2022,17 @@ def ReciprocalFrame(self, basis, mode='norm'):
20112022
rbasis.append(recpv)
20122023
sgn = -sgn
20132024

2014-
if mode != 'norm':
2015-
rbasis.append(E_sq)
2016-
else:
2025+
if mode == 'norm':
20172026
for i in range(dim):
20182027
rbasis[i] = rbasis[i] / E_sq
2028+
else:
2029+
if mode != 'append':
2030+
# galgebra 0.5.0
2031+
warnings.warn(
2032+
"Mode {!r} not understood, falling back to {!r} but this "
2033+
"is deprecated".format(mode, 'append'),
2034+
DeprecationWarning, stacklevel=2)
2035+
rbasis.append(E_sq)
20192036

20202037
return tuple(rbasis)
20212038

test/test_test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,33 @@ def test_extracting_vectors_from_conformal_2_blade(self):
363363
aB = a|B
364364
assert str(aB) == '-(P2.a)*P1 + (P1.a)*P2'
365365

366+
def test_ReciprocalFrame(self):
367+
ga, *basis = Ga.build('e*u|v|w')
368+
369+
r_basis = ga.ReciprocalFrame(basis)
370+
371+
for i, base in enumerate(basis):
372+
for r_i, r_base in enumerate(r_basis):
373+
if i == r_i:
374+
assert (base | r_base).simplify() == 1
375+
else:
376+
assert (base | r_base).simplify() == 0
377+
378+
def test_ReciprocalFrame_append(self):
379+
ga, *basis = Ga.build('e*u|v|w')
380+
*r_basis, E_sq = ga.ReciprocalFrame(basis, mode='append')
381+
382+
for i, base in enumerate(basis):
383+
for r_i, r_base in enumerate(r_basis):
384+
if i == r_i:
385+
assert (base | r_base).simplify() == E_sq
386+
else:
387+
assert (base | r_base).simplify() == 0
388+
389+
# anything that isn't 'norm' means 'append', but this is deprecated
390+
with pytest.warns(DeprecationWarning):
391+
assert ga.ReciprocalFrame(basis, mode='nonsense') == (*r_basis, E_sq)
392+
366393
def test_reciprocal_frame_test(self):
367394

368395
g = '1 # #,'+ \

0 commit comments

Comments
 (0)