# ----------------------------------------------------------------------------# SymForce - Copyright 2022, Skydio, Inc.# This source code is under the Apache 2.0 license found in the LICENSE file.# ----------------------------------------------------------------------------from__future__importannotationsimportsympyfromsymforceimporttypingasT
[docs]classDataBuffer(sympy.MatrixSymbol):""" Custom class to make sympy's MatrixSymbol consistent with symengine, where we have a custom 1-D Databuffer. We want to force Databuffers to be 1-D since otherwise CSE will (rightfully) treat each index as a separate expression. """# HACK(harrison): needed to get around the flast that DataBuffer needs to be called from# initialization.py__sympy_module__:T.Any=Nonedef__new__(cls,name:str,n:T.Optional[T.Scalar]=None,m:T.Optional[T.Scalar]=None)->DataBuffer:ifnisNone:n=DataBuffer.__sympy_module__.Symbol(name+"_dim")ifmisnotNone:assertm==1,"DataBuffer is 1-D only!"instance=super(DataBuffer,cls).__new__(cls,name,n,DataBuffer.__sympy_module__.S(1))returninstancedef__getitem__(self,key:T.Any)->sympy.matrices.expressions.matexpr.MatrixElement:returnsuper().__getitem__((key,DataBuffer.__sympy_module__.S(0)))