-
Notifications
You must be signed in to change notification settings - Fork 22
Implement dpnp.compress
and dpnp_array.compress
method
#2177
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
Implement dpnp.compress
and dpnp_array.compress
method
#2177
Conversation
cf9df6d
to
9b05295
Compare
Also disable checks for protected access, as `compress` uses dpctl.tensor private functions
Also removes an unnecessary check per PR review
Also fix a typo when `condition` is not an array
Also tweaks to docstring
Should slightly improve efficiency by escaping an additional copy where `out` is not `None` and flattening of indices
f8886cd
to
edace9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @ndgrigorian. I have only a minor comment, but in overall LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @ndgrigorian
@antonwolfy CI is passed, please merge at your convenience |
* Implement dpnp.compress * Add `dpnp_array.compress` method * Break up `compress` to satisfy pylint Also disable checks for protected access, as `compress` uses dpctl.tensor private functions * Unmute third-party tests for `compress` * Use `get_usm_allocations` in `compress` * Fix bug where `out` in `compress` is dpnp_array Also removes an unnecessary check per PR review * Apply comments per PR review by @antonwolfy Also fix a typo when `condition` is not an array * Remove branching when `condition` is an array Also tweaks to docstring * Add tests for `compress` * Re-use `_take_index` for `dpnp.take` Should slightly improve efficiency by escaping an additional copy where `out` is not `None` and flattening of indices * Change error for incorrect out array dtype to `TypeError` * Move compress tests into a TestCompress class * Use NumPy in compress tests * Add `no_none=True` to `test_compress_condition_all_dtypes` * Add USM type and SYCL queue tests for `compress` * More tests for compress added * Docstring change per PR review * Integrate test for compute follows data in compress into test_2in_1out * Add test for `dpnp_array.compress` and add a test for strided inputs to `compress` * Refactor `test_compress` in test_usm_type.py into `test_2in_1out` 367e74e
* Implement dpnp.compress * Add `dpnp_array.compress` method * Break up `compress` to satisfy pylint Also disable checks for protected access, as `compress` uses dpctl.tensor private functions * Unmute third-party tests for `compress` * Use `get_usm_allocations` in `compress` * Fix bug where `out` in `compress` is dpnp_array Also removes an unnecessary check per PR review * Apply comments per PR review by @antonwolfy Also fix a typo when `condition` is not an array * Remove branching when `condition` is an array Also tweaks to docstring * Add tests for `compress` * Re-use `_take_index` for `dpnp.take` Should slightly improve efficiency by escaping an additional copy where `out` is not `None` and flattening of indices * Change error for incorrect out array dtype to `TypeError` * Move compress tests into a TestCompress class * Use NumPy in compress tests * Add `no_none=True` to `test_compress_condition_all_dtypes` * Add USM type and SYCL queue tests for `compress` * More tests for compress added * Docstring change per PR review * Integrate test for compute follows data in compress into test_2in_1out * Add test for `dpnp_array.compress` and add a test for strided inputs to `compress` * Refactor `test_compress` in test_usm_type.py into `test_2in_1out`
* Implement dpnp.compress * Add `dpnp_array.compress` method * Break up `compress` to satisfy pylint Also disable checks for protected access, as `compress` uses dpctl.tensor private functions * Unmute third-party tests for `compress` * Use `get_usm_allocations` in `compress` * Fix bug where `out` in `compress` is dpnp_array Also removes an unnecessary check per PR review * Apply comments per PR review by @antonwolfy Also fix a typo when `condition` is not an array * Remove branching when `condition` is an array Also tweaks to docstring * Add tests for `compress` * Re-use `_take_index` for `dpnp.take` Should slightly improve efficiency by escaping an additional copy where `out` is not `None` and flattening of indices * Change error for incorrect out array dtype to `TypeError` * Move compress tests into a TestCompress class * Use NumPy in compress tests * Add `no_none=True` to `test_compress_condition_all_dtypes` * Add USM type and SYCL queue tests for `compress` * More tests for compress added * Docstring change per PR review * Integrate test for compute follows data in compress into test_2in_1out * Add test for `dpnp_array.compress` and add a test for strided inputs to `compress` * Refactor `test_compress` in test_usm_type.py into `test_2in_1out`
This PR proposes an implementation for
dpnp.compress
usingdpctl.tensor
kernels.nonzero
is used to accumulate thecondition
into 1d array of indices, which are then used to take the appropriate slices of the array. Whenaxis
isNone
, the operand array is flattened.The coupled
dpnp_array.compress
method is implemented through a simple call to thecompress
function,