symforce.ops.ops module

exception OpNotImplementedError[source]

Bases: NotImplementedError

Exception raised when an operation is not implemented for a given type.

class Ops[source]

Bases: object

Class for specifying how Storage/Group/LieGroup ops functions should be implemented for specific types (e.g. scalars, geo objects, etc.). Classes that inherit from Ops can be considered “concepts” (see https://en.wikipedia.org/wiki/Concept_(generic_programming)), meaning that they define a set of valid operations on the types (or subtypes) registered with this base class.

As classes are created, they (or one of their parent classes) must be registered by calling register(), which specifies a specific implementation of the ops for that class. This is similar to template specialization in C++.

IMPLEMENTATIONS: Dict[Type, Tuple[Type, Type]] = {<class 'float'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'numpy.float16'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'numpy.float32'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'numpy.float64'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'int'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'numpy.int8'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'numpy.int16'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'numpy.int32'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'numpy.int64'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'symforce.ops.ScalarExpr'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.scalar_lie_group_ops.ScalarLieGroupOps'>), <class 'list'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.sequence_lie_group_ops.SequenceLieGroupOps'>), <class 'tuple'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.sequence_lie_group_ops.SequenceLieGroupOps'>), <class 'numpy.ndarray'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.array_lie_group_ops.ArrayLieGroupOps'>), <class 'symforce.typing.Dataclass'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.dataclass_lie_group_ops.DataclassLieGroupOps'>), <class 'NoneType'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.nonetype_lie_group_ops.NoneTypeLieGroupOps'>), <class 'symforce.ops.LieGroupSymClass'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.sym_class_lie_group_ops.SymClassLieGroupOps'>), <class 'symengine.lib.symengine_wrapper.DataBuffer'>: (<class 'symforce.ops.storage_ops.StorageOps'>, <class 'symforce.ops.impl.databuffer_storage_ops.DataBufferStorageOps'>), <class 'symforce.ops.interfaces.storage.Storage'>: (<class 'symforce.ops.storage_ops.StorageOps'>, <class 'symforce.ops.impl.class_storage_ops.ClassStorageOps'>), <class 'symforce.ops.interfaces.group.Group'>: (<class 'symforce.ops.group_ops.GroupOps'>, <class 'symforce.ops.impl.class_group_ops.ClassGroupOps'>), <class 'symforce.ops.interfaces.lie_group.LieGroup'>: (<class 'symforce.ops.lie_group_ops.LieGroupOps'>, <class 'symforce.ops.impl.class_lie_group_ops.ClassLieGroupOps'>)}
classmethod register(impl_type, impl_ops)[source]

Register the operations class for a given type. Once a type is registered, child classes of Ops will be able to call functions defined in impl_ops.

Example:

# ScalarStorageOps defines valid storage operations on floats
StorageOps.register(float, ScalarStorageOps)

# We can now perform storage operations of objects of type float
StorageOps.storage_dim(1.0)
Parameters:
  • impl_type (Type) – Type to be registered

  • impl_ops (Type) – Class defining how each operation is implemented for the given type

Return type:

None

classmethod implementation(impl_type)[source]

Returns the class defining the operations for the given type or one of its parent classes.

If multiple parent classes are registered with the calling class, the implementation of the first such parent class in method resolution order is returned.

Raises:

OpNotImplementedError – If impl_type or one of its parent classes is not registered with the calling class or one of its subclasses.

Parameters:

impl_type (Type) –

Return type:

Type