* mln/norm/l2.hh (mln::norm::internal::sqr_l2_(const V&)):
New function.
(mln::norm::sqr_l2(const C (&vec)[n]))
(mln::norm::sqr_l2(const algebra::vec<n,C>&)):
New facades.
---
milena/ChangeLog | 10 ++++++++++
milena/mln/norm/l2.hh | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index a2f96af..8572d83 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,15 @@
2008-12-30 Roland Levillain <roland(a)lrde.epita.fr>
+ Add a squared L2-norm.
+
+ * mln/norm/l2.hh (mln::norm::internal::sqr_l2_(const V&)):
+ New function.
+ (mln::norm::sqr_l2(const C (&vec)[n]))
+ (mln::norm::sqr_l2(const algebra::vec<n,C>&)):
+ New facades.
+
+2008-12-30 Roland Levillain <roland(a)lrde.epita.fr>
+
Add a missing accessor in mln::p_complex.
* mln/core/site_set/p_complex.hh
diff --git a/milena/mln/norm/l2.hh b/milena/mln/norm/l2.hh
index 397c7e7..03e1142 100644
--- a/milena/mln/norm/l2.hh
+++ b/milena/mln/norm/l2.hh
@@ -46,6 +46,13 @@
namespace mln
{
+ // Forward declaration.
+ namespace algebra
+ {
+ template <unsigned n, typename T> class vec;
+ }
+
+
namespace norm
{
@@ -58,6 +65,15 @@ namespace mln
mln_sum(C) l2(const algebra::vec<n,C>& vec);
/// \}
+ /// Squared L2-norm of a vector \a vec.
+ /// \{
+ template <unsigned n, typename C>
+ mln_sum(C) sqr_l2(const C (&vec)[n]);
+
+ template <unsigned n, typename C>
+ mln_sum(C) sqr_l2(const algebra::vec<n,C>& vec);
+ /// \}
+
/// L2-norm distance between vectors \a vec1 and \p vec2.
/// \{
template <unsigned n, typename C>
@@ -92,6 +108,17 @@ namespace mln
template <unsigned n, typename C, typename V>
inline
mln_sum(C)
+ sqr_l2_(const V& vec)
+ {
+ mln_sum(C) m = 0;
+ for (unsigned i = 0; i < n; ++i)
+ m += mln::math::sqr(vec[i]);
+ return m;
+ }
+
+ template <unsigned n, typename C, typename V>
+ inline
+ mln_sum(C)
l2_distance_(const V& vec1, const V& vec2)
{
typedef mln_sum(C) D;
@@ -127,6 +154,24 @@ namespace mln
return impl::l2_<n, C>(vec);
}
+
+ template <unsigned n, typename C>
+ inline
+ mln_sum(C)
+ sqr_l2(const C (&vec)[n])
+ {
+ return impl::sqr_l2_<n, C>(vec);
+ }
+
+ template <unsigned n, typename C>
+ inline
+ mln_sum(C)
+ sqr_l2(const algebra::vec<n,C>& vec)
+ {
+ return impl::sqr_l2_<n, C>(vec);
+ }
+
+
template <unsigned n, typename C>
inline
mln_sum(C)
--
1.6.0.4
Show replies by date