Computes the reciprocal based on elements using the following formula, where PAR indicates the number of elements that can be processed by the Vector Unit in one iteration.

Computation of the first n data elements of a tensor:
template <typename T> __aicore__ inline void Reciprocal(const LocalTensor<T>& dstLocal, const LocalTensor<T>& srcLocal, const int32_t& calCount)
Table 1 Template parameters
| Parameter | Description |
|---|---|
| T | Operand data type. |
Table 2 Parameters
| Parameter | Input/Output | Description |
|---|---|---|
| dstLocal | Output | Destination operand. The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT. The start address of the LocalTensor must be 32-byte aligned. For Kirin 9020, Kirin 9030, and Kirin X90 series processors, the supported data types include: half and float. |
| srcLocal | Input | Source operand. The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT. The start address of the LocalTensor must be 32-byte aligned. The source operand must have the same data type as the destination operand. For Kirin 9020, Kirin 9030, and Kirin X90 series processors, the supported data types include: half and float. |
| calCount | Input | Number of elements of the input data. |
Kirin 9020 series processors
Kirin 9030 series processors
Kirin X90 series processors
For details about the alignment requirements of the operand address offset, see General Constraints.
If the value of srcLocal is 0, an unknown result may be produced.
Using the Reciprocal API, the operator computation result fails to meet the dual-0.1% error limit (the error ratio is within 0.1% and the relative error is within 0.1%) with input of the half type, and fails to meet the dual-0.01% error limit with input of the float type. If the accuracy requirement is high, the Div API is preferred.
This example shows only part of the code used in the computation process (Compute). In this example, srcLocal and dstLocal are of the half type and occupy 16 bits.
To run the sample code, copy the code snippet to replace some code of the Compute function in Sample Template.
Example of computing the first n data elements of a tensor:
AscendC::Reciprocal(dstLocal, srcLocal, 512);
An example of the result is as follows:
Input (srcLocal): [-7.152 -7.24 1.771... -1.339 4.473] Output (dstLocal): [-0.1396 -0.1382 0.5645 ... -0.748 0.2231]