Boost logo

Ublas :

From: Riccardo Rossi (rrossi_at_[hidden])
Date: 2005-12-13 14:03:36

hi all...

      i am somehow a newbie of ublas (currently using 1.32.0) and ... i am having some troubles with the compressed_matrix

in particular i am trying to write a optimized funcion to do a product of the type

A += trans(B)*B

where all the matrix involved are sparse.

i want to preallocate on my own the matrix A and to be sure not to modify its sparsity in processing it...
in other words i would like to get an error when i try to access an index that does not exist

is it possible?

the code i wrote is attached ... but it feels free of allocating dynamically new memory if needed

P.S. does it exist any efficient way of dealign with symmetric compressed matrices? they tend to be quite frequent in FE applications...

greetings and thanks in advance

for (size_type k = 0; k < input.size1 (); ++ k)


size_type begin = input.index1_data () [k];

size_type end = input.index1_data () [k + 1];

for (size_type i = begin; i < end; ++ i)


unsigned int index_i = input.index2_data () [i];

value_type data_i = input.value_data()[i];

for (size_type j = begin; j < end; ++ j)


unsigned int index_j = input.index2_data () [j];

output(index_i,index_j) += data_i * input.value_data()[j];




//std::cout << k << " nnz = " << end << " " << begin << std::endl;