Neal Becker wrote:

> Keith Goodman wrote:
> ...
>> Oh, I thought he meant there was a numpy function for partial 
sorting.
>> 
Try this one:

template<typename in_t>
inline void partial_sort (in_t in, int n_el) {
  std::partial_sort (boost::begin (in), boost::begin(in) + n_el, 
boost::end (in));
}
...
  def ("partial_sort", 
&partial_sort<pyublas::numpy_strided_vector<int32_t> >);
  def ("partial_sort", 
&partial_sort<pyublas::numpy_strided_vector<int64_t> >);
  def ("partial_sort", 
&partial_sort<pyublas::numpy_strided_vector<double> >);
---------
import pyublas
import numpy as np
u = np.arange (20)[::-1]
from numpy_fncs import partial_sort
partial_sort (u, 4)
In [2]: u
Out[2]: 
array([ 0,  1,  2,  3, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  
7,
        6,  5,  4])

_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to