-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display funsor terms nicely when it breaks into multiple lines #512
Labels
enhancement
New feature or request
Comments
How about import black
class Foo:
def __str__(self):
ugly = ...
return black.format_str(ugly, mode=black.FileMode()) for example >>> import black, funsor, torch
>>> funsor.set_backend("torch")
>>> from funsor.torch.distributions import Multinomial
>>> x = Multinomial(10, torch.tensor([[0.2, 0.8], [0.3, 0.7]]))
>>> print(x)
Multinomial(tensor(10.), tensor([[0.2000, 0.8000],
[0.3000, 0.7000]]), value)
>>> print(black.format_str(repr(x), mode=black.FileMode()))
Multinomial(
total_count=tensor(10.0),
probs=tensor([[0.2000, 0.8000], [0.3000, 0.7000]]),
value=value,
) ... though I guess this won't work on large tensors that abbreviate like |
Nice solution! I tested with abbreviation and it seems to work. Together with from funsor import Reals, Tensor, Variable, ops, testing
from funsor.delta import Delta
import black
shape = (3, 2)
point = Tensor(testing.randn(shape))
x = Variable("x", Reals[shape])
actual = Delta("y", point)(y=ops.log(x))
bx = black.format_str(repr(actual), mode=black.FileMode())
print(bx)
from yapf.yapflib.yapf_api import FormatCode
print(FormatCode(bx)[0]) return
This could be the right path for us. I'll try to see if we can avoid extra dependency... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: