Skip to content
Snippets Groups Projects
Commit fc6e47de authored by Timo Koch's avatar Timo Koch
Browse files

[math] Improve trace to work with all dense matrices

parent 13c861ab
No related branches found
No related tags found
1 merge request!807Feature/improve math functions
...@@ -637,20 +637,21 @@ Dune::FieldMatrix<Scalar, rows1, cols2> multiplyMatrices(const Dune::FieldMatrix ...@@ -637,20 +637,21 @@ Dune::FieldMatrix<Scalar, rows1, cols2> multiplyMatrices(const Dune::FieldMatrix
/*! /*!
* \ingroup Common * \ingroup Common
* \brief Trace of dynamic matrix * \brief Trace of a dense matrix
* *
* \param M The dynamic matrix * \param M The dense matrix
*/ */
template <class Scalar> template <class MatrixType>
Scalar trace(const Dune::DynamicMatrix<Scalar>& M) typename Dune::DenseMatrix<MatrixType>::field_type
trace(const Dune::DenseMatrix<MatrixType>& M)
{ {
std::size_t rows_T = M.M(); const auto rows = M.N();
DUNE_ASSERT_BOUNDS(rows == M.M()); // rows == cols
DUNE_ASSERT_BOUNDS(rows_T == M.N()); using MatType = Dune::DenseMatrix<MatrixType>;
typename MatType::field_type trace = 0.0;
Scalar trace = 0.0; for (typename MatType::size_type i = 0; i < rows; ++i)
for (std::size_t i = 0; i < rows_T; ++i)
trace += M[i][i]; trace += M[i][i];
return trace; return trace;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment