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

Function atimsort_

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

Source from the content-addressed store, hash-verified

901
902template <typename Tag>
903static int
904atimsort_(void *v, npy_intp *tosort, npy_intp num)
905{
906 using type = typename Tag::type;
907 int ret;
908 npy_intp l, n, stack_ptr, minrun;
909 buffer_intp buffer;
910 run stack[TIMSORT_STACK_SIZE];
911 buffer.pw = NULL;
912 buffer.size = 0;
913 stack_ptr = 0;
914 minrun = compute_min_run(num);
915
916 for (l = 0; l < num;) {
917 n = acount_run_<Tag>((type *)v, tosort, l, num, minrun);
918 stack[stack_ptr].s = l;
919 stack[stack_ptr].l = n;
920 ++stack_ptr;
921 ret = atry_collapse_<Tag>((type *)v, tosort, stack, &stack_ptr,
922 &buffer);
923
924 if (NPY_UNLIKELY(ret < 0)) {
925 goto cleanup;
926 }
927
928 l += n;
929 }
930
931 ret = aforce_collapse_<Tag>((type *)v, tosort, stack, &stack_ptr, &buffer);
932
933 if (NPY_UNLIKELY(ret < 0)) {
934 goto cleanup;
935 }
936
937 ret = 0;
938cleanup:
939
940 if (buffer.pw != NULL) {
941 free(buffer.pw);
942 }
943
944 return ret;
945}
946
947/* For string sorts and generic sort, element comparisons are very expensive,
948 * and the time cost of insertion sort (involves N**2 comparison) clearly

Callers

nothing calls this directly

Calls 1

compute_min_runFunction · 0.85

Tested by

no test coverage detected