|
Boost Users : |
Subject: Re: [Boost-users] ranking of ublas vector
From: Kraus Philipp (philipp.kraus_at_[hidden])
Date: 2010-03-13 16:27:38
Am 13.03.2010 um 22:18 schrieb Steven Watanabe:
> AMDG
>
> Kraus Philipp wrote:
>> I have a very large non sparse ublas vector (most long double
>> content).
>> I would like to sort this vector without change the vector content,
>> but
>> I know the rank of the elements like
>>
>> the smalest element in the vector is the 312 element in the original
>> vector (for example).
>>
>> Is there a boost implementation for create ranking of elements?
>
> There isn't, but it's fairly straightforward to do.
>
> ublas::vector<long double> vec;
>
> using namespace boost::lambda;
> std::vector<std::size_t>
> temp(boost::counting_iterator<std::size_t>(0),
> boost::counting_iterator<std::size_t>(vec.size()));
> std::sort(temp.begin(), temp.end(), var(vec)[_1] < var(vec)[_2]);
> std::vector<std::size_t> ranking(temp.size());
> std::copy(boost::counting_iterator<std::size_t>(0),
> boost::counting_iterator<std::size_t>(vec.size()),
> boost::make_permutation_iterator(ranking.begin(), temp.begin()));
Thanks for the working example
Phil
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net