C.clear();
sp_C.reinit (0,0,0);
- // create a sparsity pattern for the matrix. we will go through all the
- // rows in the matrix A, and for each column in a row we add the whole
- // row of matrix B with that row number. This means that we will insert
- // a lot of entries to each row, which is best handled by the
- // DynamicSparsityPattern class.
+ // create a sparsity pattern for the matrix C.
{
- DynamicSparsityPattern dsp (m(), B.n());
- for (size_type i = 0; i < dsp.n_rows(); ++i)
- {
- const size_type *rows = &sp_A.colnums[sp_A.rowstart[i]];
- const size_type *const end_rows =
- &sp_A.colnums[sp_A.rowstart[i+1]];
- for (; rows != end_rows; ++rows)
- {
- const size_type col = *rows;
- size_type *new_cols = const_cast<size_type *>
- (&sp_B.colnums[sp_B.rowstart[col]]);
- size_type *end_new_cols = const_cast<size_type *>
- (&sp_B.colnums[sp_B.rowstart[col+1]]);
-
- // if B has a diagonal, need to add that manually. this way,
- // we maintain sortedness.
- if (sp_B.n_rows() == sp_B.n_cols())
- {
- ++new_cols;
- dsp.add(i, col);
- }
-
- dsp.add_entries (i, new_cols, end_new_cols, true);
- }
- }
+ DynamicSparsityPattern dsp ;
+ dsp.compute_mmult_pattern(sp_A,sp_B);
sp_C.copy_from (dsp);
}