MCPcopy Create free account
hub / github.com/numpy/numpy / npy_atimsort

Function npy_atimsort

numpy/core/src/npysort/timsort.cpp:2706–2758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2704}
2705
2706NPY_NO_EXPORT int
2707npy_atimsort(void *start, npy_intp *tosort, npy_intp num, void *varr)
2708{
2709 PyArrayObject *arr = reinterpret_cast<PyArrayObject *>(varr);
2710 size_t len = PyArray_ITEMSIZE(arr);
2711 PyArray_CompareFunc *cmp = PyArray_DESCR(arr)->f->compare;
2712 int ret;
2713 npy_intp l, n, stack_ptr, minrun;
2714 run stack[TIMSORT_STACK_SIZE];
2715 buffer_intp buffer;
2716
2717 /* Items that have zero size don't make sense to sort */
2718 if (len == 0) {
2719 return 0;
2720 }
2721
2722 buffer.pw = NULL;
2723 buffer.size = 0;
2724 stack_ptr = 0;
2725 minrun = compute_min_run_short(num);
2726
2727 for (l = 0; l < num;) {
2728 n = npy_acount_run((char *)start, tosort, l, num, minrun, len, cmp,
2729 arr);
2730 /* both s and l are scaled by len */
2731 stack[stack_ptr].s = l;
2732 stack[stack_ptr].l = n;
2733 ++stack_ptr;
2734 ret = npy_atry_collapse((char *)start, tosort, stack, &stack_ptr,
2735 &buffer, len, cmp, arr);
2736
2737 if (NPY_UNLIKELY(ret < 0)) {
2738 goto cleanup;
2739 }
2740
2741 l += n;
2742 }
2743
2744 ret = npy_aforce_collapse((char *)start, tosort, stack, &stack_ptr,
2745 &buffer, len, cmp, arr);
2746
2747 if (NPY_UNLIKELY(ret < 0)) {
2748 goto cleanup;
2749 }
2750
2751 ret = 0;
2752
2753cleanup:
2754 if (buffer.pw != NULL) {
2755 free(buffer.pw);
2756 }
2757 return ret;
2758}
2759
2760/***************************************
2761 * C > C++ dispatch

Callers

nothing calls this directly

Calls 6

PyArray_ITEMSIZEFunction · 0.85
PyArray_DESCRFunction · 0.85
compute_min_run_shortFunction · 0.85
npy_acount_runFunction · 0.85
npy_atry_collapseFunction · 0.85
npy_aforce_collapseFunction · 0.85

Tested by

no test coverage detected