Swap & reorder the different chunks in a block.
(
self, mode: Literal["start", "stop", "median"] = "median"
)
| 1427 | tmp_disk[ns] = tmp |
| 1428 | |
| 1429 | def swap_chunks( |
| 1430 | self, mode: Literal["start", "stop", "median"] = "median" |
| 1431 | ) -> None: |
| 1432 | """Swap & reorder the different chunks in a block.""" |
| 1433 | boundsnames = { |
| 1434 | "start": "abounds", |
| 1435 | "stop": "zbounds", |
| 1436 | "median": "mbounds", |
| 1437 | } |
| 1438 | tmp = self.tmp |
| 1439 | sorted_ = tmp.sorted |
| 1440 | indices = tmp.indices |
| 1441 | tmp_sorted = tmp.sorted2 |
| 1442 | tmp_indices = tmp.indices2 |
| 1443 | sorted_lr = tmp.sortedLR |
| 1444 | indices_lr = tmp.indicesLR |
| 1445 | cs = self.chunksize |
| 1446 | ncs = self.nchunkslice |
| 1447 | nsb = self.nslicesblock |
| 1448 | ncb = ncs * nsb |
| 1449 | ncb2 = ncb |
| 1450 | boundsobj = tmp._f_get_child(boundsnames[mode]) |
| 1451 | can_cross_bbounds = self.indsize == 8 and self.nelementsILR > 0 |
| 1452 | for nblock in range(self.nblocks): |
| 1453 | # Protection for last block having less chunks than ncb |
| 1454 | remainingchunks = self.nchunks - nblock * ncb |
| 1455 | if remainingchunks < ncb: |
| 1456 | ncb2 = remainingchunks |
| 1457 | if ncb2 <= 1: |
| 1458 | # if only zero or one chunks remains we are done |
| 1459 | break |
| 1460 | nslices = ncb2 // ncs |
| 1461 | bounds = boundsobj[nblock * ncb : nblock * ncb + ncb2] |
| 1462 | # Do this only if lastrow elements can cross block boundaries |
| 1463 | if nblock == self.nblocks - 1 and can_cross_bbounds: # last block |
| 1464 | nslices += 1 |
| 1465 | ul = self.nelementsILR // cs |
| 1466 | bounds = np.concatenate((bounds, self.bebounds[:ul])) |
| 1467 | sbounds_idx = bounds.argsort(kind=defsort) |
| 1468 | offset = int(nblock * nsb) |
| 1469 | # Swap sorted and indices following the new order |
| 1470 | self.get_neworder( |
| 1471 | sbounds_idx, |
| 1472 | sorted_, |
| 1473 | tmp_sorted, |
| 1474 | sorted_lr, |
| 1475 | nslices, |
| 1476 | offset, |
| 1477 | self.dtype, |
| 1478 | ) |
| 1479 | self.get_neworder( |
| 1480 | sbounds_idx, |
| 1481 | indices, |
| 1482 | tmp_indices, |
| 1483 | indices_lr, |
| 1484 | nslices, |
| 1485 | offset, |
| 1486 | f"u{self.indsize}", |
no test coverage detected