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

Function broadcast_trick

dask/array/wrap.py:143–165  ·  view source on GitHub ↗

Provide a decorator to wrap common numpy function with a broadcast trick. Dask arrays are currently immutable; thus when we know an array is uniform, we can replace the actual data by a single value and have all elements point to it, thus reducing the size. >>> x = np.broadcas

(func)

Source from the content-addressed store, hash-verified

141
142
143def broadcast_trick(func):
144 """
145 Provide a decorator to wrap common numpy function with a broadcast trick.
146
147 Dask arrays are currently immutable; thus when we know an array is uniform,
148 we can replace the actual data by a single value and have all elements point
149 to it, thus reducing the size.
150
151 >>> x = np.broadcast_to(1, (100,100,100))
152 >>> x.base.nbytes
153 8
154
155 Those array are not only more efficient locally, but dask serialisation is
156 aware of the _real_ size of those array and thus can send them around
157 efficiently and schedule accordingly.
158
159 Note that those array are read-only and numpy will refuse to assign to them,
160 so should be safe.
161 """
162 inner = _broadcast_trick_inner(func)
163 inner.__doc__ = func.__doc__
164 inner.__name__ = func.__name__
165 return inner
166
167
168ones = array_creation_dispatch.register_inplace(

Callers 2

_layerMethod · 0.90
wrap.pyFile · 0.85

Calls 1

_broadcast_trick_innerFunction · 0.85

Tested by

no test coverage detected