Boost logo

Boost :

From: Benedikt Weber (weber_at_[hidden])
Date: 2002-06-23 13:11:27

I was playing around with ublas today to better understand how it works. One
point that got my attention is the 2-dimensional iterator (officially
"iterator1" and "iterator2"). I was assuming that the iterators of a sparse
matrix iterate over the non-zero elements, but when trying it out, I found
the following:

numerics::sparse_matrix<double> A(3,3,1);
 A(0,0)= 1;

 for (numerics::sparse_matrix<double>::iterator1 i= A.begin1(); i !=
A.end1(); ++i)
  for (numerics::sparse_matrix<double>::iterator2 j= i.begin(); j !=
i.end(); ++j)
    std::cout << "(" << i.index1() << "," << j.index2() << ") ";
 std::cout << std::endl;

 This prints out:
 (0,0) (1,0) (1,1) (1,2) (2,0) (2,1) (2,2)

Is this intention and what would the reason, or is it a bug?

The consequence is that matrix multiplication takes very long for sparse
matrices. The following code takes forever, even though there is only one
multiplication involved.

// large matrices with just one entry
 numerics::sparse_matrix<double> B(1000,1000,1);
 numerics::sparse_matrix<double> C(1000,1000,1);
 B(0,0)= 1;
 C(0,0)= 1;
numerics::sparse_matrix<double> D= numerics::prod(B,C);

I certainly hope this is an easy to fix implementation bug or a wrong
interpretation on my side and not a design problem. (sparse_vector works a
expected and so is the sparse_matrix/sparce_vector multiplication)

Benedikt Weber

Boost list run by bdawes at, gregod at, cpdaniel at, john at