Skip to content

Docstring of dask.array.coarsen should provide more details on valid reduction functions #9825

@jni

Description

@jni

The dask.array.coarsen documentation provides little detail about the requirements of its reduction argument:

dask/dask/array/chunk.py

Lines 87 to 88 in 6d639d2

reduction: function
Function like np.sum, np.mean, etc...

Looking at the relevant part of the implementation:

dask/dask/array/chunk.py

Lines 133 to 136 in 6d639d2

# (10, 10) -> (5, 2, 5, 2)
newshape = tuple(concat([(x.shape[i] // axes[i], axes[i]) for i in range(x.ndim)]))
return reduction(x.reshape(newshape), axis=tuple(range(1, x.ndim * 2, 2)), **kwargs)

It seems to me that the requirements on the reduction function are:

  • it should be able to take an array as the first argument, and
  • it should be able to take in a tuple of axes as an axis= argument, and
  • it should be able to not instantiate the input dask array (?). ie does the reduction function of np. only work because of __array_function__ dispatch? Or am I missing some other magic here?

Obviously I'm not super clear on the last one, or whether I'm missing some, and would love some guidance from people more familiar with this function, after which I'd be happy to make a PR or leave this as a good-first-issue for some dask hackathons. 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraydocumentationImprove or add to documentationneeds attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions