3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-25 22:03:43 +01:00

arrays: add make_unit_matrix and norm2, norm2_sqr

This commit is contained in:
Olivier Parcollet 2014-02-16 15:43:50 +01:00
parent 1c9d6dacfa
commit 76e39c826f
2 changed files with 22 additions and 0 deletions

View File

@ -208,6 +208,14 @@ namespace triqs { namespace arrays {
#undef _IMPL_MATRIX_COMMON #undef _IMPL_MATRIX_COMMON
#undef IMPL_TYPE #undef IMPL_TYPE
template<typename V>
matrix <V> make_unit_matrix(int dim) {
matrix<V> r(dim, dim);
r() = 1;
return r;
}
template<typename ArrayType> template<typename ArrayType>
matrix_view<typename ArrayType::value_type, ArrayType::opt_flags, ArrayType::traversal_order> matrix_view<typename ArrayType::value_type, ArrayType::opt_flags, ArrayType::traversal_order>
make_matrix_view(ArrayType const & a) { make_matrix_view(ArrayType const & a) {

View File

@ -223,6 +223,20 @@ namespace triqs { namespace arrays {
#include "./blas_lapack/axpy.hpp" #include "./blas_lapack/axpy.hpp"
namespace triqs { namespace arrays { namespace triqs { namespace arrays {
// norm2 squared
template <typename V> typename std::enable_if<ImmutableVector<V>::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 V> typename std::enable_if<ImmutableVector<V>::value, typename V::value_type>::type norm2(V const& a) {
using std::sqrt;
return sqrt(norm2(a));
}
// lexicographical comparison operators // lexicographical comparison operators
template<typename V1, typename V2> template<typename V1, typename V2>
typename std::enable_if< ImmutableVector<V1>::value && ImmutableVector<V2>::value , bool>::type typename std::enable_if< ImmutableVector<V1>::value && ImmutableVector<V2>::value , bool>::type