| 3425 | |
| 3426 | |
| 3427 | def _split_up_single_chunk( |
| 3428 | c: int, this_chunksize_tolerance: float, max_chunk_size: int, proposed: int |
| 3429 | ) -> list[int]: |
| 3430 | # Calculate by what factor we have to split this chunk |
| 3431 | m = c / proposed |
| 3432 | if math.ceil(m) / m > this_chunksize_tolerance: |
| 3433 | # We want to smooth things potentially if rounding up would change the result |
| 3434 | # by a lot |
| 3435 | m = math.ceil(c / max_chunk_size) |
| 3436 | else: |
| 3437 | m = math.ceil(m) |
| 3438 | # split the chunk |
| 3439 | new_c, remainder = divmod(c, min(m, c)) |
| 3440 | x = [new_c] * min(m, c) |
| 3441 | for i in range(remainder): |
| 3442 | x[i] += 1 |
| 3443 | return x |
| 3444 | |
| 3445 | |
| 3446 | def round_to(c, s): |