mx.symbol.linalg_maketrian

Description

Constructs a square matrix with the input representing a specific triangular sub-matrix. This is basically the inverse of linalg.extracttrian. Input is a tensor A of dimension n >= 1.

If n=1, then A represents the entries of a triangular matrix which is lower triangular if offset<0 or offset=0, lower=true. The resulting matrix is derived by first constructing the square matrix with the entries outside the triangle set to zero and then adding offset-times an additional diagonal with zero entries to the square matrix.

If n>1, then A represents a batch of triangular sub-matrices. The batch of corresponding square matrices is returned as an n+1-dimensional tensor.

Note

The operator supports float32 and float64 data types only.

Example:

Single  matrix construction
A = [1.0, 2.0, 3.0]

maketrian(A)              = [[1.0, 0.0],
[2.0, 3.0]]

maketrian(A, lower=false) = [[1.0, 2.0],
[0.0, 3.0]]

maketrian(A, offset=1)    = [[0.0, 1.0, 2.0],
[0.0, 0.0, 3.0],
[0.0, 0.0, 0.0]]
maketrian(A, offset=-1)   = [[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[2.0, 3.0, 0.0]]

Batch matrix construction
A = [[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0]]

maketrian(A)           = [[[1.0, 0.0],
[2.0, 3.0]],
[[4.0, 0.0],
[5.0, 6.0]]]

maketrian(A, offset=1) = [[[0.0, 1.0, 2.0],
[0.0, 0.0, 3.0],
[0.0, 0.0, 0.0]],
[[0.0, 4.0, 5.0],
[0.0, 0.0, 6.0],
[0.0, 0.0, 0.0]]]

Usage

mx.symbol.linalg_maketrian(...)

Arguments

Argument

Description

A

NDArray-or-Symbol.

Tensor of triangular matrices stored as vectors

offset

int, optional, default=’0’.

Offset of the diagonal versus the main diagonal. 0 corresponds to the main diagonal, a negative/positive value to diagonals below/above the main diagonal.

lower

boolean, optional, default=1.

Refer to the lower triangular matrix if lower=true, refer to the upper otherwise. Only relevant when offset=0

name

string, optional.

Name of the resulting symbol.