MCPcopy Index your code
hub / github.com/dask/dask / _construct_graph

Method _construct_graph

dask/layers.py:202–253  ·  view source on GitHub ↗

Construct graph for a simple overlap operation.

(self, deserializing=False)

Source from the content-addressed store, hash-verified

200 return result
201
202 def _construct_graph(self, deserializing=False):
203 """Construct graph for a simple overlap operation."""
204 axes = self.axes
205 chunks = self.chunks
206 name = self.name
207 dask_keys = self._dask_keys()
208
209 getitem_name = f"getitem-{self.token}"
210 overlap_name = f"overlap-{self.token}"
211
212 if deserializing:
213 # Use CallableLazyImport objects to avoid importing dataframe
214 # module on the scheduler
215 concatenate_shaped = CallableLazyImport(
216 "dask.array.core.concatenate_shaped"
217 )
218 else:
219 # Not running on distributed scheduler - Use explicit functions
220 from dask.array.core import concatenate_shaped
221
222 dims = list(map(len, chunks))
223 expand_key2 = functools.partial(
224 _expand_keys_around_center, dims=dims, axes=axes
225 )
226
227 # Make keys for each of the surrounding sub-arrays
228 interior_keys = toolz.pipe(
229 dask_keys,
230 flatten,
231 map(expand_key2),
232 map(lambda a: a[0]),
233 map(flatten),
234 toolz.concat,
235 list,
236 )
237 interior_slices = {}
238 overlap_blocks = {}
239 for k in interior_keys:
240 frac_slice = fractional_slice((name,) + k, axes)
241 if frac_slice is False:
242 continue
243 if (name,) + k != frac_slice:
244 interior_slices[(getitem_name,) + k] = frac_slice
245 else:
246 interior_slices[(getitem_name,) + k] = (name,) + k
247 overlap_blocks[(overlap_name,) + k] = (
248 concatenate_shaped,
249 *(expand_key2((None,) + k, name=getitem_name)),
250 )
251
252 dsk = toolz.merge(interior_slices, overlap_blocks)
253 return dsk
254
255
256def _expand_keys_around_center(k, dims, name=None, axes=None):

Callers 1

_dictMethod · 0.95

Calls 5

_dask_keysMethod · 0.95
CallableLazyImportClass · 0.85
fractional_sliceFunction · 0.85
pipeMethod · 0.80
mergeMethod · 0.45

Tested by

no test coverage detected