Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2006-07-20 04:43:23


Am Donnerstag, 20. Juli 2006 04:18 schrieben Sie:
> I need
> to create a function to swap rows and columns in a sparse matrix. I
> would like to know your opinion about the best template class to use
> in this situation and if you have any suggestion to make this
> function be "fast" considering the problem of row/column storage
> scheme.

You always get the fastest swap operation, when you use constructions
like

std::vector< std::vector<double> >

because a swap of a row is only a swap of two pointers. The
corresponding ublas type is

generalized_vector_of_vector<double, row_major,
compressed_vector<double> >

Then you have fast row swaps. In order to be able to swap rows and
columns simultaniously without expensive operations you should use
"virtual swaps" which means using row and column permutation matrices.
The you always have to use P A Q inplace of the transformed matrix.
Maybe someone volunteers to write a new "permutated_matrix" proxy that
transparantly applies a row and column permutation to the underlying
matrix.

Alternativly you could use symmetric matrices, then swapping two rows
always swaps the corresponding columns, too.

mfg
Gunter