Boost logo

Boost :

From: Joerg Walter (jhr.walter_at_[hidden])
Date: 2003-01-29 16:03:12


Hi Julius,

you wrote:

> to me it looks like there may be a bug with sparse_matrix and matrix_row.
> I was building a large sparse matrix from some smaller ones. When I tried
to assign a
> matrix_row of a sparse_matrix to another matrix_row of another
sparse_matrix, nothing > happened. When I mix sparse_matrix with matrix, it
works as I expected, but then the
> sparse matrix isn't sparse anymore.
>
> I tried this with the following code:
>
> void SparseBug()
> {
> using namespace boost::numeric;
> typedef ublas::sparse_matrix<double> TSM;
> typedef ublas::matrix<double> TM;
> TSM sm1(3,3);
> TSM sm2(3,3);
> TM m1(3,3);
> TM m2(3,3);
> sm1(1,1) = m1(1,1) = 2.;
> ublas::matrix_row<TSM> (sm2,1) = ublas::matrix_row<TSM> (sm1,1);
> ublas::matrix_row<TM> (m2,1) = ublas::matrix_row<TM> (m1,1);
> std::cout << "matrix=matrix: m2(1,1) should be " << m1(1,1) << ",
is "<< m2(1,1) > << std::endl;
> std::cout << "sparse_matrix=sparse_matrix: sm2(1,1) should be " <<
sm1(1,1) << > ", is "<< sm2(1,1) << std::endl;
> ublas::matrix_row<TSM> (sm2,1) = ublas::matrix_row<TM> (m1,1);
> std::cout << "sparse_matrix=matrix: sm2(1,1) should be " <<
m1(1,1) << ", is "<< > sm2(1,1) << std::endl;
> ublas::matrix_row<TM> (m2,1) = ublas::matrix_row<TSM> (sm1,1);
> std::cout << "matrix=sparse_matrix: m2(1,1) should be " <<
sm1(1,1) << ", is "<< > m2(1,1) << std::endl;
> };
>
> and got
>
> matrix=matrix: m2(1,1) should be 2, is 2
> sparse_matrix=sparse_matrix: sm2(1,1) should be 2, is 0
> sparse_matrix=matrix: sm2(1,1) should be 2, is 2
> matrix=sparse_matrix: m2(1,1) should be 2, is 2
>
> on my Win2000 SP3 machine with Microsoft VC++.net in debug mode.
>
> Has anyone an idea?

I just fed this into GCC 3.2.1 and got the following results with my current
version (in debug & release mode):

matrix=matrix: m2(1,1) should be 2,is 2
sparse_matrix=sparse_matrix: sm2(1,1) should be 2, is 2
sparse_matrix=matrix: sm2(1,1) should be 2, is 2
matrix=sparse_matrix: m2(1,1) should be 2, is 2

So I'm assuming you're using the boost_1_29_0 distribution. ublas had an
undocumented restriction regarding sparse proxy assignment at that time,
which was later resolved thanks to Michael Stevens.

I'm a bit surprised that ublas's debug mode didn't alert you, though.

Sorry for the inconvenience,

Joerg

P.S.: Please see Boost CVS for a more current version of ublas.

P.P.S.: Did you already consider to use compressed_matrix<>?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk