- class Values(_dict=None, **kwargs)#
Ordered dictionary serializable storage. This class is the basis for specifying both inputs and outputs in symforce. The hierarchy of nested values get code generated into types, and several methods of access and introspection are provided that reduce downstream complexity.
Includes standard operator access to keys and values.
Access with dot notation, such as
Underlying storage - ordered dictionary
- get(key, default=None)#
Return the value for key if key is in the dictionary, else default.
Returns a deepcopy of this Values.
Returns the index with structural information to reconstruct this values in
- static get_index_from_items(items)#
Builds an index from a list of key/value pairs of objects. This function can be called recursively either for the items of a Values object or for the items of a list (using e.g.
zip(my_keys, my_list), where
my_keysare some arbitrary names for each element in
Returns a flat list of key/value pairs for every element in this object in insertion order of highest level dot separated key.
Returns a flat list of unique keys for every element in this object in insertion order of highest level dot separated key.
Returns a flat list of elements stored in this Values object in insertion order of highest level dot separated key.
Returns a flat list of subkeys for every element in this object in insertion order of highest level dot separated key. Unlike
subkeys_recursivedoes not return dot-separated keys.
Returns a flat list of keys to each scalar in this object in insertion order of highest level dot separated key.
Returns a flat list of unique values for every scalar element in this object.
- classmethod from_storage_index(vector_values, indices)#
Takes a vectorized values and corresponding indices and reconstructs the original form. Reverse of
Create a Values object with the same structure as self but constructed from a flat list representation. Opposite of
- symbolic(name, **kwargs)#
Create a Values object with the same structure as self, where each element is a symbolic element with the given name prefix. Kwargs are forwarded to
sf.Symbol(for example, sympy assumptions).
Returns Values object with same structure as self, but with each element as an identity element.
- Return type:
Element-wise compose of each element with another Values of identical structure
- from_tangent(vec, epsilon=0.0)#
Returns a Values object with the same structure as self, but by computing each element using the mapping from its corresponding tangent space vector about identity into a group element.
Returns flat vector representing concatenated tangent spaces of each element.
- retract(vec, epsilon=0.0)#
Apply a perturbation vec in the concatenated tangent spaces of each element. Often used in optimization to update nonlinear values from an update step in the tangent space.
NOTE(aaron): We have to override the default LieGroup implementation of retract because not all values we can store here obey retract(a, vec) = compose(a, from_tangent(vec))
- local_coordinates(b, epsilon=0.0)#
Computes a perturbation in the combined tangent space around self to produce b. Often used in optimization to minimize the distance between two group elements.
NOTE(aaron): We have to override the default LieGroup implementation of local_coordinates because not all values we can store here obey local_coordinates(a, b) = to_tangent(between(a, b))
Returns a matrix with dimensions (storage_dim x tangent_dim) which represents the jacobian of the flat storage space of self wrt to the flat tangent space of self. The resulting jacobian is a block diagonal matrix, where each block corresponds to the storage_D_tangent for a single element or is zero.
- Return type:
Returns a matrix with dimensions (tangent_dim x storage_dim) which represents the jacobian of the flat tangent space of self wrt to the flat storage space of self. The resulting jacobian is a block diagonal matrix, where each block corresponds to the tangent_D_storage for a single element or is zero.
- Return type:
Pretty format as an indented tree.
- __setitem__(key, value)#
Set an entry at a given path in the Values, creating the path if it doesn’t exist
This means that intermediate Values objects along the path will be created. Intermediate sequences (lists) will be created or appended to only if the index requested is no more than 1 past the current length - e.g.
values['foo'] = 5will create the
foolist with one entry (5) if the
foolist did not previously exist, and
values['foo'] = 6will append 6 to the
foolist if it previously had length 1.
Context manager to apply a name scope to both keys added to the values and new symbols created within the with block.
- add(value, **kwargs)#
Add a symbol into the values using its given name, either a Symbol or a string. Allows avoiding duplication of the sort
v['foo'] = sf.Symbol('foo').
- subs(*args, **kwargs)#
Substitute given values of each scalar element into a new instance.
Apply the given function to each leaf node of the Values, and return a new Values. This currently also converts any dataclasses to Values.
Convert any symbolic types in this Values to numerical quantities. This currently also converts any dataclasses to Values.
- Return type:
Converts this Values object and any Values or Dataclass objects contained within it to dict objects. This is different from
dictcan have leaves which are Values objects, whereas the dict returned by this function recursively converts all Values and Dataclass objects into dicts.
Called when pickling this Values. Because some symengine objects cannot be pickled, we first convert any symbolic types to numerical types, and then store the data + index.