fromsymengine.lib.symengine_wrapperimportccode,sympify,Basicfromsymengine.libimportsymengine_wrapperclassCCodePrinter:defdoprint(self,expr,assign_to=None):ifnotisinstance(assign_to,(Basic,type(None),str)):raiseTypeError("{0} cannot assign to object of type {1}".format(type(self).__name__,type(assign_to)))expr=sympify(expr)ifnotassign_to:ifexpr.is_Matrix:raiseRuntimeError("Matrices need a assign_to parameter")returnccode(expr)assign_to=str(assign_to)ifnotexpr.is_Matrix:return"{} = {};".format(assign_to,ccode(expr))code_lines=[]fori,elementinenumerate(expr):code_line='{}[{}] = {};'.format(assign_to,i,element)code_lines.append(code_line)return'\n'.join(code_lines)
[docs]definit_printing(pretty_print=True,use_latex=True):ifpretty_print:ifnotuse_latex:raiseRuntimeError("Only latex is supported for pretty printing")symengine_wrapper.repr_latex[0]=Trueelse:symengine_wrapper.repr_latex[0]=False