Boost logo

Ublas :

Subject: Re: [ublas] Distinct rows in a matrix
From: Pawe³ Szlendak (ogee_at_[hidden])
Date: 2008-11-02 10:34:51


Gunter Winkler pisze:
> Am Freitag, 31. Oktober 2008 10:41 schrieb Pawe³ Szlendak:
>
>> Unfortunatelly, linear independence is not what I want to check.
>> Since, having
>>
>> A = [ 1 2 3; 4 5 6 ; 2 4 6]
>>
>> rank(A) = 2 and there are 3 distict rows although row 1 is a linear
>> combination of row 3.
>> What I am trying to obtain is something like SQL query:
>>
>> select distinct *
>> from A
>>
>
> Then you could order the rows of the matrix and make the result unique.
>
> This can be achieved by using a "permutation vector" and custom compare
> functors:
>
> // pseudo code
>
> class row_compare {
> const matrix & A;
> row_compare(const matrix & A) : A(A) {}
> boolean operator() (int left, int right) const {
> return row(A, left) < row(A, right);
> }
> };
>
> class row_equal {
> const matrix & A;
> row_compare(const matrix & A) : A(A) {}
> boolean operator() (int left, int right) const {
> return row(A, left) == row(A, right);
> }
> };
>
> vector<int> index(A.size1());
> ... foreach i: set index[i] = i
>
> std::sort(index.begin(), index.end(), row_compare(A));
>
> iterator new_end = std::unique(index.begin(), index.end(),
> row_equal(A));
>
>
> mfg
> Gunter
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>
I'm trying to follow your idea, however it seems that there is no '=='
operator for class matrix_row defined.
The following piece of code fails to compile:

    matrix<int> m(10,10);
    matrix_row<matrix<int> > mr = row(m, 0);
    matrix_row<matrix<int> > mr2 = row(m, 0);

    if (mr == mr2)
        cout << "Equal" << endl;

The error is:

error C2678: binary '==' : no operator found which takes a left-hand
operand of type 'const boost::numeric::ublas::matrix_reference<E>' (or
there is no acceptable conversion) c:\program
files\boost\boost_1_35_0\boost\numeric\ublas\matrix_proxy.hpp

What am I doing wrong?