mirror of
https://github.com/triqs/dft_tools
synced 2025-01-12 14:08:24 +01:00
add trace for ImmutableMatrix
This commit is contained in:
parent
92f4df91fe
commit
0f85b08693
@ -222,6 +222,16 @@ namespace triqs { namespace arrays {
|
||||
return a;
|
||||
}
|
||||
|
||||
template <typename M>
|
||||
TYPE_ENABLE_IF(typename M::value_type, ImmutableMatrix<M>) 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.
|
||||
|
Loading…
Reference in New Issue
Block a user