ranking of ublas vector
Hello, 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? Thanks Phil
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())); In Christ, Steven Watanabe
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
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()));
I have a problem with the boost libs (1.42). Your code compiles without errors, but in the "operator_lambda_func_base.hpp" at line 135 the compilere shows the error 4 times: conversion from 'double' to non-scalar type 'boost::lambda::detail::unspecified' requested I have set this includes: #include <boost/iterator/counting_iterator.hpp> #include <boost/iterator/permutation_iterator.hpp> #include <boost/lambda/lambda.hpp> #include <boost/numeric/ublas/vector.hpp> Can you please help to solve this problem? Thank Phil
AMDG Kraus Philipp wrote:
I have a problem with the boost libs (1.42). Your code compiles without errors, but in the "operator_lambda_func_base.hpp" at line 135 the compilere shows the error 4 times: conversion from 'double' to non-scalar type 'boost::lambda::detail::unspecified' requested <snip> Can you please help to solve this problem?
Obviously I should have tried to compile before posting... Apparently Lambda doesn't work with uBLAS by default. #include <boost/iterator/counting_iterator.hpp> #include <boost/iterator/permutation_iterator.hpp> #include <boost/lambda/lambda.hpp> #include <boost/numeric/ublas/vector.hpp> #include <algorithm> #include <iostream> namespace ublas = boost::numeric::ublas; namespace boost { namespace lambda { template<class T, class Allocator, class B> struct plain_return_type_2<other_action<subscript_action>, ublas::vector<T, Allocator>, B> { typedef typename ublas::vector<T, Allocator>::reference type; }; } } int main() { ublas::vector<long double> vec(5); vec[0] = 2.0; vec[1] = 1.0; vec[2] = 3.0; vec[3] = 5.0; vec[4] = 4.0; 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())); std::copy(ranking.begin(), ranking.end(), std::ostream_iterator<std::size_t>(std::cout, " ")); } In Christ, Steven Watanabe
Am 13.03.2010 um 23:12 schrieb Steven Watanabe:
Obviously I should have tried to compile before posting...
Apparently Lambda doesn't work with uBLAS by default.
now it works. The example: [5](0.664852, 0.548873, 0.0389818, 0.914604, 0.261907) [5](3,2,0,4,1) But my target vector should be 2, 4, 1, 0, 3, because the smallest entry is the third element. Sorry at this time, it's midnight and I can't think about it anymore Thanks a lot Phil
AMDG Kraus Philipp wrote:
Am 13.03.2010 um 23:12 schrieb Steven Watanabe:
Obviously I should have tried to compile before posting...
Apparently Lambda doesn't work with uBLAS by default.
now it works. The example: [5](0.664852, 0.548873, 0.0389818, 0.914604, 0.261907) [5](3,2,0,4,1)
But my target vector should be 2, 4, 1, 0, 3, because the smallest entry is the third element. Sorry at this time, it's midnight and I can't think about it anymore
Oops. I guess I didn't understand exactly what you wanted. The temp vector, should contain the result you want. In Christ, Steven Watanabe
participants (2)
-
Kraus Philipp
-
Steven Watanabe