mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 13:53:40 +01:00
arrays: add make_unit_matrix and norm2, norm2_sqr
This commit is contained in:
parent
1c9d6dacfa
commit
76e39c826f
@ -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) {
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user