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)
| 141 | |
| 142 | |
| 143 | def 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 | |
| 168 | ones = array_creation_dispatch.register_inplace( |
no test coverage detected