Skip to content

Commit c49dcb3

Browse files
committed
types definition depends on python version
1 parent 542dda0 commit c49dcb3

File tree

4 files changed

+159
-63
lines changed

4 files changed

+159
-63
lines changed

spatialmath/base/_types_38.py

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

spatialmath/base/_types_39.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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]

spatialmath/base/sm_types.py

Lines changed: 0 additions & 63 deletions
This file was deleted.

spatialmath/base/types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
import sys
3+
4+
if sys.version_info.minor > 8:
5+
from spatialmath.base._types_39 import *
6+
else:
7+
from spatialmath.base._types_38 import *

0 commit comments

Comments
 (0)