MCPcopy Create free account
hub / github.com/dask/dask / _slice_1d

Function _slice_1d

dask/array/slicing.py:378–542  ·  view source on GitHub ↗

Returns a dict of {blocknum: slice} This function figures out where each slice should start in each block for a single dimension. If the slice won't return any elements in the block, that block will not be in the output. Parameters ---------- dim_shape - the number of elem

(dim_shape, lengths, index)

Source from the content-addressed store, hash-verified

376
377
378def _slice_1d(dim_shape, lengths, index):
379 """Returns a dict of {blocknum: slice}
380
381 This function figures out where each slice should start in each
382 block for a single dimension. If the slice won't return any elements
383 in the block, that block will not be in the output.
384
385 Parameters
386 ----------
387
388 dim_shape - the number of elements in this dimension.
389 This should be a positive, non-zero integer
390 blocksize - the number of elements per block in this dimension
391 This should be a positive, non-zero integer
392 index - a description of the elements in this dimension that we want
393 This might be an integer, a slice(), or an Ellipsis
394
395 Returns
396 -------
397
398 dictionary where the keys are the integer index of the blocks that
399 should be sliced and the values are the slices
400
401 Examples
402 --------
403
404 Trivial slicing
405
406 >>> _slice_1d(100, [60, 40], slice(None, None, None))
407 {0: slice(None, None, None), 1: slice(None, None, None)}
408
409 100 length array cut into length 20 pieces, slice 0:35
410
411 >>> _slice_1d(100, [20, 20, 20, 20, 20], slice(0, 35))
412 {0: slice(None, None, None), 1: slice(0, 15, 1)}
413
414 Support irregular blocks and various slices
415
416 >>> _slice_1d(100, [20, 10, 10, 10, 25, 25], slice(10, 35))
417 {0: slice(10, 20, 1), 1: slice(None, None, None), 2: slice(0, 5, 1)}
418
419 Support step sizes
420
421 >>> _slice_1d(100, [15, 14, 13], slice(10, 41, 3))
422 {0: slice(10, 15, 3), 1: slice(1, 14, 3), 2: slice(2, 12, 3)}
423
424 >>> _slice_1d(100, [20, 20, 20, 20, 20], slice(0, 100, 40)) # step > blocksize
425 {0: slice(0, 20, 40), 2: slice(0, 20, 40), 4: slice(0, 20, 40)}
426
427 Also support indexing single elements
428
429 >>> _slice_1d(100, [20, 20, 20, 20, 20], 25)
430 {1: 5}
431
432 And negative slicing
433
434 >>> _slice_1d(100, [20, 20, 20, 20, 20], slice(100, 0, -3)) # doctest: +NORMALIZE_WHITESPACE
435 {4: slice(-1, -21, -3),

Callers 3

test_slice_1dFunction · 0.90
new_blockdimFunction · 0.85

Calls 4

cached_cumsumFunction · 0.90
minFunction · 0.85
maxFunction · 0.85
itemsMethod · 0.45

Tested by 2

test_slice_1dFunction · 0.72