MCPcopy
hub / github.com/dask/dask / fractional_slice

Function fractional_slice

dask/layers.py:323–360  ·  view source on GitHub ↗

>>> fractional_slice(('x', 5.1), {0: 2}) ( , ('x', 5), (slice(-2, None, None),)) >>> fractional_slice(('x', 3, 5.1), {0: 2, 1: 3}) ( , ('x', 3, 5), (slice(None, None, None), slice(-3, None, None))) >>> fractional_slice(('x',

(task, axes)

Source from the content-addressed store, hash-verified

321
322
323def fractional_slice(task, axes):
324 """
325
326 >>> fractional_slice(('x', 5.1), {0: 2})
327 (<built-in function getitem>, ('x', 5), (slice(-2, None, None),))
328
329 >>> fractional_slice(('x', 3, 5.1), {0: 2, 1: 3})
330 (<built-in function getitem>, ('x', 3, 5), (slice(None, None, None), slice(-3, None, None)))
331
332 >>> fractional_slice(('x', 2.9, 5.1), {0: 2, 1: 3})
333 (<built-in function getitem>, ('x', 3, 5), (slice(0, 2, None), slice(-3, None, None)))
334 """
335 rounded = (task[0],) + tuple(int(round(i)) for i in task[1:])
336
337 index = []
338 for i, (t, r) in enumerate(zip(task[1:], rounded[1:])):
339 depth = axes.get(i, 0)
340 if isinstance(depth, tuple):
341 left_depth = depth[0]
342 right_depth = depth[1]
343 else:
344 left_depth = depth
345 right_depth = depth
346
347 if t == r:
348 index.append(slice(None, None, None))
349 elif t < r and right_depth:
350 index.append(slice(0, right_depth))
351 elif t > r and left_depth:
352 index.append(slice(-left_depth, None))
353 else:
354 return False
355 index = tuple(index)
356
357 if all(ind == slice(None, None, None) for ind in index):
358 return task
359 else:
360 return (operator.getitem, rounded, index)
361
362
363#

Callers 2

test_fractional_sliceFunction · 0.90
_construct_graphMethod · 0.85

Calls 3

roundFunction · 0.85
allFunction · 0.85
getMethod · 0.45

Tested by 1

test_fractional_sliceFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…