| 1436 | |
| 1437 | |
| 1438 | class SubArrayFormat: |
| 1439 | def __init__(self, format_function, **options): |
| 1440 | self.format_function = format_function |
| 1441 | self.threshold = options['threshold'] |
| 1442 | self.edge_items = options['edgeitems'] |
| 1443 | |
| 1444 | def __call__(self, a): |
| 1445 | self.summary_insert = "..." if a.size > self.threshold else "" |
| 1446 | return self.format_array(a) |
| 1447 | |
| 1448 | def format_array(self, a): |
| 1449 | if np.ndim(a) == 0: |
| 1450 | return self.format_function(a) |
| 1451 | |
| 1452 | if self.summary_insert and a.shape[0] > 2 * self.edge_items: |
| 1453 | formatted = ( |
| 1454 | [self.format_array(a_) for a_ in a[:self.edge_items]] |
| 1455 | + [self.summary_insert] |
| 1456 | + [self.format_array(a_) for a_ in a[-self.edge_items:]] |
| 1457 | ) |
| 1458 | else: |
| 1459 | formatted = [self.format_array(a_) for a_ in a] |
| 1460 | |
| 1461 | return "[" + ", ".join(formatted) + "]" |
| 1462 | |
| 1463 | |
| 1464 | class StructuredVoidFormat: |
no outgoing calls
no test coverage detected
searching dependent graphs…