Returns a summarized string representation of eager `tensor`. Args: tensor: EagerTensor to summarize summarize: Include these many first elements of `array`
(tensor, summarize=None)
| 76 | |
| 77 | |
| 78 | def _summarize_eager(tensor, summarize=None): |
| 79 | """Returns a summarized string representation of eager `tensor`. |
| 80 | |
| 81 | Args: |
| 82 | tensor: EagerTensor to summarize |
| 83 | summarize: Include these many first elements of `array` |
| 84 | """ |
| 85 | # Emulate the behavior of Tensor::SummarizeValue() |
| 86 | if summarize is None: |
| 87 | summarize = 3 |
| 88 | elif summarize < 0: |
| 89 | summarize = array_ops.size(tensor) |
| 90 | |
| 91 | # reshape((-1,)) is the fastest way to get a flat array view |
| 92 | if tensor._rank(): # pylint: disable=protected-access |
| 93 | flat = tensor.numpy().reshape((-1,)) |
| 94 | lst = [str(x) for x in flat[:summarize]] |
| 95 | if len(lst) < flat.size: |
| 96 | lst.append("...") |
| 97 | else: |
| 98 | # tensor.numpy() returns a scalar for zero dimensional arrays |
| 99 | if gen_math_ops.not_equal(summarize, 0): |
| 100 | lst = [str(tensor.numpy())] |
| 101 | else: |
| 102 | lst = [] |
| 103 | |
| 104 | return ", ".join(lst) |
| 105 | |
| 106 | |
| 107 | # pylint: disable=protected-access |