Functional maths operators
Include <mln/core/functional_ops.hpp>
Component-wise
-
auto abs(Scalar s)
-
auto abs(Scalar s)
-
auto abs(Vector v)
Returns the absolute value of
s
: \(r = \lvert s \rvert\).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}
-
auto abs(Vector v)
-
auto pow(Scalar s, Scalar p)
-
auto pow(Scalar s, Scalar p)
-
auto pow(Vector v, Scalar p)
Returns
s
exponentp
: \(r = s^p\).Returns each component of
v
exponentp
: \(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}
-
auto pow(Vector v, Scalar p)
-
auto sqr(Scalar s)
-
auto sqr(Scalar s)
-
auto sqr(Vector v)
Returns the square value of
s
: \(r = s^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}
-
auto sqr(Vector v)
-
auto cbrt(Scalar s)
-
auto cbrt(Scalar s)
-
auto cbrt(Vector v)
Returns the cubic root of
s
: \(r = \sqrt[3]{s}\).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}
-
auto cbrt(Vector v)
-
auto sqrt(Scalar s)
-
auto sqrt(Scalar s)
-
auto sqrt(Vector v)
Returns the square root of
s
: \(r = \sqrt{s}\).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}
-
auto sqrt(Vector v)
Reduction
-
auto sum(Scalar s)
-
auto sum(Scalar s)
-
auto sum(Vector v)
Returns
s
: \(r = s\).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
-
auto sum(Vector v)
-
auto prod(Scalar s)
-
auto prod(Scalar s)
-
auto prod(Vector v)
Returns
s
: \(r = s\).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
-
auto prod(Vector v)
-
auto min(Scalar s)
-
auto min(Scalar s)
-
auto min(Vector v)
Returns
s
: \(r = s\).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
-
auto min(Vector v)
-
auto max(Scalar s)
-
auto max(Scalar s)
-
auto max(Vector v)
Returns
s
: \(r = s\).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
-
auto max(Vector v)
-
auto dot(Vector v1, Vector v2)
Returns the scalar product of
v1
byv2
: \(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
-
auto dot(Vector v1, Vector v2)
-
auto cross(Vector v1, Vector v2)
Returns the cross product of
v1
byv2
: \(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.
-
auto cross(Vector v1, Vector v2)
Norms
-
auto l0norm(Scalar s)
-
auto l0norm(Scalar s)
-
auto l0norm(Vector v)
Returns the absolute value norm of
s
: \(r = \lvert s \rvert\).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
-
auto l0norm(Vector v)
-
auto l1norm(Scalar s)
-
auto l1norm(Scalar s)
-
auto l1norm(Vector v)
Returns the absolute value norm of
s
: \(r = \lvert s \rvert\).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
-
auto l1norm(Vector v)
-
auto l2norm(Scalar s)
-
auto l2norm(Scalar s)
-
auto l2norm(Vector v)
Returns the euclidean norm of
s
: \(r = \lvert s \rvert\).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
-
auto l2norm(Vector v)
-
auto l2norm_sqr(Scalar s)
-
auto l2norm_sqr(Scalar s)
-
auto l2norm_sqr(Vector v)
Returns the squared euclidean norm of
s
: \(r = \lvert s \rvert^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
-
auto l2norm_sqr(Vector v)
-
auto linfnorm(Scalar s)
-
auto linfnorm(Scalar s)
-
auto linfnorm(Vector v)
Returns the absolute value norm of
s
: \(r = \lvert s \rvert\).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
-
auto linfnorm(Vector v)
-
template<unsigned p>
auto lpnorm<p>(Vector v) Returns the p-euclidean norm of
s
: \(r = \lvert s \rvert\).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...
-
template<unsigned p>
Distances
-
auto l0dist(Scalar s1, Scalar s2)
-
auto l0dist(Scalar s1, Scalar s2)
-
auto l0dist(Vector v1, Vector v2)
Returns the distance between
s1
ands2
: \(d = \lvert s_1 - s_2 \rvert\).Returns the distance normalized (min of absolute values) between
v1
andv2
: \(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
-
auto l0dist(Vector v1, Vector v2)
-
auto l1dist(Scalar s1, Scalar s2)
-
auto l1dist(Scalar s1, Scalar s2)
-
auto l1dist(Vector v1, Vector v2)
Returns the distance between
s1
ands2
: \(d = \lvert s_1 - s_2 \rvert\).Returns the distance normalized (sum of absolute values) between
v1
andv2
: \(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
-
auto l1dist(Vector v1, Vector v2)
-
auto l2dist(Scalar s1, Scalar s2)
-
auto l2dist(Scalar s1, Scalar s2)
-
auto l2dist(Vector v1, Vector v2)
Returns the distance between
s1
ands2
: \(d = \lvert s_1 - s_2 \rvert\).Returns the distance normalized (euclidean) between
v1
andv2
: \(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
-
auto l2dist(Vector v1, Vector v2)
-
auto l2dist_sqr(Scalar s1, Scalar s2)
-
auto l2dist_sqr(Scalar s1, Scalar s2)
-
auto l2dist_sqr(Vector v1, Vector v2)
Returns the squared distance between
s1
ands2
: \(d = \lvert s_1 - s_2 \rvert^2\).Returns the squared distance normalized (euclidean) between
v1
andv2
: \(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
-
auto l2dist_sqr(Vector v1, Vector v2)
-
auto linfdist(Scalar s1, Scalar s2)
-
auto linfdist(Scalar s1, Scalar s2)
-
auto linfdist(Vector v1, Vector v2)
Returns the distance between
s1
ands2
: \(d = \lvert s_1 - s_2 \rvert\).Returns the distance normalized (max of absolute values) between
v1
andv2
: \(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
-
auto linfdist(Vector v1, Vector v2)
-
template<unsigned p>
auto lpdist<p>(Vector v1, Vector v2) Returns the distance between
s1
ands2
: \(d = \lvert s_1 - s_2 \rvert\).Returns the distance normalized (p-euclidean) between
v1
andv2
: \(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
-
template<unsigned p>