Compute a map with the interesting chunks in index.
(self)
| 2324 | return (start, stop) |
| 2325 | |
| 2326 | def get_chunkmap(self) -> np.ndarray: |
| 2327 | """Compute a map with the interesting chunks in index.""" |
| 2328 | if profile: |
| 2329 | tref = clock() |
| 2330 | if profile: |
| 2331 | show_stats("Entering get_chunkmap", tref) |
| 2332 | ss = self.slicesize |
| 2333 | nsb = self.nslicesblock |
| 2334 | nslices = self.nslices |
| 2335 | lbucket = self.lbucket |
| 2336 | indsize = self.indsize |
| 2337 | bucketsinblock = self.blocksize / lbucket |
| 2338 | nchunks = math.ceil(self.nelements / lbucket) |
| 2339 | chunkmap = np.zeros(shape=nchunks, dtype="bool") |
| 2340 | reduction = self.reduction |
| 2341 | starts = (self.starts - 1) * reduction + 1 |
| 2342 | stops = (self.starts + self.lengths) * reduction |
| 2343 | starts[starts < 0] = 0 # All negative values set to zero |
| 2344 | indices = self.indices |
| 2345 | for nslice in range(self.nrows): |
| 2346 | start = starts[nslice] |
| 2347 | stop = stops[nslice] |
| 2348 | if stop > start: |
| 2349 | idx = np.empty(shape=stop - start, dtype="u%d" % indsize) |
| 2350 | if nslice < nslices: |
| 2351 | indices._read_index_slice(nslice, start, stop, idx) |
| 2352 | else: |
| 2353 | self.indicesLR._read_index_slice(start, stop, idx) |
| 2354 | if indsize == 8: |
| 2355 | idx //= np.asarray(lbucket).astype(idx.dtype) |
| 2356 | elif indsize == 2: |
| 2357 | # The chunkmap size cannot be never larger than 'int_' |
| 2358 | idx = idx.astype("int_") |
| 2359 | offset = int((nslice // nsb) * bucketsinblock) |
| 2360 | idx += offset |
| 2361 | elif indsize == 1: |
| 2362 | # The chunkmap size cannot be never larger than 'int_' |
| 2363 | idx = idx.astype("int_") |
| 2364 | offset = (nslice * ss) // lbucket |
| 2365 | idx += offset |
| 2366 | chunkmap[idx] = True |
| 2367 | # The case lbucket < nrowsinchunk should only happen in tests |
| 2368 | nrowsinchunk = self.nrowsinchunk |
| 2369 | if lbucket != nrowsinchunk: |
| 2370 | # Map the 'coarse grain' chunkmap into the 'true' chunkmap |
| 2371 | nelements = self.nelements |
| 2372 | tnchunks = math.ceil(nelements / nrowsinchunk) |
| 2373 | tchunkmap = np.zeros(shape=tnchunks, dtype="bool") |
| 2374 | ratio = lbucket / nrowsinchunk |
| 2375 | idx = chunkmap.nonzero()[0] |
| 2376 | starts = (idx * ratio).astype("int_") |
| 2377 | stops = np.ceil((idx + 1) * ratio).astype("int_") |
| 2378 | for start, stop in zip(starts, stops): |
| 2379 | tchunkmap[start:stop] = True |
| 2380 | chunkmap = tchunkmap |
| 2381 | if profile: |
| 2382 | show_stats("Exiting get_chunkmap", tref) |
| 2383 | return chunkmap |
no test coverage detected