ERROR (?) in interplay between uBLAS and STL algorithms.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ERROR (?) in interplay between uBLAS and STL algorithms.

Pascal Bauer
Hi List,

I created a (stl vector) of matrix_rows from the boost uBLAS. This seems to
work fine. But somehow, the interplay with the stl algorithms seems then not
to work.

If I compile the code, i would expect a list of all the rows, ordered by the
first row entry.  But to sort algorithms seems to create multiple copies of
the same matrix row. Can someone tell me, what is going wrong there?

I'm using the gcc version 4.0.2 20050901 (prerelease) (SUSE Linux).

Many thanks for advises how to make this work.

Here the Code:

#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/matrix_proxy.hpp>
#include <boost/numeric/ublas/io.hpp>

#include <vector>
#include <algorithm>

namespace num = boost::numeric::ublas;

typedef num::matrix<double> matrix_type;
typedef num::matrix_row<matrix_type> matrix_row;
typedef std::vector<matrix_row> data_proxy;

template <int N>
class Ordering
{
public:
    bool operator()(const matrix_row& row_1, const matrix_row& row_2)
        {
            return row_1(N) < row_2(N);
        }
};

int main(int argc, char* argv)
{

    const size_t N_1 = 25;
    const size_t M_1 = 10;

    const size_t N_2 = 20;
    const size_t M_2 = 10;

    matrix_type Data_1(N_1, M_1);
    matrix_type Data_2(N_2, M_2);

    data_proxy my_proxy;

    for (size_t i = 0; i < N_1; ++i)
    {
        Data_1(i, 0) = i;
        my_proxy.push_back(matrix_row(Data_1, i) );
    }

    for (size_t j = 0; j < N_2; ++j)
    {
        Data_2(j, 0) = 0.5 + j;
        my_proxy.push_back(matrix_row(Data_2, j) );
    }

    data_proxy copy(my_proxy);

    std::sort(my_proxy.begin(), my_proxy.end(), Ordering<0>() );

    for (size_t i = 0; i < my_proxy.size(); ++i)
    {
        std::cout << my_proxy[i] << std::endl;
    }

}

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users

matrix_sort.cpp (1K) Download Attachment