diff --git a/triqs/arrays/matrix.hpp b/triqs/arrays/matrix.hpp index 0b50b15b..34d1aeb6 100644 --- a/triqs/arrays/matrix.hpp +++ b/triqs/arrays/matrix.hpp @@ -208,6 +208,14 @@ namespace triqs { namespace arrays { #undef _IMPL_MATRIX_COMMON #undef IMPL_TYPE + + template + matrix make_unit_matrix(int dim) { + matrix r(dim, dim); + r() = 1; + return r; + } + template matrix_view make_matrix_view(ArrayType const & a) { diff --git a/triqs/arrays/vector.hpp b/triqs/arrays/vector.hpp index e5009355..74b530d2 100644 --- a/triqs/arrays/vector.hpp +++ b/triqs/arrays/vector.hpp @@ -223,6 +223,20 @@ namespace triqs { namespace arrays { #include "./blas_lapack/axpy.hpp" namespace triqs { namespace arrays { + // norm2 squared + template typename std::enable_if::value, typename V::value_type>::type norm2_sqr(V const& a) { + int dim = a.size(); + auto r = typename V::value_type{}; + for (int i = 0; i < dim; ++i) r += a(i) * a(i); + return r; + } + + // norm2 + template typename std::enable_if::value, typename V::value_type>::type norm2(V const& a) { + using std::sqrt; + return sqrt(norm2(a)); + } + // lexicographical comparison operators template typename std::enable_if< ImmutableVector::value && ImmutableVector::value , bool>::type