Arange
Applicability
|
Product |
Supported |
|---|---|
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
|
|
x |
|
|
x |
Function
Returns an arithmetic progression given the start value, arithmetical value, and length.
Principles
The figure below illustrates the internal algorithm block diagram of ArithProgression high-level APIs, taking the float type, ND format, and firstValue and diffValue input scalars as examples.
The computation process is divided into the following steps, all of which are performed on vectors:
- Step for arithmetic progression with a length less than 8: Use SetValue to expand the arithmetic progression based on the values of firstValue and diffValue. The maximum expanded length is 8. If the length of the arithmetic progression is less than 8, the algorithm ends.
- Step for arithmetic progression with a length of 8 to 64: Use Adds to expand the arithmetic progression result in step 1, with a maximum of seven cycles of expansion to reach a length of 64. If the length of the arithmetic progression is less than 64, the algorithm ends.
- Step for arithmetic progression with a length greater than 64: Use Adds to expand the arithmetic progression result in step 2, and repeat until the target length of the arithmetic progression is reached.
Prototype
1 2 |
template <typename T> __aicore__ inline void Arange(const LocalTensor<T>& dst, const T firstValue, const T diffValue, const int32_t count) |
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Data type of the operand. |
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
dst |
Output |
Destination operand. The size of dst must be greater than or equal to count x sizeof(T). The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT. |
|
firstValue |
Input |
Value of the first element in an arithmetic progression. |
|
diffValue |
Input |
Difference between elements in an arithmetic progression. The value must be greater than or equal to 0. |
|
count |
Input |
Length of an arithmetic progression. The value of count is greater than 0. |
Returns
None
Restrictions
Currently, only the ND format is supported.
Example
1 2 3 |
AscendC::LocalTensor<T> dst = outDst.AllocTensor<T>(); AscendC::Arange<T>(dst, static_cast<T>(firstValue_), static_cast<T>(diffValue_), count_); outDst.EnQue<T>(dst); |