FilesLast commitLast update
15 days ago
3 months ago
15 days ago
15 days ago
15 days ago
8 days ago
15 days ago
15 days ago
5 days ago
README

Inv

English | 简体中文

Product Support Status

Product Supported
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products √
Atlas inference products √
Atlas training products √

Function Description

  • Operator function: computes the reciprocal of each element in the input tensor element-wise.

  • Computation formula:

yi=1xiy_{i}=\frac{1}{x_{i}}

  • Floating-point types (FLOAT, FLOAT16, BFLOAT16) compute the true reciprocal according to IEEE-754 (division by zero yields ±Inf\pm\text{Inf}, ±Inf\pm\text{Inf} yields ±0\pm0, and NaN yields NaN).

  • INT32 computes the integer reciprocal truncated toward zero. For integers, 1/x1/x is non-zero only when ∣x∣=1|x|=1, which is equivalent to a three-value mapping:

yi={+1xi=+1−1xi=−10other (including xi=0,∣xi∣≥2,INT_MIN,INT_MAX)y_{i}= \begin{cases} +1 & x_{i}=+1 \\ -1 & x_{i}=-1 \\ 0 & \text{other (including } x_{i}=0, |x_{i}|\ge 2, \text{INT\_MIN}, \text{INT\_MAX)} \end{cases}

Here, xi=0x_{i}=0 is mapped to 00 without throwing an exception, and INT_MIN(−2147483648)\text{INT\_MIN}(-2147483648) and INT_MAX(2147483647)\text{INT\_MAX}(2147483647) are both mapped to 00 without overflow.

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
x Input Input parameter for the inv computation, which is x in the formula. Empty tensors and non-contiguous tensors are supported, and the number of shape dimensions ranges from 0 to 8. FLOAT, FLOAT16, BFLOAT16, INT32 ND
y Output Output parameter for the inv computation, which is y in the formula. The shape and data type are the same as those of x. FLOAT, FLOAT16, BFLOAT16, INT32 ND

Constraint Description

  • x and y must have the same shape and dtype, with element-wise computation and no broadcasting.
  • Dynamic shape support: dynamic shapes and dynamic ranks are supported (-1 indicates an unknown dimension / -2 indicates an unknown rank). The dimension and rank are specified by the actual input at runtime, and after specification, the number of shape dimensions must range from 0 to 8.
  • The precision of the floating-point path follows community standards: FLOAT rtol/atol = 1e-4, FLOAT16 = 1e-3, and BFLOAT16 = 4e-3.
  • The INT32 path is an exact match (bitwise, rtol = atol = 0). The three-value mapping is implemented through pure integer comparison and selection, without float32 conversion or negating INT_MIN. Therefore, INT_MIN/INT_MAX do not overflow, and x = 0 does not throw an exception.

Invocation Description

Invocation Method Sample Code Description
GE graph mode test_geir_inv Invokes the Inv operator by building a graph through the operator IR.