From f683cc276cd82f33d2f707bdf567db1f871beeb0 Mon Sep 17 00:00:00 2001 From: Wasim Niyaz Munshi Date: Tue, 4 Feb 2025 16:44:00 -0700 Subject: [PATCH] Add checks that src is not equal to dst in mmult(). --- include/deal.II/lac/full_matrix.templates.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/deal.II/lac/full_matrix.templates.h b/include/deal.II/lac/full_matrix.templates.h index e6a01a9ae1..8fe9efd0b9 100644 --- a/include/deal.II/lac/full_matrix.templates.h +++ b/include/deal.II/lac/full_matrix.templates.h @@ -519,10 +519,19 @@ FullMatrix::mmult(FullMatrix &dst, Assert(n() == src.m(), ExcDimensionMismatch(n(), src.m())); Assert(dst.n() == src.n(), ExcDimensionMismatch(dst.n(), src.n())); Assert(dst.m() == m(), ExcDimensionMismatch(m(), dst.m())); + if constexpr (std::is_same_v) + { + Assert(&dst != this, + ExcMessage( + "The output matrix cannot be the same as the current matrix.")); + Assert(&dst != &src, + ExcMessage( + "The output matrix cannot be the same as the input matrix.")); + } - // see if we can use BLAS algorithms for this and if the type for 'number' - // works for us (it is usually not efficient to use BLAS for very small - // matrices): + // see if we can use BLAS algorithms for this and if the type for 'number' + // works for us (it is usually not efficient to use BLAS for very small + // matrices): #ifdef DEAL_II_WITH_LAPACK const size_type max_blas_int = std::numeric_limits::max(); if ((std::is_same_v || -- 2.39.5