Append the array to the last row index objects.
(
self, xarr: list[np.ndarray], update: bool = False
)
| 817 | show_stats("Exiting append", tref) |
| 818 | |
| 819 | def append_last_row( |
| 820 | self, xarr: list[np.ndarray], update: bool = False |
| 821 | ) -> None: |
| 822 | """Append the array to the last row index objects.""" |
| 823 | if profile: |
| 824 | tref = clock() |
| 825 | if profile: |
| 826 | show_stats("Entering appendLR", tref) |
| 827 | # compute the elements in the last row sorted & bounds array |
| 828 | nrows = self.nslices |
| 829 | if not update and self.temp_required: |
| 830 | where = self.tmp |
| 831 | # The reduction will take place *after* the optimization process |
| 832 | reduction = 1 |
| 833 | else: |
| 834 | where = self |
| 835 | reduction = self.reduction |
| 836 | indices_lr = where.indicesLR |
| 837 | sorted_lr = where.sortedLR |
| 838 | larr, arr, idx = self.initial_append(xarr, nrows, reduction) |
| 839 | nelements_slr = len(arr) |
| 840 | nelements_ilr = len(idx) |
| 841 | # Build the cache of bounds |
| 842 | rchunksize = self.chunksize // reduction |
| 843 | self.bebounds = np.concatenate((arr[::rchunksize], [larr])) |
| 844 | # The number of elements will be saved as an attribute |
| 845 | sorted_lr.attrs.nelements = nelements_slr |
| 846 | indices_lr.attrs.nelements = nelements_ilr |
| 847 | # Save the number of elements, bounds and sorted values |
| 848 | # at the end of the sorted array |
| 849 | offset2 = len(self.bebounds) |
| 850 | sorted_lr[nelements_slr : nelements_slr + offset2] = self.bebounds |
| 851 | sorted_lr[:nelements_slr] = arr |
| 852 | del arr |
| 853 | # Now that arr is gone, we can upcast the indices and add the offset |
| 854 | if self.indsize == 4: |
| 855 | idx = self.final_idx32(idx, nrows * self.slicesize) |
| 856 | # Save the reverse index array |
| 857 | indices_lr[: len(idx)] = idx |
| 858 | del idx |
| 859 | # Update counters after a successful append |
| 860 | self.nrows = nrows + 1 |
| 861 | self.nelements = nrows * self.slicesize + nelements_ilr |
| 862 | self.nelementsILR = nelements_ilr |
| 863 | self.nelementsSLR = nelements_slr |
| 864 | self.dirtycache = True # the cache is dirty now |
| 865 | if profile: |
| 866 | show_stats("Exiting appendLR", tref) |
| 867 | |
| 868 | def optimize(self, verbose: bool = False) -> None: |
| 869 | """Optimize an index so as to allow faster searches. |
no test coverage detected