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

Function aradixsort0

numpy/core/src/npysort/radixsort.cpp:143–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141
142template <class T, class UT>
143static npy_intp *
144aradixsort0(UT *start, npy_intp *aux, npy_intp *tosort, npy_intp num)
145{
146 npy_intp cnt[sizeof(UT)][1 << 8] = {{0}};
147 UT key0 = KEY_OF<T>(start[0]);
148
149 for (npy_intp i = 0; i < num; i++) {
150 UT k = KEY_OF<T>(start[i]);
151
152 for (size_t l = 0; l < sizeof(UT); l++) {
153 cnt[l][nth_byte(k, l)]++;
154 }
155 }
156
157 size_t ncols = 0;
158 npy_ubyte cols[sizeof(UT)];
159 for (size_t l = 0; l < sizeof(UT); l++) {
160 if (cnt[l][nth_byte(key0, l)] != num) {
161 cols[ncols++] = l;
162 }
163 }
164
165 for (size_t l = 0; l < ncols; l++) {
166 npy_intp a = 0;
167 for (npy_intp i = 0; i < 256; i++) {
168 npy_intp b = cnt[cols[l]][i];
169 cnt[cols[l]][i] = a;
170 a += b;
171 }
172 }
173
174 for (size_t l = 0; l < ncols; l++) {
175 npy_intp *temp;
176 for (npy_intp i = 0; i < num; i++) {
177 UT k = KEY_OF<T>(start[tosort[i]]);
178 npy_intp dst = cnt[cols[l]][nth_byte(k, cols[l])]++;
179 aux[dst] = tosort[i];
180 }
181
182 temp = aux;
183 aux = tosort;
184 tosort = temp;
185 }
186
187 return tosort;
188}
189
190template <class T, class UT>
191static int

Callers

nothing calls this directly

Calls 1

nth_byteFunction · 0.85

Tested by

no test coverage detected