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

Adds choose method to dask.array.Array #2584

Merged
merged 4 commits into from Aug 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions dask/array/core.py
Expand Up @@ -1307,6 +1307,10 @@ def ravel(self):

flatten = ravel

@wraps(np.choose)
def choose(self, choices):
return elemwise(variadic_choose, self, *choices)
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense for this to just call the function implementation or vice versa?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point! It probably makes more sense to just implement choose on a dask Array once. I'll change the PR to have the choose function simply call the choose method on an input dask array.

Copy link
Member

Choose a reason for hiding this comment

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

Personal preference, but I'd rather have the method call the function (smaller diff too). Not a big deal though, up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hey @jcrist, yeah I can switch it so that the method calls the function. I don't have a strong preference either way.

Copy link
Member

Choose a reason for hiding this comment

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

Just for completeness, the argument for the function calling the method would be to handle inheritance from Dask Array. That said, I have no strong preferences here either and it can always be changed if there is a need.


@wraps(np.reshape)
def reshape(self, *shape):
from .reshape import reshape
Expand Down
7 changes: 7 additions & 0 deletions dask/array/tests/test_array_core.py
Expand Up @@ -709,12 +709,19 @@ def test_norm():


def test_choose():
# test choose function
x = np.random.randint(10, size=(15, 16))
d = from_array(x, chunks=(4, 5))

assert_eq(choose(d > 5, [0, d]), np.choose(x > 5, [0, x]))
assert_eq(choose(d > 5, [-d, d]), np.choose(x > 5, [-x, x]))

# test choose method
index_dask = d > 5
index_numpy = x > 5
assert_eq(index_dask.choose([0, d]), index_numpy.choose([0, x]))
assert_eq(index_dask.choose([-d, d]), index_numpy.choose([-x, x]))


def test_argwhere():
for shape, chunks in [(0, ()), ((0, 0), (0, 0)), ((15, 16), (4, 5))]:
Expand Down