Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play nicer with ndarray subclasses #2486

Merged
merged 3 commits into from Jun 28, 2017
Merged

Conversation

jcrist
Copy link
Member

@jcrist jcrist commented Jun 23, 2017

Two changes:

  • Add subok kwarg to da.from_array.

Mirrors the subok kwarg in np.array. If True, array-like's will be passed through as chunks unchanged. Default is False. This allows avoiding the np.asarray call, making it easier to work with non numpy arrays as chunks.

To make this work we change getarray to a more generic getter function and add a subok parameter. Alternatively we could have kept the same format and created more getter functions, but this would have led to an explosion of functions for all the different combinations
(which seemed less maintainable).

  • Add da.asanyarray

Similar to da.asarray, except avoids the call to np.asarray.

Mirrors the `subok` kwarg in `np.array`. If True, array-like's will be
passed through as chunks unchanged. Default is False. This allows
avoiding the `np.asarray` call, making it easier to work with non numpy
arrays as chunks.

To make this work we change `getarray` to a more generic `getter`
function and add a `subok` parameter. Alternatively we could have kept
the same format and created more getter functions, but this would have
led to an explosion of functions for all the different combinations
(which seemed less maintainable).
Similar to `asarray`, but doesn't convert chunks to instances of
`ndarray`.
@jcrist
Copy link
Member Author

jcrist commented Jun 23, 2017

I'm not sure if subok is the best keyword here, as technically we don't care if they're np.ndarray subclasses (e.g. works fine with sparse.COO which isn't). Perhaps asarray or something would be a better keyword?

@mrocklin
Copy link
Member

Perhaps asarray or something would be a better keyword?

No strong thoughts from me. subok isn't immediately clear to me.

Rename subok kwarg in `from_array` to `asarray`, switch defaults
accordingly.
@jcrist
Copy link
Member Author

jcrist commented Jun 26, 2017

I've switched to use asarray=True as the kwarg. Looks like github is having slowdowns processing events (new commit isn't showing up here), but you can see the commit on my branch. I'm happy to merge pending review/tests passing.

@jcrist
Copy link
Member Author

jcrist commented Jun 28, 2017

Planning to merge later today if no comment.


if lock:
lock.acquire()
try:
c = a[b]
if type(c) != np.ndarray:
if asarray:
c = np.asarray(c)
Copy link
Member

Choose a reason for hiding this comment

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

Any value in making asarray a callable that defaults to np.asarray?

Copy link
Member Author

Choose a reason for hiding this comment

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

Working with it as a boolean makes the optimizations easier to write and reason about. Could be done with a callable, but it'd be a bit trickier. Perhaps hold off until a use case presents itself? I'm not sure when that would be useful.

@mrocklin
Copy link
Member

mrocklin commented Jun 28, 2017 via email

@jcrist jcrist merged commit e9a7cc7 into dask:master Jun 28, 2017
@jcrist jcrist deleted the from-array-no-asarray branch June 28, 2017 20:39
@sinhrks sinhrks added this to the 0.15.1 milestone Aug 30, 2017
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.

None yet

3 participants