Basic functions

xtensor provides the following basic functions for xexpressions and scalars:

Defined in xtensor/core/xmath.hpp

template<class E>
inline detail::xfunction_type_t<math::abs_fun, E> abs(E &&e) noexcept

Absolute value function.

Returns an xfunction for the element-wise absolute value of e.

Parameters:

e – an xexpression

Returns:

an xfunction

template<class E>
inline detail::xfunction_type_t<math::fabs_fun, E> fabs(E &&e) noexcept

Absolute value function.

Returns an xfunction for the element-wise absolute value of e.

Parameters:

e – an xexpression

Returns:

an xfunction

template<class E1, class E2>
inline detail::xfunction_type_t<math::fmod_fun, E1, E2> fmod(E1 &&e1, E2 &&e2) noexcept

Remainder of the floating point division operation.

Returns an xfunction for the element-wise remainder of the floating point division operation e1 / e2.

Note

e1 and e2 can’t be both scalars.

Parameters:
Returns:

an xfunction

template<class E1, class E2>
inline detail::xfunction_type_t<math::remainder_fun, E1, E2> remainder(E1 &&e1, E2 &&e2) noexcept

Signed remainder of the division operation.

Returns an xfunction for the element-wise signed remainder of the floating point division operation e1 / e2.

Note

e1 and e2 can’t be both scalars.

Parameters:
Returns:

an xfunction

template<class E1, class E2, class E3>
inline detail::xfunction_type_t<math::fma_fun, E1, E2, E3> fma(E1 &&e1, E2 &&e2, E3 &&e3) noexcept

Fused multiply-add operation.

Returns an xfunction for e1 * e2 + e3 as if to infinite precision and rounded only once to fit the result type.

Note

e1, e2 and e3 can’t be scalars every three.

Parameters:
Returns:

an xfunction

template<class E1, class E2>
inline detail::xfunction_type_t<math::maximum<void>, E1, E2> maximum(E1 &&e1, E2 &&e2) noexcept

Elementwise maximum.

Returns an xfunction for the element-wise maximum between e1 and e2.

Parameters:
Returns:

an xfunction

template<class E1, class E2>
inline detail::xfunction_type_t<math::minimum<void>, E1, E2> minimum(E1 &&e1, E2 &&e2) noexcept

Elementwise minimum.

Returns an xfunction for the element-wise minimum between e1 and e2.

Parameters:
Returns:

an xfunction

template<class E1, class E2>
inline detail::xfunction_type_t<math::fmax_fun, E1, E2> fmax(E1 &&e1, E2 &&e2) noexcept

Maximum function.

Returns an xfunction for the element-wise maximum of e1 and e2.

Note

e1 and e2 can’t be both scalars.

Parameters:
Returns:

an xfunction

template<class E1, class E2>
inline detail::xfunction_type_t<math::fmin_fun, E1, E2> fmin(E1 &&e1, E2 &&e2) noexcept

Minimum function.

Returns an xfunction for the element-wise minimum of e1 and e2.

Note

e1 and e2 can’t be both scalars.

Parameters:
Returns:

an xfunction

template<class E1, class E2>
inline detail::xfunction_type_t<math::fdim_fun, E1, E2> fdim(E1 &&e1, E2 &&e2) noexcept

Positive difference function.

Returns an xfunction for the element-wise positive difference of e1 and e2.

Note

e1 and e2 can’t be both scalars.

Parameters:
Returns:

an xfunction

template<class E1, class E2, class E3>
inline detail::xfunction_type_t<math::clamp_fun, E1, E2, E3> clip(E1 &&e1, E2 &&lo, E3 &&hi) noexcept

Clip values between hi and lo.

Returns an xfunction for the element-wise clipped values between lo and hi

Parameters:
  • e1 – an xexpression or a scalar

  • lo – a scalar

  • hi – a scalar

Returns:

a xfunction

template<class E>
inline detail::xfunction_type_t<math::sign_fun, E> sign(E &&e) noexcept

Returns an element-wise indication of the sign of a number.

If the number is positive, returns +1. If negative, -1. If the number is zero, returns 0.

Parameters:

e – an xexpression

Returns:

an xfunction