1
2 from . import contract, np, logger
3 from .manifolds import DifferentiableManifold
4 from contracts import describe_value, describe_type
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 converters = {}
29 default_representation = {}
38
50
51
52 @contract(returns='list[2]')
53 -def to_yaml(manifold, value, representation=None):
54 if representation is None:
55 representation = get_default_representation(manifold)
56 key = (manifold, representation)
57 if not key in converters:
58 raise ValueError('Unknown format %s; I know %s.' %
59 (key, converters.keys()))
60 conv = converters[key]
61 try:
62 x = conv.to_yaml(value)
63 except:
64 msg = 'Error while trying to convert %s' % describe_value(value)
65 logger.error(msg)
66 raise
67 return ['%s:%s' % (manifold, representation), x]
68
69
70 @contract(x='list[2]')
71 -def from_yaml(x):
72 if not isinstance(x, list):
73 raise ValueError('I expect a list with two elements.')
74 form = x[0]
75 if not isinstance(form, str):
76 raise ValueError('I expect a string describing the format,'
77 ' not %s, while decoding %s' %
78 (describe_type(form), describe_value(x)))
79 value = x[1]
80 space, representation = form.split(':')
81
82 key = (space, representation)
83 if not key in converters:
84 raise ValueError('Unknown format %s; I know %s.' %
85 (key, converters.keys()))
86 conv = converters[key]
87 return conv.from_yaml(value)
88
96
99 @staticmethod
100 @contract(x='SE3', returns='list[4](list[4](float))')
103
104 @staticmethod
105 @contract(y='list[4](list[4](float))', returns='SE3')
108
109 register_yaml_converter('SE3', 'm44', SE3_m44)
110
111
112 -class se3_m44(Representation):
113 @staticmethod
116
117 @staticmethod
120
123 @staticmethod
127
128 @staticmethod
132
133
134 register_yaml_converter('TSE3', 'bt', TSE3_bt)
135