Power functions¶
xtensor provides the following power functions for xexpressions and scalars:
Defined in xtensor/xmath.hpp
-
template<class
E1, classE2>
autoxt::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
e1: an xexpression or a scalare2: an xexpression or a scalar
-
template<std::size_t
N, classE>
autoxt::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^20can be expressed as(((e1^2)^2)^2)^2*(e1^2)^2, which is just 5 multiplications.- Return
an xfunction
- Parameters
e: an xexpression
- Template Parameters
N: the exponent (has to be positive integer)
-
template<class
E1>
autoxt::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
e1: an xexpression or a scalar
-
template<class
E1>
autoxt::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
e1: an xexpression or a scalar
-
template<class
E>
autoxt::sqrt(E &&e)¶ Square root function.
Returns an xfunction for the element-wise square root of e.
- Return
an xfunction
- Parameters
e: an xexpression
-
template<class
E>
autoxt::cbrt(E &&e)¶ Cubic root function.
Returns an xfunction for the element-wise cubic root of e.
- Return
an xfunction
- Parameters
e: an xexpression
-
template<class
E1, classE2>
autoxt::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
e1: an xexpression or a scalare2: an xexpression or a scalar