Hi,

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?

Thanks, Julius



Julius Muschaweck

_____________________________________________________
OEC AG
Paul-Gerhardt-Allee 42
81245 Muenchen, Germany

Phone: +49 89 820050-30
Fax:   +49 89 820050-41
e-mail:    <muschaweck@oec.net>
Internet:   www.oec.net
______________________________________________________