E.V.E  0.1-beta

◆ fdim

eve::fdim = {}
inlineconstexpr

Callable object computing the positive difference.

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

Members Functions

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

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

Parameters

x, y: values

Return value

Returns the elementwise positive difference between x and y:

  • if x>y, x-y is returned
  • if x<=y, +0 is returned
  • otherwise a Nan is returned

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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

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

    The expression diff_1st(fim)(x,y) and diff_2nd(fim)(x,y) computes the partial derivatives of \(f\), where \(f\) is the function \((x,y) \rightarrow \ \max(0,x-y)\).

Example

See it live on Compiler Explorer

#include <eve/function/fdim.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<float>())};
wide_it qf = {1, -1, 0, eve::valmax(eve::as<float>())};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qf = " << qf << '\n'
<< "-> fdim(pf, qf) = " << eve::fdim(pf, qf) << '\n'
<< '\n';
float xf = -eve::valmax(eve::as<float>());
float yf = eve::valmax(eve::as<float>());
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "-> fdim(xf, yf) = " << eve::fdim(xf, yf) << '\n'
<< '\n';
return 0;
}
constexpr callable_fdim_ fdim
Callable object computing the positive difference.
Definition: fdim.hpp:80
constexpr callable_valmax_ valmax
Callable object computing the greatest representable value.
Definition: valmax.hpp:53
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65