简体   繁体   中英

How is the pivot chosen in numpy.argsort?

I want to benchmark np.argsort by comparing different sorting algorithms, that are 'quicksort' , 'mergesort' , 'heapsort' , 'stable' available in the np.argsort documentation . I was wondering how was the pivot chosen in the ie quicksort .

I found the source file for np.sort and the choice of pivot is clear there. However, I cannot find the file describing what is happening under the hood of the np.argsort . The reasonable assumption would be that the methods are performing the same, however, I would want to somehow verify it.

When calling np.argsort(kind='quicksort') the call gets dispatched to PyArray_ArgSort and then to npy_aquicksort (C source links):

This also includes a choice of pivot identical to your link to np.sort :

pm = pl + ((pr - pl) >> 1);

Without having looked into it further, I assume this chooses the center element of the current partition as pivot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM