E.V.E  0.1-beta

◆ lpnorm

eve::lpnorm = {}
inlineconstexpr

Callable object computing the lpnorm operation \( \left(\sum_{i = 0}^n |x_i|^p\right)^{\frac1p} \).

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

Members Functions

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

template< floating_value P, floating_value T, floating_value ...Ts> auto operator()( T x,Ts... args ) const noexcept
requires (compatiblevalues< P, T, Ts > && ...);
Definition: value.hpp:83

Parameters

p, x, args: floating values

Return value

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


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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

  • eve::pedantic

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

    The call pedantic(lpnorm)(x,args...) computes the \(l_p\) norm without undue overflow or underflow at intermediate stages of the computation and can be more accurate than the non decorated call.

    Morever it returns \(\infty\) as soon as one of its parameter is infinite, regardless of possible Nan values.

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

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

    The expression diff_< N >(lpnorm)(x,args...) computes the partial diff of the function relative to its Nth parameter. The returned value is 0 if N is greater that the actual number of parameters, otherwise it is the Nth parameter value divided by the lpnorm value.

Example

See it live on Compiler Explorer

#include <eve/function/lpnorm.hpp>
#include <eve/function/pedantic/lpnorm.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <iomanip>
int main()
{
wide_ft x = {eve::nan(eve::as<float>()), 1.0f, 1.0f, 1.0f};
wide_ft y = {-1.5f, 2.9f, 3.5f, -11.0f};
wide_ft z = { eve::inf(eve::as(1.0f)), -2.0f, 1.0f, eve::nan(eve::as<float>())};
wide_ft p = { 3.2f, 3.0f, 2.0f, eve::inf(eve::as(1.0f))};
std::cout << "---- simd" << std::setprecision(5) << '\n'
<< "<- p = " << p << '\n'
<< "<- x = " << x << '\n'
<< "<- y = " << y << '\n'
<< "<- z = " << z << '\n'
<< "-> lpnorm(p, x, y, z) = " << eve::lpnorm(p, x, y, z) << '\n'
<< "-> pedantic(lpnorm)(p, x, y, z) = " << eve::pedantic(eve::lpnorm)(p, x, y, z) << '\n';
double xf = 10.0;
double yf = 1.0;
double zf = 111.0;
double pf = 2.0; //eve::inf(eve::as(xf));
std::cout << "---- scalar" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "<- zf = " << zf << '\n'
<< "-> lpnorm(p, xf, yf, zf) = " << eve::lpnorm(pf, xf, yf, zf) << '\n'
<< "-> pedantic(lpnorm)(p, xf, yf, zf) = " << eve::pedantic(eve::lpnorm)(pf, xf, yf, zf) << '\n';
return 0;
}
constexpr callable_nan_ nan
Callable object computing the nan value.
Definition: nan.hpp:52
constexpr callable_inf_ inf
Callable object computing the infinity ieee value.
Definition: inf.hpp:54
constexpr pedantic_type const pedantic
Higher-order Callable Object imbuing more standard semantic onto other Callable Objects.
Definition: pedantic.hpp:56
constexpr callable_lpnorm_ lpnorm
Callable object computing the lpnorm operation .
Definition: lpnorm.hpp:90
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65