Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2008-06-21 17:17:03

Nico Galoppo schrieb:
> Hi,
> What is the best way to find out if the nonzero structure of two
> sparse matrices is the same (assume both have the same type,
> compressed_matrix<T,O>)?
I think the fastest way is to directly compare index1_data and
index2_data. An efficient merge of two sparse structures is a
non-trivial task. So most people prefer to force both matrices to have
the same structure. Others simply convert the matrices to coordinate
matrices add the arrays and sort & compress back to compressed matrix.
> On a similar note, if they aren't, I need this type of query: say A
> and B are sparse, slightly different structure. Say C = A + B also
> sparse. Iterating over C.value_data()[i], I'd like to find out the
> corresponding indices (i,j) into A and B.
I don't exactly understand what you mean. If you only know the index
into value_data, then you also know the column index (from
index2_data[i]) but you have to search the row index such that
index1_data[j] <= i < index1_data[j+1]