1
+ # for Python >= 3.9
2
+
3
+ from typing import overload , Union , List , Tuple , Type , TextIO , Any , Callable , Optional
4
+ from typing import Literal as L
5
+
6
+ from numpy import ndarray , dtype , floating
7
+ from numpy .typing import NDArray , DTypeLike
8
+
9
+ # array like
10
+
11
+ # these are input to many functions in spatialmath.base, and can be a list, tuple or
12
+ # ndarray. The elements are generally float, but some functions accept symbolic
13
+ # arguments as well, which leads to a NumPy array with dtype=object
14
+ #
15
+ # The variants like ArrayLike2 indicate that a list, tuple or ndarray of
16
+ # length 2 is expected. Static checking of tuple length is possible but not a lists.
17
+ # This might be possible in future versions of Python, but for now it is a hint to the
18
+ # coder about what is expected
19
+
20
+
21
+ ArrayLike = Union [float , List [float ], Tuple [float ], ndarray [Any , dtype [floating ]]]
22
+ ArrayLike2 = Union [List , Tuple [float ,float ], ndarray [Tuple [L [2 ,]], dtype [floating ]]]
23
+ ArrayLike3 = Union [List ,Tuple [float ,float ,float ],ndarray [Tuple [L [3 ,]], dtype [floating ]]]
24
+ ArrayLike4 = Union [List ,Tuple [float ,float ,float ,float ],ndarray [Tuple [L [4 ,]], dtype [floating ]]]
25
+ ArrayLike6 = Union [List ,Tuple [float ,float ,float ,float ,float ,float ],ndarray [Tuple [L [6 ,]], dtype [floating ]]]
26
+
27
+ # real vectors
28
+ R2 = ndarray [Tuple [L [2 ,]], dtype [floating ]] # R^2
29
+ R3 = ndarray [Tuple [L [3 ,]], dtype [floating ]] # R^3
30
+ R4 = ndarray [Tuple [L [4 ,]], dtype [floating ]] # R^3
31
+ R6 = ndarray [Tuple [L [6 ,]], dtype [floating ]] # R^6
32
+
33
+ # real matrices
34
+ R2x2 = ndarray [Tuple [L [2 ,2 ]], dtype [floating ]] # R^{2x2} matrix
35
+ R3x3 = ndarray [Tuple [L [3 ,3 ]], dtype [floating ]] # R^{3x3} matrix
36
+ R4x4 = ndarray [Tuple [L [4 ,4 ]], dtype [floating ]] # R^{4x4} matrix
37
+ R6x6 = ndarray [Tuple [L [6 ,6 ]], dtype [floating ]] # R^{6x6} matrix
38
+ R1x3 = ndarray [Tuple [L [1 ,3 ]], dtype [floating ]] # R^{1x3} row vector
39
+ R3x1 = ndarray [Tuple [L [3 ,1 ]], dtype [floating ]] # R^{3x1} column vector
40
+ R1x2 = ndarray [Tuple [L [1 ,2 ]], dtype [floating ]] # R^{1x2} row vector
41
+ R2x1 = ndarray [Tuple [L [2 ,1 ]], dtype [floating ]] # R^{2x1} column vector
42
+
43
+ Points2 = ndarray [(2 ,Any ), dtype [floating ]] # R^{2xN} matrix
44
+ Points3 = ndarray [(3 ,Any ), dtype [floating ]] # R^{2xN} matrix
45
+
46
+ RNx3 = ndarray [(Any ,3 ), dtype [floating ]] # R^{Nx3} matrix
47
+
48
+ def a (x :Points2 ):
49
+ return x
50
+
51
+ import numpy as np
52
+ b = np .zeros ((2 ,10 ))
53
+ z = a ('sss' )
54
+ z = a (b )
55
+
56
+
57
+ # Lie group elements
58
+ SO2Array = ndarray [Tuple [L [2 ,2 ]], dtype [floating ]] # SO(2) rotation matrix
59
+ SE2Array = ndarray [Tuple [L [3 ,3 ]], dtype [floating ]] # SE(2) rigid-body transform
60
+ SO3Array = ndarray [Tuple [L [3 ,3 ]], dtype [floating ]] # SO(3) rotation matrix
61
+ SE3Array = ndarray [Tuple [L [4 ,4 ]], dtype [floating ]] # SE(3) rigid-body transform
62
+
63
+ # Lie algebra elements
64
+ so2Array = ndarray [Tuple [L [2 ,2 ]], dtype [floating ]] # so(2) Lie algebra of SO(2), skew-symmetrix matrix
65
+ se2Array = ndarray [Tuple [L [3 ,3 ]], dtype [floating ]] # se(2) Lie algebra of SE(2), augmented skew-symmetrix matrix
66
+ so3Array = ndarray [Tuple [L [3 ,3 ]], dtype [floating ]] # so(3) Lie algebra of SO(3), skew-symmetrix matrix
67
+ se3Array = ndarray [Tuple [L [4 ,4 ]], dtype [floating ]] # se(3) Lie algebra of SE(3), augmented skew-symmetrix matrix
68
+
69
+ # quaternion arrays
70
+ QuaternionArray = ndarray [Tuple [L [4 ,]], dtype [floating ]]
71
+ UnitQuaternionArray = ndarray [Tuple [L [4 ,]], dtype [floating ]]
72
+
73
+ Rn = Union [R2 ,R3 ]
74
+
75
+ SOnArray = Union [SO2Array ,SO3Array ]
76
+ SEnArray = Union [SE2Array ,SE3Array ]
77
+
78
+ sonArray = Union [so2Array ,so3Array ]
79
+ senArray = Union [se2Array ,se3Array ]
0 commit comments