Skip to content

Use concatenate_lookup in concatenate#6339

Merged
TomAugspurger merged 3 commits intodask:masterfrom
jakirkham:use_concatenate_lookup
Jun 23, 2020
Merged

Use concatenate_lookup in concatenate#6339
TomAugspurger merged 3 commits intodask:masterfrom
jakirkham:use_concatenate_lookup

Conversation

@jakirkham
Copy link
Member

@jakirkham jakirkham commented Jun 22, 2020

Fixes #5008

As we sometimes need to have custom ways to dispatch concatenate over different array types like SciPy's or CuPy's sparse matrices, make sure we lookup the appropriate concatenate implementation and use that.

  • Tests added / passed
  • Passes black dask / flake8 dask

@TomAugspurger
Copy link
Member

Thanks @jakirkham. I can confirm that this fixes things for dask/dask-ml#685.

@jakirkham
Copy link
Member Author

Thanks for confirming Tom 🙂

Looks like it is passing on CI too. Travis CI isn't showing up for me on the status indicator, but the build did pass here. I'll work on some tests as well.

@jakirkham jakirkham marked this pull request as ready for review June 23, 2020 03:13
@jakirkham jakirkham changed the title WIP: Use concatenate_lookup in concatenate Use concatenate_lookup in concatenate Jun 23, 2020
@jakirkham
Copy link
Member Author

@pentschev @cjnolet, it would be good if you could both take a look 🙂

@jakirkham jakirkham force-pushed the use_concatenate_lookup branch 4 times, most recently from 588db14 to 52c1ef1 Compare June 23, 2020 05:15
As we sometimes need to have custom ways to dispatch `concatenate` over
different array types like SciPy's or CuPy's sparse matrices, make sure
we lookup the appropriate `concatenate` implementation and use that.
@jakirkham jakirkham force-pushed the use_concatenate_lookup branch from 52c1ef1 to 60fdbf1 Compare June 23, 2020 05:21
@jakirkham
Copy link
Member Author

Have added tests for SciPy and CuPy sparse matrices. Also have tested with a pre-release of CuPy 8. Since CuPy sparse matrices need PR ( cupy/cupy#2665 ) for concatenation support.

@jakirkham jakirkham force-pushed the use_concatenate_lookup branch from 60fdbf1 to e3f3e36 Compare June 23, 2020 05:37
Copy link
Member

@pentschev pentschev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes make sense to me, thanks for doing that @jakirkham .

Copy link
Member

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One question inline.

meta = np.concatenate([meta_from_array(s) for s in seq], axis=axis)
seq_metas = [meta_from_array(s) for s in seq]
_concatenate = concatenate_lookup.dispatch(
type(max(seq_metas, key=lambda x: getattr(x, "__array_priority__", 0)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we do similar things with __array_priority__ in other places where we use concat?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I actually took it from some concatenation code for creating a concrete result from a Dask Array above

dask/dask/array/core.py

Lines 298 to 300 in 4d7e674

concatenate = concatenate_lookup.dispatch(
type(max(arrays, key=lambda x: getattr(x, "__array_priority__", 0)))
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks.

@cjnolet
Copy link
Contributor

cjnolet commented Jun 23, 2020

This LGTM. Thanks @jakirkham!

@TomAugspurger TomAugspurger merged commit 8bf737b into dask:master Jun 23, 2020
@TomAugspurger
Copy link
Member

Thanks @jakirkham!

@jakirkham
Copy link
Member Author

Thanks all! 😄

@jakirkham jakirkham deleted the use_concatenate_lookup branch June 23, 2020 18:24
kumarprabhu1988 pushed a commit to kumarprabhu1988/dask that referenced this pull request Oct 29, 2020
* Use `concatenate_lookup` in `concatenate`

As we sometimes need to have custom ways to dispatch `concatenate` over
different array types like SciPy's or CuPy's sparse matrices, make sure
we lookup the appropriate `concatenate` implementation and use that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concatenate Array[sparse] raises ValueError

4 participants