11"""Metrology APIs."""
22
3- from typing import Final , Protocol , Self , override , runtime_checkable
3+ from typing import TYPE_CHECKING , Final , Protocol , Self , override , runtime_checkable
44
55import optype as op
66
7+ if TYPE_CHECKING :
8+ import fractions
9+
10+
711__version__ : Final = "0.0.1.dev0"
812__all__ = ["__version__" , "Dimension" , "Quantity" , "Unit" ]
913
@@ -17,6 +21,31 @@ def __pow__(self, other: int, /) -> Self: ...
1721 def __rmul__ (self , other : Self , / ) -> Self : ...
1822 def __rtruediv__ (self , other : Self , / ) -> Self : ...
1923
24+ def decompose (self ) -> "dict[Dimension, int | fractions.Fraction]" :
25+ """Decompose the dimension into its base dimensions and exponents.
26+
27+ Notes
28+ -----
29+ By far the most common dimension system is (Length, Mass, Time, Electric
30+ Current, Temperature, Amount of Substance, Luminous Intensity).
31+ This method will decompose the dimension into a dictionary of these
32+ base dimensions and their respective exponents.
33+
34+ Examples
35+ --------
36+ As this is an API protocol, no runtime examples are possible. The
37+ following is an illustrative example:
38+
39+ >>> import metrology as u
40+
41+ >>> dim = u.Length / u.Time
42+
43+ >>> dim.decompose()
44+ {Length: 1, Time: -1}
45+
46+ """
47+ ...
48+
2049
2150@runtime_checkable
2251class Unit (Protocol ):
0 commit comments