Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions galgebra/interop/_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ def Cl(p: int, q: int = 0, r: int = 0, root: str = 'e', **kwargs):
Uses galgebra defaults (basis numbered from 1, dual mode ``'I+'``).
For kingdon conventions, use ``galgebra.interop.kingdon.Cl`` instead.

.. note::

This function resets the session-wide dual mode to ``'I+'``
(galgebra default) before building the algebra. If you have
previously called ``galgebra.interop.kingdon.Cl`` in the same
session, that call will have set ``'Iinv+'`` globally; this call
restores the galgebra default. See :issue:`555` for the
long-term per-instance fix.

Parameters
----------
p : int
Expand Down Expand Up @@ -52,6 +61,9 @@ def Cl(p: int, q: int = 0, r: int = 0, root: str = 'e', **kwargs):
if n == 0:
raise ValueError("Total dimension p + q + r must be positive.")

# Reset to galgebra default dual convention
Ga.dual_mode('I+')

# Build diagonal metric: p ones, q negative ones, r zeros
g = [1] * p + [-1] * q + [0] * r

Expand Down
14 changes: 9 additions & 5 deletions galgebra/interop/kingdon.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ def Cl(p: int, q: int = 0, r: int = 0, root: str = 'e', **kwargs):
- **Basis naming**: uses 0-indexed names (``e_0, e_1, ...``) to match
kingdon's default for PGA algebras.

.. warning::

The dual mode change is session-wide. If you mix kingdon and
galgebra conventions in the same session, save and restore
``Ga.dual_mode_value`` around the kingdon block::
.. note::

This function sets the session-wide dual mode to ``'Iinv+'``
before building the algebra. ``galgebra.interop.Cl`` resets it
back to ``'I+'``. This means any algebra built under ``'Iinv+'``
will compute duals with ``'I+'`` once a subsequent
``galgebra.interop.Cl`` call is made. For full isolation over a
block of kingdon-convention code, save and restore
``Ga.dual_mode_value`` manually::

saved = Ga.dual_mode_value
try:
Expand Down
15 changes: 15 additions & 0 deletions test/test_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,3 +734,18 @@ def test_Cl_kingdon(self):
assert Ga.dual_mode_value == 'Iinv+'
finally:
Ga.dual_mode(saved)

def test_Cl_dual_mode_reset(self):
"""galgebra.interop.Cl must reset dual mode to I+ after kingdon.Cl set Iinv+."""
from galgebra.interop.kingdon import Cl as KCl
from galgebra.interop import Cl
from galgebra.ga import Ga

saved = Ga.dual_mode_value
try:
KCl(3)
assert Ga.dual_mode_value == 'Iinv+'
Cl(3)
assert Ga.dual_mode_value == 'I+'
finally:
Ga.dual_mode(saved)
Loading