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

Function _get_binsearch_func

numpy/core/src/npysort/binsearch.cpp:347–384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345
346template <arg_t arg>
347static inline typename binsearch_t<arg>::function_type
348_get_binsearch_func(PyArray_Descr *dtype, NPY_SEARCHSIDE side)
349{
350 using binsearch = binsearch_t<arg>;
351 npy_intp nfuncs = binsearch::map.size();
352 npy_intp min_idx = 0;
353 npy_intp max_idx = nfuncs;
354 int type = dtype->type_num;
355
356 if ((int)side >= (int)NPY_NSEARCHSIDES) {
357 return NULL;
358 }
359
360 /*
361 * It seems only fair that a binary search function be searched for
362 * using a binary search...
363 */
364 while (min_idx < max_idx) {
365 npy_intp mid_idx = min_idx + ((max_idx - min_idx) >> 1);
366
367 if (binsearch::map[mid_idx].typenum < type) {
368 min_idx = mid_idx + 1;
369 }
370 else {
371 max_idx = mid_idx;
372 }
373 }
374
375 if (min_idx < nfuncs && binsearch::map[min_idx].typenum == type) {
376 return binsearch::map[min_idx].binsearch[side];
377 }
378
379 if (dtype->f->compare) {
380 return binsearch::npy_map[side];
381 }
382
383 return NULL;
384}
385
386/*
387 *****************************************************************************

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected