2006-11-07 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* xtd/vec.hh (L2_norm): New.
(include): Add cmath header.
Index: xtd/vec.hh
===================================================================
--- xtd/vec.hh (revision 694)
+++ xtd/vec.hh (working copy)
@@ -29,6 +29,8 @@
# define XTD_VEC_HH
# include <iostream>
+# include <cmath>
+
# include <mlc/contract.hh>
# include <xtd/optraits.hh>
@@ -317,6 +319,8 @@
}
+ // lexi_less.
+
struct lexi_less_t
{
template <unsigned n, typename T>
@@ -331,7 +335,6 @@
}
};
-
template <unsigned n, typename T>
bool lexi_less(const vec<n,T>& lhs, const vec<n,T>& rhs)
{
@@ -340,6 +343,19 @@
}
+ // L2_norm.
+
+ template <unsigned n, typename T>
+ float L2_norm(const vec<n,T>& v)
+ {
+ float val = 0.f;
+ for (unsigned i = 0; i < n; ++i)
+ val += float(v[i]) * float(v[i]);
+ return std::sqrt(val);
+ }
+
+
+
template <typename uop,
unsigned n, typename T>
struct set_trait_< uop, vec<n,T> >