(self, indent, summarize, formatter1)
| 204 | |
| 205 | |
| 206 | def _vector_str(self, indent, summarize, formatter1): |
| 207 | # length includes spaces and comma between elements |
| 208 | element_length = formatter1.width() + 2 |
| 209 | elements_per_line = max( |
| 210 | 1, int(math.floor((PRINT_OPTS.linewidth - indent) / (element_length))) |
| 211 | ) |
| 212 | |
| 213 | def _val_formatter(val, formatter1=formatter1): |
| 214 | return formatter1.format(val) |
| 215 | |
| 216 | if summarize and self.size(0) > 2 * PRINT_OPTS.edgeitems: |
| 217 | left_values = _try_convert_to_local_tensor( |
| 218 | self[: PRINT_OPTS.edgeitems] |
| 219 | ).tolist() |
| 220 | right_values = _try_convert_to_local_tensor( |
| 221 | self[-PRINT_OPTS.edgeitems :] |
| 222 | ).tolist() |
| 223 | data = ( |
| 224 | [_val_formatter(val) for val in left_values] |
| 225 | + [" ..."] |
| 226 | + [_val_formatter(val) for val in right_values] |
| 227 | ) |
| 228 | else: |
| 229 | values = _try_convert_to_local_tensor(self).tolist() |
| 230 | data = [_val_formatter(val) for val in values] |
| 231 | |
| 232 | data_lines = [ |
| 233 | data[i : i + elements_per_line] for i in range(0, len(data), elements_per_line) |
| 234 | ] |
| 235 | lines = [", ".join(line) for line in data_lines] |
| 236 | return "[" + ("," + "\n" + " " * (indent + 1)).join(lines) + "]" |
| 237 | |
| 238 | |
| 239 | def _tensor_str_with_formatter(self, indent, summarize, formatter1): |
no test coverage detected