Power functions

xtensor provides the following power functions for xexpressions and scalars:

Defined in xtensor/xmath.hpp

template<class E1, class E2>
inline auto xt::pow(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<math::pow_fun, E1, E2>

Power function.

Returns an xfunction for the element-wise value of of e1 raised to the power e2.

Note

e1 and e2 can’t be both scalars.

Parameters
Returns

an xfunction

template<std::size_t N, class E>
inline auto xt::pow(E &&e) noexcept

Integer power function.

Returns an xfunction for the element-wise power of e1 to an integral constant.

Instead of computing the power by using the (expensive) logarithm, this function computes the power in a number of straight-forward multiplication steps. This function is therefore much faster (even for high N) than the generic pow-function.

For example, e1^20 can be expressed as (((e1^2)^2)^2)^2*(e1^2)^2, which is just 5 multiplications.

Parameters

e – an xexpression

Template Parameters

N – the exponent (has to be positive integer)

Returns

an xfunction

template<class E1>
inline auto xt::square(E1 &&e1) noexcept

Square power function, equivalent to e1 * e1.

Returns an xfunction for the element-wise value of of e1 * e1.

Parameters

e1 – an xexpression or a scalar

Returns

an xfunction

template<class E1>
inline auto xt::cube(E1 &&e1) noexcept

Cube power function, equivalent to e1 * e1 * e1.

Returns an xfunction for the element-wise value of of e1 * e1.

Parameters

e1 – an xexpression or a scalar

Returns

an xfunction

template<class E>
inline auto xt::sqrt(E &&e) noexcept -> detail::xfunction_type_t<math::sqrt_fun, E>

Square root function.

Returns an xfunction for the element-wise square root of e.

Parameters

e – an xexpression

Returns

an xfunction

template<class E>
inline auto xt::cbrt(E &&e) noexcept -> detail::xfunction_type_t<math::cbrt_fun, E>

Cubic root function.

Returns an xfunction for the element-wise cubic root of e.

Parameters

e – an xexpression

Returns

an xfunction

template<class E1, class E2>
inline auto xt::hypot(E1 &&e1, E2 &&e2) noexcept -> detail::xfunction_type_t<math::hypot_fun, E1, E2>

Hypotenuse function.

Returns an xfunction for the element-wise square root of the sum of the square of e1 and e2, avoiding overflow and underflow at intermediate stages of computation.

Note

e1 and e2 can’t be both scalars.

Parameters
Returns

an xfunction