Skip to content

Commit dcec6ca

Browse files
authored
ENH: support MatrixSymbol in HelicityModel attributes (#495)
* ENH: make signature in dict sorting functions generic
1 parent a7caba3 commit dcec6ca

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def _get_scipy_url() -> str:
115115
"FourMomenta": ("obj", "ampform.kinematics.lorentz.FourMomenta"),
116116
"FourMomentumSymbol": ("obj", "ampform.kinematics.lorentz.FourMomentumSymbol"),
117117
"InteractionProperties": "qrules.quantum_numbers.InteractionProperties",
118+
"K": "typing.TypeVar",
118119
"LatexPrinter": "sympy.printing.printer.Printer",
119120
"Literal[-1, 1]": "typing.Literal",
120121
"Literal[(-1, 1)]": "typing.Literal",
@@ -139,6 +140,7 @@ def _get_scipy_url() -> str:
139140
"SympyObject": "typing.TypeVar",
140141
"T": "typing.TypeVar",
141142
"Topology": "qrules.topology.Topology",
143+
"V": "typing.TypeVar",
142144
"WignerD": "sympy.physics.quantum.spin.WignerD",
143145
"sympy.tensor.array.expressions.array_expressions.ArraySymbol": (
144146
"mod",

src/ampform/helicity/__init__.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from collections import OrderedDict, abc
1515
from fractions import Fraction
1616
from functools import reduce, singledispatchmethod
17-
from typing import TYPE_CHECKING, cast
17+
from typing import TYPE_CHECKING, TypeVar, cast
1818

1919
import attrs
2020
import sympy as sp
@@ -74,27 +74,24 @@
7474

7575
_LOGGER = logging.getLogger(__name__)
7676

77+
K = TypeVar("K")
78+
V = TypeVar("V")
7779

78-
def _order_component_mapping(
79-
mapping: Mapping[str, sp.Expr],
80-
) -> OrderedDict[str, sp.Expr]:
80+
81+
def _order_component_mapping(mapping: Mapping[str, V], /) -> OrderedDict[str, V]:
8182
return collections.OrderedDict([
8283
(key, mapping[key]) for key in sorted(mapping, key=natural_sorting)
8384
])
8485

8586

86-
def _order_symbol_mapping(
87-
mapping: Mapping[sp.Symbol, sp.Expr],
88-
) -> OrderedDict[sp.Symbol, sp.Expr]:
87+
def _order_symbol_mapping(mapping: Mapping[K, V], /) -> OrderedDict[K, V]:
8988
return collections.OrderedDict([
9089
(symbol, mapping[symbol])
91-
for symbol in sorted(mapping, key=lambda s: natural_sorting(s.name))
90+
for symbol in sorted(mapping, key=lambda s: natural_sorting(str(s)))
9291
])
9392

9493

95-
def _order_amplitudes(
96-
mapping: Mapping[sp.Indexed, sp.Expr],
97-
) -> OrderedDict[sp.Indexed, sp.Expr]:
94+
def _order_amplitudes(mapping: Mapping[K, V], /) -> OrderedDict[K, V]:
9895
return collections.OrderedDict([
9996
(key, mapping[key])
10097
for key in sorted(mapping, key=lambda a: natural_sorting(str(a)))

0 commit comments

Comments
 (0)