Source code for symforce.ops.impl.abstract_vector_group_ops
# ----------------------------------------------------------------------------# SymForce - Copyright 2022, Skydio, Inc.# This source code is under the Apache 2.0 license found in the LICENSE file.# ----------------------------------------------------------------------------fromsymforceimporttypingasTfrom.abstract_storage_opsimportAbstractStorageOpsElementT=T.TypeVar("ElementT")ElementOrTypeT=T.Union[ElementT,T.Type[ElementT]]
[docs]classAbstractVectorGroupOps(AbstractStorageOps[ElementT]):""" An abstract base class for GroupOps implementations whose group operation is equivalent to storage representation addition, and whose identity element is the element whose storage representation is the 0 vector. For a list of abstract methods which child classes must define, see :mod:`.abstract_storage_ops`. """
[docs]@classmethoddefcompose(cls,a:ElementT,b:ElementT)->ElementT:ifcls.storage_dim(a)!=cls.storage_dim(b):raiseValueError(f"Elements must have the same storage length ({cls.storage_dim(a)} != {cls.storage_dim(b)}).")returncls.from_storage(a,[ax+bxforax,bxinzip(cls.to_storage(a),cls.to_storage(b))])