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

Function string_atimsort_

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

Source from the content-addressed store, hash-verified

1808
1809template <typename Tag>
1810NPY_NO_EXPORT int
1811string_atimsort_(void *start, npy_intp *tosort, npy_intp num, void *varr)
1812{
1813 using type = typename Tag::type;
1814 PyArrayObject *arr = reinterpret_cast<PyArrayObject *>(varr);
1815 size_t elsize = PyArray_ITEMSIZE(arr);
1816 size_t len = elsize / sizeof(type);
1817 int ret;
1818 npy_intp l, n, stack_ptr, minrun;
1819 run stack[TIMSORT_STACK_SIZE];
1820 buffer_intp buffer;
1821
1822 /* Items that have zero size don't make sense to sort */
1823 if (len == 0) {
1824 return 0;
1825 }
1826
1827 buffer.pw = NULL;
1828 buffer.size = 0;
1829 stack_ptr = 0;
1830 minrun = compute_min_run_short(num);
1831
1832 for (l = 0; l < num;) {
1833 n = acount_run_<Tag>((type *)start, tosort, l, num, minrun, len);
1834 /* both s and l are scaled by len */
1835 stack[stack_ptr].s = l;
1836 stack[stack_ptr].l = n;
1837 ++stack_ptr;
1838 ret = atry_collapse_<Tag>((type *)start, tosort, stack, &stack_ptr,
1839 &buffer, len);
1840
1841 if (NPY_UNLIKELY(ret < 0)) {
1842 goto cleanup;
1843 }
1844
1845 l += n;
1846 }
1847
1848 ret = aforce_collapse_<Tag>((type *)start, tosort, stack, &stack_ptr,
1849 &buffer, len);
1850
1851 if (NPY_UNLIKELY(ret < 0)) {
1852 goto cleanup;
1853 }
1854
1855 ret = 0;
1856
1857cleanup:
1858 if (buffer.pw != NULL) {
1859 free(buffer.pw);
1860 }
1861 return ret;
1862}
1863
1864/*
1865 *****************************************************************************

Callers

nothing calls this directly

Calls 2

PyArray_ITEMSIZEFunction · 0.85
compute_min_run_shortFunction · 0.85

Tested by

no test coverage detected