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

Add compress #3103

Merged
merged 7 commits into from Feb 25, 2020
Merged

Add compress #3103

merged 7 commits into from Feb 25, 2020

Conversation

Harshan01
Copy link
Contributor

I tried to mimic numpy as much as possible. I observed that PyArray_Compress in numpy internally calls nonzero and take. So, I tried to do it in the same way instead of making a separate kernel. I would be happy to receive suggestions on how to implement the kernel for compress, if it is required to do so.

@Harshan01
Copy link
Contributor Author

This PR is for the feature request Issue #2224

@Harshan01 Harshan01 mentioned this pull request Feb 20, 2020
@niboshi niboshi added the cat:feature New features/APIs label Feb 21, 2020
@niboshi niboshi self-assigned this Feb 21, 2020
@niboshi niboshi added this to the v8.0.0b1 milestone Feb 21, 2020
cupy/__init__.py Outdated Show resolved Hide resolved
Comment on lines +161 to +164
if not isinstance(condition, ndarray):
condition = core.array(condition, dtype=int)
if condition.ndim != 1:
raise ValueError('condition must be a 1-d array')
Copy link
Member

@niboshi niboshi Feb 21, 2020

Choose a reason for hiding this comment

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

We do not accept numpy arrays as argument in general.
I think we can just ensure isinstance(condition, ndarray) and raise TypeError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if I understand what you said. Doesn't ndarray mean only cupy ndarrays.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's correct. ndarray is cupy.ndarray in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we just assert that instance is of ndarray, then we might not be able to take a python list of booleans as input. That's why I thought I might convert it to cupy ndarray (which also has a side-effect of converting numpy arrays also to cupy ndarrays). Otherwise, I would need to check manually for a list of booleans.

Copy link
Member

@niboshi niboshi Feb 25, 2020

Choose a reason for hiding this comment

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

We do not accept list of booleans as well.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, as take accepts both lists and NumPy arrays as indices, I think condition can support them as well.

cupy/core/_routines_indexing.pyx Outdated Show resolved Hide resolved
cupy/indexing/indexing.py Outdated Show resolved Hide resolved
cupy/indexing/indexing.py Outdated Show resolved Hide resolved
cupy/core/core.pyx Outdated Show resolved Hide resolved
cupy/indexing/indexing.py Outdated Show resolved Hide resolved
@niboshi
Copy link
Member

niboshi commented Feb 21, 2020

Please test some additional configurations:

  • condition is not bool. Maybe use cupy.testing.for_int_dtypes to parameterize its dtype?
  • condition is an empty 1-dim array (cupy.ndarray([])).

@niboshi
Copy link
Member

niboshi commented Feb 25, 2020

Thanks. Jenkins, test this please

@pfn-ci-bot
Copy link
Collaborator

Successfully created a job for commit c4b826b:

@niboshi niboshi added the st:test-and-merge (deprecated) Ready to merge after test pass. label Feb 25, 2020
@niboshi niboshi changed the title Feature-implementation of np.compress in Cupy Add compress Feb 25, 2020
@niboshi niboshi removed the st:test-and-merge (deprecated) Ready to merge after test pass. label Feb 25, 2020
@niboshi
Copy link
Member

niboshi commented Feb 25, 2020

Forgot one thing, could you add a documentation entry to docs/source/reference/indexing.rst?

@chainer-ci
Copy link
Member

Jenkins CI test (for commit c4b826b, target branch master) succeeded!

@Harshan01
Copy link
Contributor Author

@niboshi I have made the requested changes. Can you please review them?

@niboshi
Copy link
Member

niboshi commented Feb 25, 2020

Thanks. Jenkins, test this please

@pfn-ci-bot
Copy link
Collaborator

Successfully created a job for commit 9046147:

@chainer-ci
Copy link
Member

Jenkins CI test (for commit 9046147, target branch master) succeeded!

@niboshi niboshi added the st:test-and-merge (deprecated) Ready to merge after test pass. label Feb 25, 2020
@mergify mergify bot merged commit 7cf5fef into cupy:master Feb 25, 2020
@niboshi
Copy link
Member

niboshi commented Feb 25, 2020

👍

@Harshan01 Harshan01 deleted the cupy-compress branch February 25, 2020 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:feature New features/APIs st:test-and-merge (deprecated) Ready to merge after test pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants