Skip to content

Commit

Permalink
MAINT: remove redundant aslatex dispatches
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Apr 30, 2024
1 parent 1bf294d commit d22acd8
Showing 1 changed file with 1 addition and 47 deletions.
48 changes: 1 addition & 47 deletions src/ampform_dpd/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
>>> aslatex(3.4 - 2j)
'3.4-2i'
This code originates from `ComPWA/ampform#280
<https://github.com/ComPWA/ampform/pull/280>`_.
This code originates from `ComPWA/ampform#280<https://github.com/ComPWA/ampform/pull/280>`_.
"""

from __future__ import annotations
Expand Down Expand Up @@ -49,51 +48,6 @@
_LOGGER = logging.getLogger(__name__)


@aslatex.register(complex)
def _(obj: complex, **kwargs) -> str:
real = __downcast(obj.real)
imag = __downcast(obj.imag)
plus = "+" if imag >= 0 else ""
return f"{real}{plus}{imag}i"


def __downcast(obj: float) -> float | int:
if obj.is_integer():
return int(obj)
return obj


@aslatex.register(sp.Basic)
def _(obj: sp.Basic, **kwargs) -> str:
return sp.latex(obj)


@aslatex.register(abc.Mapping)
def _(obj: Mapping, **kwargs) -> str:
if len(obj) == 0:
msg = "Need at least one dictionary item"
raise ValueError(msg)
latex = R"\begin{array}{rcl}" + "\n"
for lhs, rhs in obj.items():
latex += Rf" {aslatex(lhs, **kwargs)} &=& {aslatex(rhs, **kwargs)} \\" + "\n"
latex += R"\end{array}"
return latex


@aslatex.register(abc.Iterable)
def _(obj: Iterable, **kwargs) -> str:
obj = list(obj)
if len(obj) == 0:
msg = "Need at least one item to render as LaTeX"
raise ValueError(msg)
latex = R"\begin{array}{c}" + "\n"
for item in obj:
item_latex = aslatex(item, **kwargs)
latex += Rf" {item_latex} \\" + "\n"
latex += R"\end{array}"
return latex


@aslatex.register(IsobarNode)
def _(obj: IsobarNode, **kwargs) -> str:
def render_arrow(node: IsobarNode) -> str:
Expand Down

0 comments on commit d22acd8

Please sign in to comment.