Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

A _repr_html_ for a matchpy expression. #6

Closed
tonyfast opened this issue Oct 25, 2018 · 6 comments
Closed

A _repr_html_ for a matchpy expression. #6

tonyfast opened this issue Oct 25, 2018 · 6 comments
Milestone

Comments

@tonyfast
Copy link

In the web view, a pure html representation might be better for the matchpy...Expressions

 import pprint, black, vdom, matchpy, IPython; IPython.get_ipython().display_formatter.formatters['text/html'].for_type(
        matchpy.expressions.expressions.Expression, lambda str: vdom.pre(vdom.code((black).format_str(pprint.pformat(str), 100)))._repr_html_()
    )

This snippet is meant to be registered in a notebook to demonstrate the idea.

@tonyfast
Copy link
Author

Here is a sample view:

image

@pearu
Copy link
Contributor

pearu commented Oct 25, 2018

Perhaps offtopic: while looking at the repr tree of an expression is useful, it disturbs the mathematical interpretation by a human. Would it make sense to invent a less verbose representation of such a tree, for instance:

BOp
  A(shape=None)[1][0][2]
  *
  InnerProduct
    A(shape=A_shape[2])
    ...

or similar in terms of verbosity?

@saulshanabrook
Copy link
Collaborator

@pearu Yes that is a good idea. The __str__ version does this partially, but it doesn't do any indenting. It might be nice to have a __str__ pprint version as well as a __repr__ pprint version

@saulshanabrook
Copy link
Collaborator

I have this kind of pretty printing now working in jupyter notebooks: https://github.com/Quansight-Labs/uarray/blob/master/uarray/uarray/printing.py

@tonyfast
Copy link
Author

You may prefer the IPython machinery for registering your reprs.

    def load_ipython_extension(ip):
        ip.display_formatter.formatters['text/plain'].for_type(matchpy.Operation, repr_pretty)

This would avoid some hard coding the reprs.

More info @ https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display

@saulshanabrook
Copy link
Collaborator

Ah nice thanks for that code snippet. Reopening this to adopt that

@saulshanabrook saulshanabrook transferred this issue from Quansight-Labs/uarray Mar 12, 2019
@saulshanabrook saulshanabrook added this to the Future milestone Mar 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants