|
Boost Users : |
From: Pascal Bauer (pascal.bauer_at_[hidden])
Date: 2005-04-14 03:09:33
Hi List Members
I have data stored in an matrix. Now, i want to acces the data of the matrix
row-wise. because i want to access it in a sorted manner (without moving the
matrix entries around), i make a stl-vector of matrix_rows. This works fine.
But if i now use the stl algorithms to sort the stl-vector by a certain
criteria, then it happens, that the algorithm is making several copies of a
singe vector entry and overwriting other entries.
Can anyone give me a tipp, what i'm doing wrong?
----------------------------
Here is an example code:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<boost/numeric/ublas/matrix.hpp>
#include<boost/numeric/ublas/io.hpp>
namespace num=boost::numeric::ublas;
template <int N>
class Ordering
{
public:
bool operator()(num::matrix_row<num::matrix<double> > A,
num::matrix_row<num::matrix<double> > B)
{
if (A(N) < B(N) ) return true;
else return false;
}
};
int main(int argc, char* argv[])
{
const int N = 10000;
const int M = 4;
num::matrix<double> Matrix(N, M);
for (int i = 0; i < Matrix.size1(); i++)
{
for (int j = 0; j < Matrix.size2(); j++)
{
Matrix(i, j) = drand48();
}
}
std::vector<num::matrix_row<num::matrix<double> > > MyAccess;
for (int i = 0; i < Matrix.size1(); i++)
{
MyAccess.push_back(num::matrix_row<num::matrix<double> >(Matrix, i) );
}
for (int i = 0; i < Matrix.size1(); i++)
{
std::cout << MyAccess[i] << std::endl;
}
std::sort(MyAccess.begin(), MyAccess.end(), Ordering<0>() );
for (int i = 0; i < Matrix.size1(); i++)
{
std::cout << MyAccess[i] << std::endl;
}
}
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