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

Function npy_amerge_at

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

Source from the content-addressed store, hash-verified

2547}
2548
2549static int
2550npy_amerge_at(char *arr, npy_intp *tosort, const run *stack, const npy_intp at,
2551 buffer_intp *buffer, size_t len, PyArray_CompareFunc *cmp,
2552 PyArrayObject *py_arr)
2553{
2554 int ret;
2555 npy_intp s1, l1, s2, l2, k;
2556 npy_intp *p1, *p2;
2557 s1 = stack[at].s;
2558 l1 = stack[at].l;
2559 s2 = stack[at + 1].s;
2560 l2 = stack[at + 1].l;
2561 /* tosort[s2] belongs to tosort[s1+k] */
2562 k = npy_agallop_right(arr, tosort + s1, l1, arr + tosort[s2] * len, len,
2563 cmp, py_arr);
2564
2565 if (l1 == k) {
2566 /* already sorted */
2567 return 0;
2568 }
2569
2570 p1 = tosort + s1 + k;
2571 l1 -= k;
2572 p2 = tosort + s2;
2573 /* tosort[s2-1] belongs to tosort[s2+l2] */
2574 l2 = npy_agallop_left(arr, tosort + s2, l2, arr + tosort[s2 - 1] * len,
2575 len, cmp, py_arr);
2576
2577 if (l2 < l1) {
2578 ret = resize_buffer_intp(buffer, l2);
2579
2580 if (NPY_UNLIKELY(ret < 0)) {
2581 return ret;
2582 }
2583
2584 npy_amerge_right(arr, p1, l1, p2, l2, buffer->pw, len, cmp, py_arr);
2585 }
2586 else {
2587 ret = resize_buffer_intp(buffer, l1);
2588
2589 if (NPY_UNLIKELY(ret < 0)) {
2590 return ret;
2591 }
2592
2593 npy_amerge_left(arr, p1, l1, p2, l2, buffer->pw, len, cmp, py_arr);
2594 }
2595
2596 return 0;
2597}
2598
2599static int
2600npy_atry_collapse(char *arr, npy_intp *tosort, run *stack, npy_intp *stack_ptr,

Callers 2

npy_atry_collapseFunction · 0.85
npy_aforce_collapseFunction · 0.85

Calls 5

npy_agallop_rightFunction · 0.85
npy_agallop_leftFunction · 0.85
resize_buffer_intpFunction · 0.85
npy_amerge_rightFunction · 0.85
npy_amerge_leftFunction · 0.85

Tested by

no test coverage detected