tensorflow / tensorflow/tensorflow

Make line wrapping and precision of tf.print configurable.

Open
#52,960 5 comments 0 reactions 1 assignee View on GitHub

@sachinprasadhs is already working on this.

Since Nov 5, 2021.

2.6.0 comp:ops stat:awaiting tensorflower type:feature
Dominant language
C++
Stars
200k
Forks
76.9k
Avg merge
2d 3h
Merged PRs (30d)
433

Description

Please make sure that this is a feature request. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:feature_template

System information

  • TensorFlow version (you are using): not relevant
  • Are you willing to contribute it (Yes/No): Yes

Describe the feature and the current behavior/state.
tf.print() wraps past the 4th element for me. Output from printing an (N, 7, 7), where N=2 in this case, looks like this:

[[[ 5.62430954e+00 -3.49580956e+00 -8.04360168e+02 -5.40295654e+02
   -8.65279853e-01 -1.06588173e+00 -1.18294978e+00]
  [-3.49580956e+00  7.82608986e+00  4.73972961e+02  1.18741919e+03
    1.61477351e+00  1.88551021e+00  1.97545743e+00]
  [-8.04360168e+02  4.73972961e+02  1.31743172e+05  7.44966484e+04
    2.14444519e+02  2.22681152e+02  1.98635208e+02]
  [-5.40295654e+02  1.18741919e+03  7.44966484e+04  1.97479641e+05
    2.52062241e+02  2.85624451e+02  2.64948578e+02]
  [-8.65279853e-01  1.61477351e+00  2.14444519e+02  2.52062241e+02
    3.18258524e+00  2.82087207e+00  2.33711910e+00]
  [-1.06588173e+00  1.88551021e+00  2.22681152e+02  2.85624451e+02
    2.82087207e+00  2.64690948e+00  2.28564334e+00]
  [-1.18294978e+00  1.97545743e+00  1.98635208e+02  2.64948578e+02
    2.33711910e+00  2.28564334e+00  2.24237132e+00]]

 [[ 6.57234287e+00 -4.52555466e+00 -1.04999585e+03 -7.79698792e+02
   -1.47998118e+00 -2.11049843e+00 -4.34581661e+00]
  [-4.52555466e+00  8.80841637e+00  7.03340576e+02  1.52776123e+03
    2.77018666e+00  3.56193233e+00  6.32034349e+00]
  [-1.04999585e+03  7.03340576e+02  1.78551625e+05  1.23507805e+05
    4.00629730e+01  1.89105148e+02  5.56380432e+02]
  [-7.79698792e+02  1.52776123e+03  1.23507805e+05  2.79413969e+05
    3.76035431e+02  5.24331360e+02  1.04614160e+03]
  [-1.47998118e+00  2.77018666e+00  4.00629730e+01  3.76035431e+02
    1.25411425e+01  1.00502367e+01  9.19474983e+00]
  [-2.11049843e+00  3.56193233e+00  1.89105148e+02  5.24331360e+02
    1.00502367e+01  9.68517876e+00  1.09725800e+01]
  [-4.34581661e+00  6.32034349e+00  5.56380432e+02  1.04614160e+03
    9.19474983e+00  1.09725800e+01  1.55766268e+01]]]

I work a lot with these fixed-sized matrices (eg: 7x7, or 9x9). Debugging those is hard with line wrapping.
I'd like to get them all 7 elements of the matrix row on one line, at least. Additionally, I would fancy having less precision, as that is not that informative to debug.

Will this change the current api? How?
Either have like numpy a set_print_options(), or have extra arguments to tf.print along the lines of line_length=None (where None means "no wrapping at all") and format="%12.7e" where I could specify for example format="%10.4f".
I am slightly in favor of the custom options per tf.print() call to allow granular control.

Who will benefit with this feature?
Most likely anyone debugging stuff with matrices.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.