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

Function getter

dask/array/core.py:122–145  ·  view source on GitHub ↗
(a, b, asarray=True, lock=None)

Source from the content-addressed store, hash-verified

120
121
122def getter(a, b, asarray=True, lock=None):
123 if isinstance(b, tuple) and any(x is None for x in b):
124 b2 = tuple(x for x in b if x is not None)
125 b3 = tuple(
126 None if x is None else slice(None, None)
127 for x in b
128 if not isinstance(x, Integral)
129 )
130 return getter(a, b2, asarray=asarray, lock=lock)[b3]
131
132 if lock:
133 lock.acquire()
134 try:
135 c = a[b]
136 # Below we special-case `np.matrix` to force a conversion to
137 # `np.ndarray` and preserve original Dask behavior for `getter`,
138 # as for all purposes `np.matrix` is array-like and thus
139 # `is_arraylike` evaluates to `True` in that case.
140 if asarray and (not is_arraylike(c) or isinstance(c, np.matrix)):
141 c = np.asarray(c)
142 finally:
143 if lock:
144 lock.release()
145 return c
146
147
148def getter_nofancy(a, b, asarray=True, lock=None):

Callers 5

test_getterFunction · 0.90
partial_reduceFunction · 0.85
getter_nofancyFunction · 0.85
getter_inlineFunction · 0.85
chunksMethod · 0.85

Calls 4

anyFunction · 0.90
is_arraylikeFunction · 0.90
acquireMethod · 0.45
releaseMethod · 0.45

Tested by 1

test_getterFunction · 0.72