orb_slam3_details/Thirdparty/Sophus/py/sophus/cse_codegen.py

18 lines
473 B
Python
Raw Normal View History

2022-03-28 21:20:28 +08:00
import sympy
import io
def cse_codegen(symbols):
cse_results = sympy.cse(symbols, sympy.numbered_symbols("c"))
output = io.StringIO()
for helper in cse_results[0]:
output.write("Scalar const ")
output.write(sympy.printing.ccode(helper[1], helper[0]))
output.write("\n")
assert len(cse_results[1]) == 1
output.write(sympy.printing.ccode(cse_results[1][0], "result"))
output.write("\n")
output.seek(0)
return output