const size_type j) const;
/**
- * Return the main diagonal
- * element in the <i>i</i>th
- * row. This function throws an
- * error if the matrix is not
- * quadratic.
+ * Return the main diagonal element in the <i>i</i>th row. This function
+ * throws an error if the matrix is not quadratic.
*
* This function is considerably faster than the operator()(), since for
* quadratic matrices, the diagonal entry may be the first to be stored in
*/
number &diag_element (const size_type i);
+ /**
+ * Extracts a copy of the values and indices in the given matrix row.
+ *
+ * The user is expected to pass the length of the arrays column_indices and
+ * values, which gives a means for checking that we do not write to
+ * unallocated memory. This method is motivated by a similar method in
+ * Trilinos row matrices and gives faster access to entries in the matrix as
+ * compared to iterators which are quite slow for this matrix type.
+ */
+ void extract_row_copy (const size_type row,
+ const size_type array_length,
+ size_type &row_length,
+ size_type *column_indices,
+ number *values) const;
+
//@}
/**
* @name Matrix vector multiplications
}
+
+template <typename number>
+void
+ChunkSparseMatrix<number>::extract_row_copy (const size_type row,
+ const size_type array_length,
+ size_type &row_length,
+ size_type *column_indices,
+ number *values) const
+{
+ row_length = cols->row_length(row);
+ const unsigned int chunk_size = cols->get_chunk_size();
+ const size_type reduced_row = row/chunk_size;
+ AssertIndexRange(cols->sparsity_pattern.row_length(reduced_row)*chunk_size,
+ array_length+1);
+
+ SparsityPattern::iterator it = cols->sparsity_pattern.begin(reduced_row),
+ itend = cols->sparsity_pattern.end(reduced_row);
+ const number *val_ptr = &val[(it-cols->sparsity_pattern.begin(0))*chunk_size*chunk_size
+ +(row%chunk_size)*chunk_size];
+ for ( ; it < itend; ++it)
+ {
+ for (unsigned int c=0; c<chunk_size; ++c)
+ {
+ *values++ = val_ptr[c];
+ *column_indices++ = it->column()*chunk_size+c;
+ }
+ val_ptr += chunk_size*chunk_size;
+ }
+}
+
+
+
template <typename number>
template <class OutVector, class InVector>
void