1
1
"""Metrology APIs."""
2
2
3
- from typing import Final , Protocol , Self , override , runtime_checkable
3
+ from typing import TYPE_CHECKING , Final , Protocol , Self , override , runtime_checkable
4
4
5
5
import optype as op
6
6
7
+ if TYPE_CHECKING :
8
+ import fractions
9
+
10
+
7
11
__version__ : Final = "0.0.1.dev0"
8
12
__all__ = ["__version__" , "Dimension" , "Quantity" , "Unit" ]
9
13
@@ -17,6 +21,31 @@ def __pow__(self, other: int, /) -> Self: ...
17
21
def __rmul__ (self , other : Self , / ) -> Self : ...
18
22
def __rtruediv__ (self , other : Self , / ) -> Self : ...
19
23
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
+
20
49
21
50
@runtime_checkable
22
51
class Unit (Protocol ):
0 commit comments