-
Notifications
You must be signed in to change notification settings - Fork 14
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
Pretty print function for dense tensors #350
Comments
Maybe it's a function in the tensor class, in which case the call might be |
I have a PR up for printing the frontal slices #354. IIRC matlab has a global setting to control the printing precision so my bias would be to use something similar here as well. I haven't tried if our implementation is hooked up correctly where changing the numpy printing format populates correctly for us. |
Thanks, Nick. I would still like this functionality as an option. The numpy-style printing is painful. |
The primary painful piece after having control of the print format, and the frontal slices is just the brackets and a custom name display correct? Or is there some additional functionality that I'm overlooking? |
So, the pain points are:
FWIW, I don't think we necessarily want to change the universal print formatting. I can imagine scenarios where you just want different formats for different purposes in the same file. Here's an updated version that handles 1D and 2D tensors more intelligently and changes the default name to Values.
|
I believe all of those pain points are decisions aligned with numpy conventions. Since that's the defacto scientific library for python it feels like deviating from that would make it harder for a python user to pick things up. I believe pyttb is trying to capture the functionality of the MATLAB tensor toolbox but the aesthetics are not an objective. Here it feels like we are deviating from Python/Numpy standard approaches to better match MATLAB aesthetics. I'll defer to @dmdunla since he is the one allowed to approve incoming PRs |
For MATLAB users accustomed to the TTB for MATLAB, Tammy's suggestion makes sense. However, as Nick points out, this moves away from Python/NumPy conventions and thus would be distracting to people accustomed to pythonic standards. Here are my suggestions:
I do not think there is a single solution that will both aligh with both MATLAB and Python conventions, so the above are an attempt at some compromise. This is my take ATM, and I'm open to more discussion. |
SG. If we are accommodating this then I think it makes sense to create |
Great idea. I like the separation of |
Ok I added |
This all sounds great. Thanks! One naive question about the broader setup. Why not just have matlab_print be a function for each object? I'm not sure what having pyttb.matlab_support buys. Is it just called matlab_print(X) versus X.matlab_print()? |
Functionally it is the same. But it makes it more obvious that there is a standard way and non-standard way. The non-standard way requires importing something else that is explicit this is a compatibility approach rather than something core to pyttb. In python underscore methods are internal components so while a user could type In mind the breakdown of users are:
Ideally no one from the first two categories need or want to use MATLAB support, and overtime the users in the last category become users in the first. |
Would it be possible to add a pretty print function for dense tensors. Here is what I have in mind:
So
pretty_print_tensor(X,fmt="2d",name="X")
produces output like this:Or
pretty_print_tensor(X,fmt="5.1f")
for a different tensor produces:The text was updated successfully, but these errors were encountered: