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

Function from_delayed

dask/array/core.py:4190–4234  ·  view source on GitHub ↗

Create a dask array from a dask delayed value This routine is useful for constructing dask arrays in an ad-hoc fashion using dask delayed, particularly when combined with stack and concatenate. The dask array will consist of a single chunk. Examples -------- >>> import das

(value, shape, dtype=None, meta=None, name=None)

Source from the content-addressed store, hash-verified

4188
4189
4190def from_delayed(value, shape, dtype=None, meta=None, name=None):
4191 """Create a dask array from a dask delayed value
4192
4193 This routine is useful for constructing dask arrays in an ad-hoc fashion
4194 using dask delayed, particularly when combined with stack and concatenate.
4195
4196 The dask array will consist of a single chunk.
4197
4198 Examples
4199 --------
4200 >>> import dask
4201 >>> import dask.array as da
4202 >>> import numpy as np
4203 >>> value = dask.delayed(np.ones)(5)
4204 >>> array = da.from_delayed(value, (5,), dtype=float)
4205 >>> array
4206 dask.array<from-value, shape=(5,), dtype=float64, chunksize=(5,), chunktype=numpy.ndarray>
4207 >>> array.compute()
4208 array([1., 1., 1., 1., 1.])
4209 """
4210 from dask.delayed import Delayed, delayed
4211
4212 is_future = False
4213 name = name or "from-value-" + tokenize(value, shape, dtype, meta)
4214 if isinstance(value, TaskRef):
4215 is_future = True
4216 elif not isinstance(value, Delayed) and hasattr(value, "key"):
4217 value = delayed(value)
4218 task = Alias(
4219 key=(name,) + (0,) * len(shape),
4220 target=value.key,
4221 )
4222
4223 dsk = {task.key: task}
4224
4225 if is_future:
4226 dsk[value.key] = value
4227 dependencies = []
4228 else:
4229 dependencies = [value]
4230 chunks = tuple((d,) for d in shape)
4231 # TODO: value._key may not be the name of the layer in value.dask
4232 # This should be fixed after we build full expression graphs
4233 graph = HighLevelGraph.from_collections(name, dsk, dependencies=dependencies)
4234 return Array(graph, name, chunks, dtype=dtype, meta=meta)
4235
4236
4237def from_func(func, shape, dtype=None, name=None, args=(), kwargs=None):

Callers 3

svdFunction · 0.90
test_from_delayedFunction · 0.90
test_from_delayed_metaFunction · 0.90

Calls 5

delayedFunction · 0.90
AliasClass · 0.90
from_collectionsMethod · 0.80
ArrayClass · 0.70
tokenizeFunction · 0.50

Tested by 2

test_from_delayedFunction · 0.72
test_from_delayed_metaFunction · 0.72