E.V.E
v2022.03.00

◆ lpnorm

eve::lpnorm = {}
inlineconstexpr

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

Defined in Header

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
auto operator()(P p, T x,Ts ... args ) const noexcept
}
Definition: value.hpp:83
Definition: all_of.hpp:22

Parameters

p, x, ... args: floating values

Return value

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

Example

#include <eve/module/math.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
Computes the IEEE NaN constant.
Definition: nan.hpp:53
constexpr callable_inf_ inf
Computes the infinity ieee value.
Definition: inf.hpp:58
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:63
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

    The call eve::lpnorm[mask](x, ...) provides a masked version of eve::lpnorm which is equivalent to if_else (mask, lpnorm(x, ...), x).

    Example

    #include <eve/module/math.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft pf = {0.0f, 0.5f, 2.0f, eve::inf(eve::as(1.0f))},
    of = { 0.0f, -0.0f, -1.0f, 3.0f},
    qf = { 20.0f, -5.0f, 8.0f, 1.0f},
    rf = { 2.0f, 3.0f, 4.0f, 0.0f};
    std::cout << "---- simd" << '\n'
    << "<- pf = " << pf << '\n'
    << "-> lpnorm[pf > 1.0](pf, of, qf, rf) = " << eve::lpnorm[pf > 1.0](pf, of, qf, rf) << '\n';
    return 0;
    }