Chunks tuple from nested list of arrays >>> x = np.array([1, 2]) >>> chunks_from_arrays([x, x]) ((2, 2),) >>> x = np.array([[1, 2]]) >>> chunks_from_arrays([[x], [x]]) ((1, 1), (2,)) >>> x = np.array([[1, 2]]) >>> chunks_from_arrays([[x, x]]) ((1,), (2, 2))
(arrays)
| 5426 | |
| 5427 | |
| 5428 | def chunks_from_arrays(arrays): |
| 5429 | """Chunks tuple from nested list of arrays |
| 5430 | |
| 5431 | >>> x = np.array([1, 2]) |
| 5432 | >>> chunks_from_arrays([x, x]) |
| 5433 | ((2, 2),) |
| 5434 | |
| 5435 | >>> x = np.array([[1, 2]]) |
| 5436 | >>> chunks_from_arrays([[x], [x]]) |
| 5437 | ((1, 1), (2,)) |
| 5438 | |
| 5439 | >>> x = np.array([[1, 2]]) |
| 5440 | >>> chunks_from_arrays([[x, x]]) |
| 5441 | ((1,), (2, 2)) |
| 5442 | |
| 5443 | >>> chunks_from_arrays([1, 1]) |
| 5444 | ((1, 1),) |
| 5445 | """ |
| 5446 | if not arrays: |
| 5447 | return () |
| 5448 | result = [] |
| 5449 | dim = 0 |
| 5450 | |
| 5451 | def shape(x): |
| 5452 | try: |
| 5453 | return x.shape or (1,) |
| 5454 | except AttributeError: |
| 5455 | return (1,) |
| 5456 | |
| 5457 | while isinstance(arrays, (list, tuple)): |
| 5458 | result.append(tuple(shape(deepfirst(a))[dim] for a in arrays)) |
| 5459 | arrays = arrays[0] |
| 5460 | dim += 1 |
| 5461 | return tuple(result) |
| 5462 | |
| 5463 | |
| 5464 | def deepfirst(seq): |
no test coverage detected
searching dependent graphs…