Power functions

xtensor provides the following power functions for xexpressions and scalars:

Defined in xtensor/xmath.hpp

template <class E1, class E2>
auto xt::pow(E1 &&e1, E2 &&e2)

Power function.

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

Return
an xfunction
Note
e1 and e2 can’t be both scalars.
Parameters

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

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.

Return
an xfunction
Parameters
Template Parameters
  • N: the exponent (has to be positive integer)

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

Square power function, equivalent to e1 * e1.

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

Return
an xfunction
Parameters

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

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

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

Return
an xfunction
Parameters

template <class E>
auto xt::sqrt(E &&e)

Square root function.

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

Return
an xfunction
Parameters

template <class E>
auto xt::cbrt(E &&e)

Cubic root function.

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

Return
an xfunction
Parameters

template <class E1, class E2>
auto xt::hypot(E1 &&e1, E2 &&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.

Return
an xfunction
Note
e1 and e2 can’t be both scalars.
Parameters