Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-03-05 09:08:16


Hi,

On Monday 05 March 2007 14:34, Preben Hagh Strunge Holm wrote:
> I often use this kind of matrix:
>
>
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> ...
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X X X X X X X X X X 0 0 0
> ...
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 X X X X X X X X X X 0 0 0
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
...
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
>
>
> where the X's are numbers, and the zero's are always zero's.
>
> I multiply the matrix with other matrices and vectors which are standard
> and dense.

You could use a custom class and overload the prod() function (or simpler
provide a special axpy_prod) which looks like

project(y, range(r1,r2)) += prod( submatrix, project(x, range(c1,c2)) )

where submatrix has size (r2-r1)x(c2-c1). Using a sparse matrix is also
possible but may be slower because you have to store the column indices.
Usually the dense algorithm wins over the sparse when there are more than 25%
non-zeros in you matrix.

Alternatively you could develop a new block-sparse matrix class (which would
be very interesting) and contribute it to ublas.

mfg
Gunter