Vladimir Perić
unread,Apr 18, 2016, 5:27:17 PM4/18/16Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sy...@googlegroups.com
Hi all,
I want to define some (simple) custom functions, so I could provide my
own `_imp_` for lambdify and for other benefits. I managed to program
the numerical evolution, but I'm struggling with pretty printing. I'm
trying to emulate sympy/printing/pretty/pretty/_pretty_Function, but I
barely understand the code and it feels like a hack. I'd be very much
obliged if someone could give me a simple primer on how to accomplish
what I want:
Essentially, I have a hinge function, which is defined as `max(0,
x-thr)` , where x is a vector and thr is a predefined scalar (and can
be 0). This is the code I currently have:
def _pretty(self, printer, *args):
from sympy.printing.pretty.stringpict import prettyForm, stringPict
prettyFunc = printer._print('Max')
args = self.args + (0,)
prettyArgs = prettyForm(*printer._print_seq(args).parens())
pform = prettyForm(binding=prettyForm.FUNC,
*stringPict.next(prettyFunc, prettyArgs))
return pform
Which produces the results I want. However, I really don't understand
what most of the code actually does. Is there a simpler way of writing
this? It realls feels like there should be.
Thanks in advance,
--
Vladimir Perić