From d2ef27c142c6d4825762075fffa7bf5d4f9838ef Mon Sep 17 00:00:00 2001 From: brian Date: Mon, 2 Jun 2003 13:51:46 +0000 Subject: [PATCH] added functions *= and /= for consistency with similar functions in FullMatrix, Vector classes. git-svn-id: https://svn.dealii.org/trunk@7717 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/include/lac/sparse_matrix.h | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/deal.II/lac/include/lac/sparse_matrix.h b/deal.II/lac/include/lac/sparse_matrix.h index 2bdf3e96f1..8cfea37b48 100644 --- a/deal.II/lac/include/lac/sparse_matrix.h +++ b/deal.II/lac/include/lac/sparse_matrix.h @@ -371,6 +371,18 @@ class SparseMatrix : public virtual Subscriptor void set (const unsigned int i, const unsigned int j, const number value); + /** + * Multiply the entire matrix by a + * fixed factor. + */ + SparseMatrix & operator *= (const number factor); + + /** + * Divide the entire matrix by a + * fixed factor. + */ + SparseMatrix & operator /= (const number factor); + /** * Add @p{value} to the element * @p{(i,j)}. Throws an error if @@ -1252,6 +1264,44 @@ void SparseMatrix::add (const unsigned int i, +template +inline +SparseMatrix & +SparseMatrix::operator *= (const number factor) +{ + Assert (cols != 0, ExcMatrixNotInitialized()); + Assert (val != 0, ExcMatrixNotInitialized()); + + number *val_ptr = &val[0]; + const number *const end_ptr = &val[cols->n_nonzero_elements()]; + + while (val_ptr != end_ptr) + *val_ptr++ *= factor; + + return *this; +} + + + +template +inline +SparseMatrix & +SparseMatrix::operator /= (const number factor) +{ + Assert (cols != 0, ExcMatrixNotInitialized()); + Assert (val != 0, ExcMatrixNotInitialized()); + + number *val_ptr = &val[0]; + const number *const end_ptr = &val[cols->n_nonzero_elements()]; + + while (val_ptr != end_ptr) + *val_ptr++ /= factor; + + return *this; +} + + + template inline number SparseMatrix::operator () (const unsigned int i, -- 2.39.5