megengine.functional.sqrt#

sqrt(x)[source]#

Element-wise \(\operatorname{sqrt}(x)\) function.

Calculates the square root for each element \(x_i\) of the input tensor \(x\). After rounding, each result must be indistinguishable from the infinitely precise result (as required by IEEE 754).

This function has domain [0, +infinity] and codomain [0, +infinity].

Parameters:

x (Tensor) – input tensor. Should have a floating-point data type.

Return type:

Tensor

Returns:

a tensor containing the evaluated square root result for each element in \(x\). The returned tensor must have a floating-point data type determined by Type promotion rules.

Special cases

For floating-point operands,

  • If \(x_i\) is NaN, the result is NaN.

  • If \(x_i\) is less than 0, the result is NaN.

  • If \(x_i\) is +0, the result is +0.

  • If \(x_i\) is -0, the result is -0.

  • If \(x_i\) is +infinity, the result is +infinity.

Examples

>>> F.sqrt(4)
Tensor(2.0, device=xpux:0)

Element-wise square root:

>>> x = Tensor([1, 4, 9, 16])
>>> F.sqrt(x)
Tensor([1. 2. 3. 4.], device=xpux:0)