Skip to content

Array.__getitem__ should consider array.chunk-size for concrete indexers? #6270

Closed

Description

@TomAugspurger

Reported in pydata/xarray#4112, where xarray calling Array.__getitem__ resulted in an unbalanced Array.

import dask.array

arr = dask.array.from_array([0, 1, 2, 3], chunks=(1,))
print(arr.chunks)  # ((1, 1, 1, 1),)
# align calls reindex which indexes with something like this
indexer = [0, 1, 2, 3, ] + [-1,] * 111
print(arr[indexer].chunks)  # ((1, 1, 1, 112),)

That last chunk is large, since all of the -1s are in the same input chunk.

To be explicit, the user could chunk the indexer:

# maybe something like this is a solution
lazy_indexer = dask.array.from_array(indexer, chunks=arr.chunks[0][0], name="idx")
print(arr[lazy_indexer].chunks) # ((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1),)

If the indexer isn't chunked, perhaps dask could examine the input array and indexer and chunk the indexer if we detect that the output chunksize would exceed dask.config.get('array.chunk-size')?

Activity

  1. shoyer commented on Jun 13, 2020

    @shoyer
    Member

    If the indexer isn't chunked, perhaps dask could examine the input array and indexer and chunk the indexer if we detect that the output chunksize would exceed dask.config.get('array.chunk-size')?

    I think this strategy could work well for chunking arr[indexer] if any chunks would exceed some maximum chunk sizes.

    However, I wouldn't implement this via chunking indexer. This removes information about which source chunks different parts of the indexer refer to, which makes indexing require a quadratic number of tasks.

  2. added a commit that references this issue on Aug 14, 2020
    ac9a618
  3. added a commit that references this issue on Sep 9, 2020
    99ea30d
  4. added a commit that references this issue on Oct 29, 2020
    81fc297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions