E.V.E  0.1-beta

◆ dist

eve::dist = {}
inlineconstexpr

Callable object computing the distance between two values.

Required header: #include <eve/function/dist.hpp>

Members Functions

Member Effect
operator() the distance operation
operator[] Construct a conditional version of current function object

template< value T, value U > auto operator()( T x, U y ) const noexcept requires compatible< T, U >;

Parameters

x, y: values

Return value

auto r = dist(x,y);
constexpr callable_dist_ dist
Callable object computing the distance between two values.
Definition: dist.hpp:97

is semantically equivalent to:

auto r = abs(x-y);
constexpr callable_abs_ abs
Callable object computing the absolute value.
Definition: abs.hpp:91

If an element of the expected result is not representable in the result type, the corresponding result element is undefined.

The result type is the common compatible type of the two parameters.


auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::dist

Parameters

cond : conditional expression

Return value

A Callable object so that the expression dist[cond](x, ...) is equivalent to if_else(cond,dist(x, ...),x)


Supported decorators

  • saturated

    Required header: #include <eve/function/saturated/dist.hpp>

    The call saturated(dist)(x, y) computes a saturated distance. Contrary to the non decorated case, it guarantees that the result is always defined. If \(|x-y|\) is not representable the greatest representable positive value is returned

  • eve::diff, eve::diff_1st, eve::diff_2nd, eve::diff_nth

    Required header: #include <eve/function/diff/dist.hpp>

    The expression diff_1st(dist)(x,y) and diff_2nd(dist)(x,y) compute the partial derivatives of \(f\), where \(f\) is the function \((x,y) \rightarrow \ |x-y|\).

Example

See it live on Compiler Explorer

#include <eve/function/dist.hpp>
#include <eve/function/saturated/dist.hpp>
#include <eve/wide.hpp>
#include <eve/constant/valmax.hpp>
#include <eve/constant/valmin.hpp>
#include <iostream>
int main()
{
wide_it pf = {0, 1, -1, -eve::valmax(eve::as<int16_t>())};
wide_it qf = {1, -1, 0, eve::valmax(eve::as<int16_t>())};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qf = " << qf << '\n'
<< "-> dist(pf, qf) = " << eve::dist(pf, qf) << '\n'
<< "-> saturated(dist)(pf, qf) = " << eve::saturated(eve::dist)(pf, qf)
<< '\n';
int16_t xf = -eve::valmax(eve::as<int16_t>());
int16_t yf = eve::valmax(eve::as<int16_t>());
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "-> dist(xf, yf) = " << eve::dist(xf, yf) << '\n'
<< "-> saturated(dist)(xf, yf) = " << eve::saturated(eve::dist)(xf, yf)
<< '\n';
return 0;
}
constexpr callable_valmax_ valmax
Callable object computing the greatest representable value.
Definition: valmax.hpp:53
constexpr saturated_type const saturated
Higher-order Callable Object imbuing saturation semantic onto other Callable Objects.
Definition: saturated.hpp:68
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65