From 0f85b086931cd286abc850ad4ee1e3eb6075f528 Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Sun, 12 Jan 2014 20:46:10 +0100 Subject: [PATCH] add trace for ImmutableMatrix --- triqs/arrays/matrix.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/triqs/arrays/matrix.hpp b/triqs/arrays/matrix.hpp index 1562ef3d..0b50b15b 100644 --- a/triqs/arrays/matrix.hpp +++ b/triqs/arrays/matrix.hpp @@ -222,6 +222,16 @@ namespace triqs { namespace arrays { return a; } + template + TYPE_ENABLE_IF(typename M::value_type, ImmutableMatrix) trace(M const &m) { + auto r = typename M::value_type{}; + if (first_dim(m) != second_dim(m)) + TRIQS_RUNTIME_ERROR << " Trace of a non square matrix"; + auto d = first_dim(m); + for (int i = 0; i < d; ++i) + r += m(i, i); + return r; + } }}//namespace triqs::arrays // The std::swap is WRONG for a view because of the copy/move semantics of view.