TRIQS / nda

C++ library for multi-dimensional arrays
https://triqs.github.io/nda
Other
13 stars 11 forks source link

l2 norm function #33

Closed jasonkaye closed 1 year ago

jasonkaye commented 1 year ago

It would be nice to have a function which computes the l^2 norm of an NDA vector, as

norm(v)

or

norm2(v).

One could also have norm(v,p) to compute l^p norm.

dominikkiese commented 1 year ago

Ran into the same thing. I don't know if this is a good way to do it, but what about:

template <typename T> double norm2(nda::array<T, 1> const &v) { return std::sqrt(nda::blas::dot(v, v)); };

Wentzell commented 1 year ago

Thank you for the suggestion

I added a generic p-norm implementation here c2d519a

@jasonkaye Please have a look and let me know if you agree.

Wentzell commented 1 year ago

I moved the implementation into nda/linalg/norm.hpp. You make it available by including nda/linalg.hpp

jasonkaye commented 1 year ago

Thank you for the suggestion

I added a generic p-norm implementation here c2d519a

@jasonkaye Please have a look and let me know if you agree.

Looks great, thanks.