Modify mean chunk functions to return dicts rather than arrays (#4513)
Modify mean chunk functions to return dicts rather than arrays (#4513)

These functions return two array chunks each:

1.  The sum of the array
2.  The counts of the array

We need to return these as a single intermediate value.

Previously we did this by constructing an empty numpy array and then
assigning into it.  This doesn't work as well with numpy-like arrays
like cupy and sparse.

Now we return a dict containing two arrays.  This is nice in a few ways,
but does mean that we need to replicate the `concatenate=`
functionality within our chunk aggregation and combine functions, which
can be tricky.  This commit fails to do it correctly, but may be a good
start.

After this we would like to implement the same fix for other functions,
notably the `moment_*` functions in this same reductions.py file.

Fixes https://github.com/dask/dask/issues/4481
dask/dask,ContinuumIO/dask,blaze/dask,mrocklin/dask,jcrist/dask,mrocklin/dask,ContinuumIO/dask,dask/dask,jakirkham/dask,jakirkham/dask,jcrist/dask,blaze/dask