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

Function npy_merge_at

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

Source from the content-addressed store, hash-verified

2115}
2116
2117static int
2118npy_merge_at(char *arr, const run *stack, const npy_intp at,
2119 buffer_char *buffer, size_t len, PyArray_CompareFunc *cmp,
2120 PyArrayObject *py_arr)
2121{
2122 int ret;
2123 npy_intp s1, l1, s2, l2, k;
2124 char *p1, *p2;
2125 s1 = stack[at].s;
2126 l1 = stack[at].l;
2127 s2 = stack[at + 1].s;
2128 l2 = stack[at + 1].l;
2129 /* arr[s2] belongs to arr[s1+k] */
2130 GENERIC_COPY(buffer->pw, arr + s2 * len, len);
2131 k = npy_gallop_right(arr + s1 * len, l1, buffer->pw, len, cmp, py_arr);
2132
2133 if (l1 == k) {
2134 /* already sorted */
2135 return 0;
2136 }
2137
2138 p1 = arr + (s1 + k) * len;
2139 l1 -= k;
2140 p2 = arr + s2 * len;
2141 /* arr[s2-1] belongs to arr[s2+l2] */
2142 GENERIC_COPY(buffer->pw, arr + (s2 - 1) * len, len);
2143 l2 = npy_gallop_left(arr + s2 * len, l2, buffer->pw, len, cmp, py_arr);
2144
2145 if (l2 < l1) {
2146 ret = resize_buffer_char(buffer, l2);
2147
2148 if (NPY_UNLIKELY(ret < 0)) {
2149 return ret;
2150 }
2151
2152 npy_merge_right(p1, l1, p2, l2, buffer->pw, len, cmp, py_arr);
2153 }
2154 else {
2155 ret = resize_buffer_char(buffer, l1);
2156
2157 if (NPY_UNLIKELY(ret < 0)) {
2158 return ret;
2159 }
2160
2161 npy_merge_left(p1, l1, p2, l2, buffer->pw, len, cmp, py_arr);
2162 }
2163
2164 return 0;
2165}
2166
2167static int
2168npy_try_collapse(char *arr, run *stack, npy_intp *stack_ptr,

Callers 2

npy_try_collapseFunction · 0.85
npy_force_collapseFunction · 0.85

Calls 6

GENERIC_COPYFunction · 0.85
npy_gallop_rightFunction · 0.85
npy_gallop_leftFunction · 0.85
resize_buffer_charFunction · 0.85
npy_merge_rightFunction · 0.85
npy_merge_leftFunction · 0.85

Tested by

no test coverage detected