def __init__(self, printer=None, dummify=False): self._dummify = dummify #XXX: This has to be done here because of circular imports from sympy.printing.lambdarepr import LambdaPrinter if printer is None: printer = LambdaPrinter() if inspect.isfunction(printer): self._exprrepr = printer else: if inspect.isclass(printer): printer = printer() self._exprrepr = printer.doprint #if hasattr(printer, '_print_Symbol'): # symbolrepr = printer._print_Symbol #if hasattr(printer, '_print_Dummy'): # dummyrepr = printer._print_Dummy # Used to print the generated function arguments in a standard way self._argrepr = LambdaPrinter().doprint
def __init__(self): if 'allow_unknown_functions' in LambdaPrinter._default_settings: settings = {'allow_unknown_functions': True} else: # We're on Sympy without "allow_unknown_functions" setting settings = {} LambdaPrinter.__init__(self, settings=settings) self.known_functions = {} self.known_constants = {'pi': 'pi', 'Pi': 'pi', 'I': 'I'}
def test_issue_14911(): class Variable(sympy.Symbol): def _sympystr(self, printer): return printer.doprint(self.name) _lambdacode = _sympystr _numpycode = _sympystr x = Variable('x') y = 2 * x code = LambdaPrinter().doprint(y) assert code.replace(' ', '') == '2*x'
def test_printmethod(): # In each case, printmethod is called to test # its working obj = CustomPrintedObject() assert LambdaPrinter().doprint(obj) == 'lambda' assert TensorflowPrinter().doprint(obj) == 'tensorflow' assert NumExprPrinter().doprint(obj) == "evaluate('numexpr', truediv=True)"
def test_printmethod(): # In each case, printmethod is called to test # its working obj = CustomPrintedObject() assert LambdaPrinter().doprint(obj) == 'lambda' assert TensorflowPrinter().doprint(obj) == 'tensorflow' assert NumExprPrinter().doprint(obj) == "evaluate('numexpr', truediv=True)" assert NumExprPrinter().doprint(Piecewise((y, x >= 0), (z, x < 0))) == \ "evaluate('where((x >= 0), y, z)', truediv=True)"
def test_sqrt(): prntr = LambdaPrinter({'standard': 'python2'}) assert prntr._print_Pow(sqrt(x), rational=False) == 'sqrt(x)' assert prntr._print_Pow(sqrt(x), rational=True) == 'x**(1./2.)' prntr = LambdaPrinter({'standard': 'python3'}) assert prntr._print_Pow(sqrt(x), rational=True) == 'x**(1/2)'
def test_sqrt(): prntr = LambdaPrinter({"standard": "python2"}) assert prntr._print_Pow(sqrt(x), rational=False) == "sqrt(x)" assert prntr._print_Pow(sqrt(x), rational=True) == "x**(1./2.)" prntr = LambdaPrinter({"standard": "python3"}) assert prntr._print_Pow(sqrt(x), rational=True) == "x**(1/2)"
def __init__(self): LambdaPrinter.__init__(self) self.known_functions = {} self.known_constants = {'pi': 'pi', 'Pi': 'pi'}