From: Niklas Fehn Date: Tue, 7 Mar 2017 10:41:42 +0000 (+0100) Subject: Add operators *= and /= to LAPACKFullMatrix X-Git-Tag: v8.5.0-rc1~55^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4046%2Fhead;p=dealii.git Add operators *= and /= to LAPACKFullMatrix --- diff --git a/include/deal.II/lac/lapack_full_matrix.h b/include/deal.II/lac/lapack_full_matrix.h index ecf25ee85f..e31861687e 100644 --- a/include/deal.II/lac/lapack_full_matrix.h +++ b/include/deal.II/lac/lapack_full_matrix.h @@ -121,6 +121,18 @@ public: LAPACKFullMatrix & operator = (const double d); + /** + * This operator multiplies all entries by a fixed factor. + */ + LAPACKFullMatrix & + operator*= (const number factor); + + /** + * This operator divides all entries by a fixed factor. + */ + LAPACKFullMatrix & + operator/= (const number factor); + /** * Assignment from different matrix classes, performing the usual conversion * to the transposed format expected by LAPACK. This assignment operator diff --git a/source/lac/lapack_full_matrix.cc b/source/lac/lapack_full_matrix.cc index 29029c4ddc..7b46ef45a8 100644 --- a/source/lac/lapack_full_matrix.cc +++ b/source/lac/lapack_full_matrix.cc @@ -130,6 +130,41 @@ LAPACKFullMatrix::operator = (const double d) } +template +LAPACKFullMatrix & +LAPACKFullMatrix::operator*= (const number factor) +{ + Assert(state == LAPACKSupport::matrix || + state == LAPACKSupport::inverse_matrix, + ExcState(state)); + + for (unsigned int column = 0; columnn(); ++column) + for (unsigned int row = 0; rowm(); ++row) + (*this)(row,column) *= factor; + + return *this; +} + + +template +LAPACKFullMatrix & +LAPACKFullMatrix::operator/= (const number factor) +{ + Assert(state == LAPACKSupport::matrix || + state == LAPACKSupport::inverse_matrix, + ExcState(state)); + + AssertIsFinite(factor); + Assert (factor != number(0.), ExcZero() ); + + for (unsigned int column = 0; columnn(); ++column) + for (unsigned int row = 0; rowm(); ++row) + (*this)(row,column) /= factor; + + return *this; +} + + template void LAPACKFullMatrix::vmult ( diff --git a/tests/lapack/full_matrix_13.cc b/tests/lapack/full_matrix_13.cc new file mode 100644 index 0000000000..cd649d1449 --- /dev/null +++ b/tests/lapack/full_matrix_13.cc @@ -0,0 +1,69 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2014 - 2015 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Tests LAPACKFullMatrix::operator*= and operator/= + +#include "../tests.h" +#include +#include + +#include +#include + + + +void test() +{ + const unsigned int m=7; + const unsigned int n=11; + LAPACKFullMatrix A(m,n); + for (unsigned int i=0; i A_check(A); + + const double factor = 2.345; + + // multiply by factor + A *= factor; + + // test multiplication + for (unsigned int i=0; i