Functional maths operators

Include <mln/core/functional_ops.hpp>

Component-wise

  1. auto abs(Scalar s)
  2. auto abs(Vector v)
    1. Returns the absolute value of s: \(r = \lvert s \rvert\).

    2. Returns the absolute value of each component of v: \(r_i = \lvert v_i \rvert\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = -2;
    mln::signed_rgb8 v = {1, -2, 3};
    auto r_s = abs(s); // 2
    auto r_v = abs(v); // {1, 2, 3}
    
  1. auto pow(Scalar s, Scalar p)
  2. auto pow(Vector v, Scalar p)
    1. Returns s exponent p: \(r = s^p\).

    2. Returns each component of v exponent p: \(r_i = v_i^p\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    • p – Input exponent

    mln::int8 s = -2;
    mln::signed_rgb8 v = {1, -2, 3};
    auto r_s = pow(s, 3); // -8
    auto r_v = pow(v, 3); // {1, -8, 27}
    
  1. auto sqr(Scalar s)
  2. auto sqr(Vector v)
    1. Returns the square value of s: \(r = s^2\).

    2. Returns the square value of each component of v: \(r_i = v_i^2\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = -2;
    mln::signed_rgb8 v = {1, -2, 3};
    auto r_s = sqr(s); // 4
    auto r_v = sqr(v); // {1, 4, 9}
    
  1. auto cbrt(Scalar s)
  2. auto cbrt(Vector v)
    1. Returns the cubic root of s: \(r = \sqrt[3]{s}\).

    2. Returns the cubic root of each component of v: \(r_i = \sqrt[3]{v_i}\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 729;
    mln::signed_rgb8 v = {-0.125, 8, 729};
    auto r_s = cbrt(s); // 9
    auto r_v = cbrt(v); // {-0.5, 2, 9}
    
  1. auto sqrt(Scalar s)
  2. auto sqrt(Vector v)
    1. Returns the square root of s: \(r = \sqrt{s}\).

    2. Returns the square root of each component of v: \(r_i = \sqrt{v_i}\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 81;
    mln::signed_rgb8 v = {-0.25, 4, 9};
    auto r_s = sqrt(s); // 9
    auto r_v = sqrt(v); // {-0.5, 2, 3}
    

Reduction

  1. auto sum(Scalar s)
  2. auto sum(Vector v)
    1. Returns s: \(r = s\).

    2. Returns the sum of all components of v: \(r = \sum{v_i}\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {1, -2, 9};
    auto r_s = sum(s); // 9
    auto r_v = sum(v); // 8
    
  1. auto prod(Scalar s)
  2. auto prod(Vector v)
    1. Returns s: \(r = s\).

    2. Returns the product of all components of v: \(r = \prod{v_i}\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {1, -2, 9};
    auto r_s = prod(s); // 9
    auto r_v = prod(v); // -18
    
  1. auto min(Scalar s)
  2. auto min(Vector v)
    1. Returns s: \(r = s\).

    2. Returns the minimum of all components of v: \(r = \min(v_1, v_2, \dots, v_n)\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {1, -2, 9};
    auto r_s = min(s); // 9
    auto r_v = min(v); // -2
    
  1. auto max(Scalar s)
  2. auto max(Vector v)
    1. Returns s: \(r = s\).

    2. Returns the maximum of all components of v: \(r = \max(v_1, v_2, \dots, v_n)\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {1, -2, 9};
    auto r_s = max(s); // 9
    auto r_v = max(v); // 9
    
  1. auto dot(Vector v1, Vector v2)
    1. Returns the scalar product of v1 by v2: \(r = v_1 \cdot v_2\).

    Parameters:
    • v1 – Input vector

    • v2 – Input vector

    mln::signed_rgb8 v1= {9, 1, -2};
    mln::signed_rgb8 v2 = {1, -2, 9};
    auto v = dot(v1, v2); // -11
    
  1. auto cross(Vector v1, Vector v2)
    1. Returns the cross product of v1 by v2: \(r = v_1 \wedge v_2\).

    Parameters:
    • v1 – Input vector

    • v2 – Input vector

    mln::signed_rgb8 v1= {9, 1, -2};
    mln::signed_rgb8 v2 = {1, -2, 9};
    auto v = cross(v1, v2); // {5, -83, -19}
    

    Warning

    The cross product is only defined for vectors of dimension 3 and 7.

Norms

  1. auto l0norm(Scalar s)
  2. auto l0norm(Vector v)
    1. Returns the absolute value norm of s: \(r = \lvert s \rvert\).

    2. Returns the absolute value (min) norm of v: \(r = \lVert v \rVert_0 = \min(\lvert v_1 \rvert, \lvert v_2 \rvert, \dots, \lvert v_n \rvert)\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {1, -2, 9};
    auto r_s = l0norm(s); // 9
    auto r_v = l0norm(v); // 1
    
  1. auto l1norm(Scalar s)
  2. auto l1norm(Vector v)
    1. Returns the absolute value norm of s: \(r = \lvert s \rvert\).

    2. Returns the absolute value (sum) norm of v: \(r = \lVert v \rVert_1 = \sum{\lvert v_i \rvert}\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {1, -2, 9};
    auto r_s = l1norm(s); // 9
    auto r_v = l1norm(v); // 12
    
  1. auto l2norm(Scalar s)
  2. auto l2norm(Vector v)
    1. Returns the euclidean norm of s: \(r = \lvert s \rvert\).

    2. Returns the euclidean norm of v: \(r = \lVert v \rVert_2 = \sqrt{\sum{v_i^2}}\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {2, -4, 4};
    auto r_s = l2norm(s); // 9
    auto r_v = l2norm(v); // 6
    
  1. auto l2norm_sqr(Scalar s)
  2. auto l2norm_sqr(Vector v)
    1. Returns the squared euclidean norm of s: \(r = \lvert s \rvert^2\).

    2. Returns the squared euclidean norm of v: \(r = \lVert v \rVert_2^2 = \sum{v_i^2}\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {2, -4, 4};
    auto r_s = l2norm_sqr(s); // 81
    auto r_v = l2norm_sqr(v); // 36
    
  1. auto linfnorm(Scalar s)
  2. auto linfnorm(Vector v)
    1. Returns the absolute value norm of s: \(r = \lvert s \rvert\).

    2. Returns the absolute value (max) norm of v: \(r = \lVert v \rVert_{inf} = \max(\lvert v_1 \rvert, \lvert v_2 \rvert, \dots, \lvert v_n \rvert)\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    mln::int8 s = 9;
    mln::signed_rgb8 v = {1, -2, 9};
    auto r_s = linfnorm(s); // 9
    auto r_v = linfnorm(v); // 9
    
  1. template<unsigned p>
    auto lpnorm<p>(Scalar s)
  2. template<unsigned p>
    auto lpnorm<p>(Vector v)
    1. Returns the p-euclidean norm of s: \(r = \lvert s \rvert\).

    2. Returns the p-euclidean norm of v: \(r = \lVert v \rVert_p = \sqrt[p]{\sum{\lvert v_i \rvert^p}}\).

    Parameters:
    • s – Input scalar

    • v – Input vector

    Template Parameters:

    p – Norm exponent

    mln::int8 s = 9;
    mln::signed_rgb8 v = {2, -4, 9};
    auto r_s = lpnorm<4>(s); // 9
    auto r_v = lpnorm<4>(v); // 9.09186...
    

Distances

  1. auto l0dist(Scalar s1, Scalar s2)
  2. auto l0dist(Vector v1, Vector v2)
    1. Returns the distance between s1 and s2: \(d = \lvert s_1 - s_2 \rvert\).

    2. Returns the distance normalized (min of absolute values) between v1 and v2: \(d = \lVert v_1 - v_2 \rVert_0\).

    Parameters:
    • s1 – Input scalar

    • s2 – Input scalar

    • v1 – Input vector

    • v2 – Input vector

    mln::int8 s1 = 9;
    mln::int8 s2 = -2;
    mln::signed_rgb8 v1 = {1, 2, 2};
    mln::signed_rgb8 v2 = {3, 6, 6};
    auto d_s = l0dist(s1, s2); // 11
    auto d_v = l0dist(v1, v2); // 2
    
  1. auto l1dist(Scalar s1, Scalar s2)
  2. auto l1dist(Vector v1, Vector v2)
    1. Returns the distance between s1 and s2: \(d = \lvert s_1 - s_2 \rvert\).

    2. Returns the distance normalized (sum of absolute values) between v1 and v2: \(d = \lVert v_1 - v_2 \rVert_1\).

    Parameters:
    • s1 – Input scalar

    • s2 – Input scalar

    • v1 – Input vector

    • v2 – Input vector

    mln::int8 s1 = 9;
    mln::int8 s2 = -2;
    mln::signed_rgb8 v1 = {1, 2, 2};
    mln::signed_rgb8 v2 = {3, 6, 6};
    auto d_s = l1dist(s1, s2); // 11
    auto d_v = l1dist(v1, v2); // 10
    
  1. auto l2dist(Scalar s1, Scalar s2)
  2. auto l2dist(Vector v1, Vector v2)
    1. Returns the distance between s1 and s2: \(d = \lvert s_1 - s_2 \rvert\).

    2. Returns the distance normalized (euclidean) between v1 and v2: \(d = \lVert v_1 - v_2 \rVert_2\).

    Parameters:
    • s1 – Input scalar

    • s2 – Input scalar

    • v1 – Input vector

    • v2 – Input vector

    mln::int8 s1 = 9;
    mln::int8 s2 = -2;
    mln::signed_rgb8 v1 = {1, 2, 2};
    mln::signed_rgb8 v2 = {3, 6, 6};
    auto d_s = l2dist(s1, s2); // 11
    auto d_v = l2dist(v1, v2); // 6
    
  1. auto l2dist_sqr(Scalar s1, Scalar s2)
  2. auto l2dist_sqr(Vector v1, Vector v2)
    1. Returns the squared distance between s1 and s2: \(d = \lvert s_1 - s_2 \rvert^2\).

    2. Returns the squared distance normalized (euclidean) between v1 and v2: \(d = \lVert v_1 - v_2 \rVert_2^2\).

    Parameters:
    • s1 – Input scalar

    • s2 – Input scalar

    • v1 – Input vector

    • v2 – Input vector

    mln::int8 s1 = 9;
    mln::int8 s2 = -2;
    mln::signed_rgb8 v1 = {1, 2, 2};
    mln::signed_rgb8 v2 = {3, 6, 6};
    auto d_s = l2dist_sqr(s1, s2); // 121
    auto d_v = l2dist_sqr(v1, v2); // 36
    
  1. auto linfdist(Scalar s1, Scalar s2)
  2. auto linfdist(Vector v1, Vector v2)
    1. Returns the distance between s1 and s2: \(d = \lvert s_1 - s_2 \rvert\).

    2. Returns the distance normalized (max of absolute values) between v1 and v2: \(d = \lVert v_1 - v_2 \rVert_{inf}\).

    Parameters:
    • s1 – Input scalar

    • s2 – Input scalar

    • v1 – Input vector

    • v2 – Input vector

    mln::int8 s1 = 9;
    mln::int8 s2 = -2;
    mln::signed_rgb8 v1 = {1, 2, 2};
    mln::signed_rgb8 v2 = {3, 6, 6};
    auto d_s = linfdist(s1, s2); // 11
    auto d_v = linfdist(v1, v2); // 4
    
  1. template<unsigned p>
    auto lpdist<p>(Scalar s1, Scalar s2)
  2. template<unsigned p>
    auto lpdist<p>(Vector v1, Vector v2)
    1. Returns the distance between s1 and s2: \(d = \lvert s_1 - s_2 \rvert\).

    2. Returns the distance normalized (p-euclidean) between v1 and v2: \(d = \lVert v_1 - v_2 \rVert_p\).

    Parameters:
    • s1 – Input scalar

    • s2 – Input scalar

    • v1 – Input vector

    • v2 – Input vector

    Template Parameters:

    p – Norm Exponent

    mln::int8 s1 = 9;
    mln::int8 s2 = -2;
    mln::signed_rgb8 v1 = {1, 2, 2};
    mln::signed_rgb8 v2 = {3, 6, 6};
    auto d_s = lpdist<4>(s1, s2); // 11
    auto d_v = lpdist<4>(v1, v2); // 4.79356