FilesLast commitLast update
6 months ago
2 months ago
2 months ago
5 months ago
2 months ago
6 months ago
1 month ago
8 days ago
README

MatrixDiagV3

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: generates matrices from the input values of one or more diagonals, and positions outside the diagonal band are filled with padding_value\mathrm{padding\_value}.
  • Assume that the sizes of the last two dimensions of the output tensor are num_rows\mathrm{num\_rows} and num_cols\mathrm{num\_cols} respectively, and k=[kl,ku]k=[k_l, k_u] indicates the range of diagonals to write. In the single-diagonal scenario, kl=kuk_l = k_u. Let d=j−id = j - i indicate the diagonal number of position (i,j)(i, j). Then the maximum diagonal length is:

max_diag_len=min⁡(num_rows+min⁡(ku,0), num_cols−max⁡(kl,0))\mathrm{max\_diag\_len} = \min(\mathrm{num\_rows} + \min(k_u, 0),\ \mathrm{num\_cols} - \max(k_l, 0))

Output elements satisfy:

y...,i,j={x...,ku−d, p(i,j)kl≤d≤kupadding_valueotherwisey_{..., i, j} = \begin{cases} x_{..., k_u - d,\ p(i, j)} & k_l \le d \le k_u \\ \text{padding\_value} & \text{otherwise} \end{cases}

Here, p(i,j)p(i, j) indicates the position of the diagonal element in the last dimension of input xx, and the left/right alignment mode is controlled by the align attribute. When kk is a single integer or kl=kuk_l = k_u, xx indicates a single diagonal; when kl<kuk_l < k_u, xx indicates a diagonal band.

Parameter Description

Parameter Name Input/Output/Attribute Description Data Type Data Format
x Input `x` in the formula. When `k` indicates a single diagonal, the last dimension of `x` stores the data of this diagonal; when `k` indicates a diagonal band, the second-to-last dimension of `x` stores the number of diagonals, and the last dimension stores the data of each diagonal padded according to `align`. DOUBLE, FLOAT, FLOAT16, INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, COMPLEX64, COMPLEX128, BOOL ND
k Input kl and ku in the formula. It can be a scalar, indicating a single diagonal; it can also be a vector of length 2, indicating the lower bound and upper bound of a diagonal band. INT32 ND
num_rows Input Number of rows of the output matrix, which is `num_rows` in the formula. A value of `-1` indicates that it is automatically inferred from `k` and `x`. INT32 ND
num_cols Input Number of columns of the output matrix, which is `num_cols` in the formula. A value of `-1` indicates that it is automatically inferred from `k` and `x`. INT32 ND
padding_value Input `padding_value` in the formula. It is used to fill positions outside the specified diagonal band, and its data type is the same as that of `x`. DOUBLE, FLOAT, FLOAT16, INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, COMPLEX64, COMPLEX128, BOOL ND
align Optional attribute Specifies the alignment mode of superdiagonals and subdiagonals. `RIGHT_LEFT`, `LEFT_RIGHT`, `LEFT_LEFT`, and `RIGHT_RIGHT` are supported, and the default value is `RIGHT_LEFT`. STRING -
y Output `y` in the formula, indicating the generated matrix tensor. Its data type is the same as that of `x`. When `k` is a single element or `k[0] == k[1]`, the rank of `y` is the rank of `x` plus 1; otherwise, the rank of `y` is the same as that of `x`. DOUBLE, FLOAT, FLOAT16, INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, COMPLEX64, COMPLEX128, BOOL ND

Constraint Description

  • The rank of x is at least 1.
  • The number of elements in k can only be 1 or 2; when k has 2 elements, k[0] <= k[1] must be satisfied.
  • When k indicates a diagonal band, the length of the second-to-last dimension of x must be equal to ku−kl+1k_u - k_l + 1, and the length of the last dimension must be equal to max_diag_len\mathrm{max\_diag\_len}.

Invocation Description

Invocation Method Invocation Sample Description
Graph-mode invocation test_geir_matrix_diag_v3 Invokes the MatrixDiagV3 operator by building a graph through the operator IR.