-
Notifications
You must be signed in to change notification settings - Fork 36
Add enforcement for np.sort and np.argsort
#918
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
Conversation
for more information, see https://pre-commit.ci
…rax into set_default_as_mergesort
for more information, see https://pre-commit.ci
…rax into set_default_as_mergesort
for more information, see https://pre-commit.ci
|
Unfortunately, the For So we have two options:
I'm checking the possibility for both ways. |
…on for highest_density_region
…rax into set_default_as_mergesort
for more information, see https://pre-commit.ci
…rax into set_default_as_mergesort
np.sort and np.argsort
…rax into set_default_as_mergesort
for more information, see https://pre-commit.ci
…rax into set_default_as_mergesort
for more information, see https://pre-commit.ci
…rax into set_default_as_mergesort
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.
|
I should mention that this PR is following up XENONnT/straxen#1176, for future reference. |
* set mergesort as default and disable unstable kinds * add unittest * formatting * formatting * change name to sort_enforcement * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * break long error messages * keep the original sorting in numpy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reemove unused import * always use stablesort * add numba-supported version of stableargsort * use better naming for stablesort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use jitable to allow both regular function and numba-decorated function for highest_density_region * remove redundant numba_sort * explicitly import stablesort from strax for numba decorated functions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * consistent import style within one module * remove unused import * add sorting error * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * disable numba support for stable_sort * consistent import style for stable sort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add kwargs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * modify docstring for stable_sort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove kwargs * update variable name * update test_sort with hypothesis * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * rewrite hithest_density_region to decoupld stable_sort from numba part * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove unused import * break long lines * remove numba decorator for the main function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix typo * rewrite hitlets to use non-numba HDR region * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * format hitlets.py * unify growing_result import to fix mypy error * remove redundant space * Remove unnecessary indent --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: dachengx <dx2227@columbia.edu>
* set mergesort as default and disable unstable kinds * add unittest * formatting * formatting * change name to sort_enforcement * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * break long error messages * keep the original sorting in numpy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reemove unused import * always use stablesort * add numba-supported version of stableargsort * use better naming for stablesort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use jitable to allow both regular function and numba-decorated function for highest_density_region * remove redundant numba_sort * explicitly import stablesort from strax for numba decorated functions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * consistent import style within one module * remove unused import * add sorting error * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * disable numba support for stable_sort * consistent import style for stable sort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add kwargs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * modify docstring for stable_sort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove kwargs * update variable name * update test_sort with hypothesis * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * rewrite hithest_density_region to decoupld stable_sort from numba part * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove unused import * break long lines * remove numba decorator for the main function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix typo * rewrite hitlets to use non-numba HDR region * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * format hitlets.py * unify growing_result import to fix mypy error * remove redundant space * Remove unnecessary indent --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: dachengx <dx2227@columbia.edu>
* set mergesort as default and disable unstable kinds * add unittest * formatting * formatting * change name to sort_enforcement * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * break long error messages * keep the original sorting in numpy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * reemove unused import * always use stablesort * add numba-supported version of stableargsort * use better naming for stablesort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use jitable to allow both regular function and numba-decorated function for highest_density_region * remove redundant numba_sort * explicitly import stablesort from strax for numba decorated functions * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * consistent import style within one module * remove unused import * add sorting error * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * disable numba support for stable_sort * consistent import style for stable sort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add kwargs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * modify docstring for stable_sort * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove kwargs * update variable name * update test_sort with hypothesis * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * rewrite hithest_density_region to decoupld stable_sort from numba part * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * remove unused import * break long lines * remove numba decorator for the main function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix typo * rewrite hitlets to use non-numba HDR region * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * format hitlets.py * unify growing_result import to fix mypy error * remove redundant space * Remove unnecessary indent --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: dachengx <dx2227@columbia.edu>
This PR enforces deterministic sorting behavior by implementing the
sort_enforcementmodule. Specifically, it:mergesortthe default sorting algorithmquicksortandheapsort) to prevent their usagenp.sortandnp.argsortto enforce the behaviors mentioned aboveThe implementation is robust to import order - the enforcement takes effect whenever
straxis imported, regardless of whethernumpyis imported before or after. This ensures consistent sorting behavior across all strax operations, addressing the non-deterministic sorting issues reported in #916.A unit test is also added accordingly.