Commit 4d12d309 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Add l1dist and l2dist_sqr as mathematical operations.

    *  mln/core/math_ops.hpp: l1dist implementation.
    *  mln/core/vec/vec_math_ops.hpp: l1dist and l2dist_sqr
       implementation.
parent 859b763b
......@@ -129,6 +129,17 @@ namespace mln
double l2dist(double x, double y);
long double l2dist(long double x, long double y);
int l1dist(int x, int y);
long l1dist(long x, long y);
long long l1dist(long long x, long long y);
unsigned int l1dist(unsigned int x, unsigned int y);
unsigned long l1dist(unsigned long x, unsigned long y);
unsigned long long l1dist(unsigned long long x, unsigned long long y);
float l1dist(float x, float y);
double l1dist(double x, double y);
long double l1dist(long double x, long double y);
int l2norm_sqr(int x);
long l2norm_sqr(long n);
......@@ -318,6 +329,18 @@ namespace mln
MLN_GEN_BINARY_CODE(l2dist, long double, abs(x - y));
MLN_FUNCTIONAL_GEN_BINARY_CODE(l2dist);
MLN_GEN_BINARY_CODE(l1dist, int, abs(x - y));
MLN_GEN_BINARY_CODE(l1dist, long, abs(x - y));
MLN_GEN_BINARY_CODE(l1dist, long long, abs(x - y));
MLN_GEN_BINARY_CODE(l1dist, unsigned int, abs(x - y));
MLN_GEN_BINARY_CODE(l1dist, unsigned long, abs(x - y));
MLN_GEN_BINARY_CODE(l1dist, unsigned long long, abs(x - y));
MLN_GEN_BINARY_CODE(l1dist, float, abs(x - y));
MLN_GEN_BINARY_CODE(l1dist, double, abs(x - y));
MLN_GEN_BINARY_CODE(l1dist, long double, abs(x - y));
MLN_FUNCTIONAL_GEN_BINARY_CODE(l1dist);
MLN_GEN_CODE(l2norm_sqr, int, sqr(x));
MLN_GEN_CODE(l2norm_sqr, long, sqr(x));
MLN_GEN_CODE(l2norm_sqr, long long, sqr(x));
......
......@@ -93,6 +93,14 @@ namespace mln
MLN_PROMOTE_FUNCOMP(T, pow, abs)
lpnorm(const internal::vec_base<T, dim, tag>& x);
template <typename T, unsigned dim, class tag>
inline
auto
l1dist(const internal::vec_base<T, dim, tag>& x,
const internal::vec_base<T, dim, tag>& y)
-> decltype(l1norm(x-y));
template <typename T, unsigned dim, class tag>
inline
auto
......@@ -100,6 +108,12 @@ namespace mln
const internal::vec_base<T, dim, tag>& y)
-> decltype(l2norm(x-y));
template <typename T, unsigned dim, class tag>
inline
auto
l2dist_sqr(const internal::vec_base<T, dim, tag>& x,
const internal::vec_base<T, dim, tag>& y)
-> decltype(l2norm_sqr(x-y));
/*****************************/
/** Implementation ***/
......@@ -135,7 +149,9 @@ namespace mln
MLN_GEN_CODE(abs);
MLN_GEN_CODE(cbrt);
MLN_GEN_BINARY_CODE(l1dist, l1norm, x-y);
MLN_GEN_BINARY_CODE(l2dist, l2norm, x-y);
MLN_GEN_BINARY_CODE(l2dist_sqr, l2norm_sqr, x-y);
template <class U, class V, unsigned dim, class tag>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment