# MatrixDiagV3

public final class **MatrixDiagV3** Returns a batched diagonal tensor with given batched diagonal values.


Returns a tensor with the contents in \`diagonal\` as \`k\[0\]\`-th to \`k\[1\]\`-th
diagonals of a matrix, with everything else padded with \`padding\`. \`num_rows\`
and \`num_cols\` specify the dimension of the innermost matrix of the output. If
both are not specified, the op assumes the innermost matrix is square and infers
its size from \`k\` and the innermost dimension of \`diagonal\`. If only one of them
is specified, the op assumes the unspecified value is the smallest possible
based on other criteria.


Let \`diagonal\` have \`r\` dimensions \`\[I, J, ..., L, M, N\]\`. The output tensor has
rank \`r+1\` with shape \`\[I, J, ..., L, M, num_rows, num_cols\]\` when only one
diagonal is given (\`k\` is an integer or \`k\[0\] == k\[1\]\`). Otherwise, it has rank
\`r\` with shape \`\[I, J, ..., L, num_rows, num_cols\]\`.


The second innermost dimension of \`diagonal\` has double meaning.
When \`k\` is scalar or \`k\[0\] == k\[1\]\`, \`M\` is part of the batch size
\[I, J, ..., M\], and the output tensor is:

    output[i, j, ..., l, m, n]
       = diagonal[i, j, ..., l, n-max(d_upper, 0)] ; if n - m == d_upper
         padding_value                             ; otherwise
     
Otherwise, \`M\` is treated as the number of diagonals for the matrix in the same batch (\`M = k\[1\]-k\[0\]+1\`), and the output tensor is:

    output[i, j, ..., l, m, n]
       = diagonal[i, j, ..., l, diag_index, index_in_diag] ; if k[0] &lt;= d &lt;= k[1]
         padding_value                                     ; otherwise
     
where \`d = n - m\`, \`diag_index = \[k\] - d\`, and \`index_in_diag = n - max(d, 0) + offset\`.


\`offset\` is zero except when the alignment of the diagonal is to the right.

    offset = max_diag_len - diag_len(d) ; if (`align` in {RIGHT_LEFT, RIGHT_RIGHT}
                                                and `d &gt;= 0`) or
                                              (`align` in {LEFT_RIGHT, RIGHT_RIGHT}
                                                and `d &lt;= 0`)
              0                          ; otherwise
     
where \`diag_len(d) = min(cols - max(d, 0), rows + min(d, 0))\`.


For example:

    # The main diagonal.
     diagonal = np.array([[1, 2, 3, 4],            # Input shape: (2, 4)
                          [5, 6, 7, 8]])
     tf.matrix_diag(diagonal) ==&gt; [[[1, 0, 0, 0],  # Output shape: (2, 4, 4)
                                    [0, 2, 0, 0],
                                    [0, 0, 3, 0],
                                    [0, 0, 0, 4]],
                                   [[5, 0, 0, 0],
                                    [0, 6, 0, 0],
                                    [0, 0, 7, 0],
                                    [0, 0, 0, 8]]]
     
     # A superdiagonal (per batch).
     diagonal = np.array([[1, 2, 3],  # Input shape: (2, 3)
                          [4, 5, 6]])
     tf.matrix_diag(diagonal, k = 1)
       ==&gt; [[[0, 1, 0, 0],  # Output shape: (2, 4, 4)
             [0, 0, 2, 0],
             [0, 0, 0, 3],
             [0, 0, 0, 0]],
            [[0, 4, 0, 0],
             [0, 0, 5, 0],
             [0, 0, 0, 6],
             [0, 0, 0, 0]]]
     
     # A tridiagonal band (per batch).
     diagonals = np.array([[[0, 8, 9],  # Input shape: (2, 2, 3)
                            [1, 2, 3],
                            [4, 5, 0]],
                           [[0, 2, 3],
                            [6, 7, 9],
                            [9, 1, 0]]])
     tf.matrix_diag(diagonals, k = (-1, 1))
       ==&gt; [[[1, 8, 0],  # Output shape: (2, 3, 3)
             [4, 2, 9],
             [0, 5, 3]],
            [[6, 2, 0],
             [9, 7, 3],
             [0, 1, 9]]]
     
     # LEFT_RIGHT alignment.
     diagonals = np.array([[[8, 9, 0],  # Input shape: (2, 2, 3)
                            [1, 2, 3],
                            [0, 4, 5]],
                           [[2, 3, 0],
                            [6, 7, 9],
                            [0, 9, 1]]])
     tf.matrix_diag(diagonals, k = (-1, 1), align="LEFT_RIGHT")
       ==&gt; [[[1, 8, 0],  # Output shape: (2, 3, 3)
             [4, 2, 9],
             [0, 5, 3]],
            [[6, 2, 0],
             [9, 7, 3],
             [0, 1, 9]]]
     
     # Rectangular matrix.
     diagonal = np.array([1, 2])  # Input shape: (2)
     tf.matrix_diag(diagonal, k = -1, num_rows = 3, num_cols = 4)
       ==&gt; [[0, 0, 0, 0],  # Output shape: (3, 4)
            [1, 0, 0, 0],
            [0, 2, 0, 0]]
     
     # Rectangular matrix with inferred num_cols and padding_value = 9.
     tf.matrix_diag(diagonal, k = -1, num_rows = 3, padding_value = 9)
       ==&gt; [[9, 9],  # Output shape: (3, 2)
            [1, 9],
            [9, 2]]
     
     
<br />

<br />

<br />

<br />

<br />

<br />

### Nested Classes

|---|---|---|---|
| class | [MatrixDiagV3.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3.Options) || Optional attributes for `https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3` |

### Public Methods

|---|---|
| static [MatrixDiagV3.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3.Options) | [align](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3#align(java.lang.String))(String align) |
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3#asOutput())() Returns the symbolic handle of a tensor. |
| static \<T\> [MatrixDiagV3](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3)\<T\> | [create](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3#create(org.tensorflow.op.Scope,%20org.tensorflow.Operand<T>,%20org.tensorflow.Operand<java.lang.Integer>,%20org.tensorflow.Operand<java.lang.Integer>,%20org.tensorflow.Operand<java.lang.Integer>,%20org.tensorflow.Operand<T>,%20org.tensorflow.op.core.MatrixDiagV3.Options...))([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> diagonal, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Integer\> k, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Integer\> numRows, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Integer\> numCols, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> paddingValue, [Options...](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3.Options) options) Factory method to create a class wrapping a new MatrixDiagV3 operation. |
| [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\> | [output](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3#output())() Has rank \`r+1\` when \`k\` is an integer or \`k\[0\] == k\[1\]\`, rank \`r\` otherwise. |

### Inherited Methods

From class [org.tensorflow.op.PrimitiveOp](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp)

|---|---|
| final boolean | [equals](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#equals(java.lang.Object))(Object obj) |
| final int | [hashCode](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#hashCode())() |
| [Operation](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation) | [op](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#op())() Returns the underlying `https://www.tensorflow.org/api_docs/java/org/tensorflow/Operation` |
| final String | [toString](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/PrimitiveOp#toString())() |

From class java.lang.Object

|---|---|
| boolean | equals(Object arg0) |
| final Class\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| String | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

From interface [org.tensorflow.Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)

|---|---|
| abstract [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\> | [asOutput](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand#asOutput())() Returns the symbolic handle of a tensor. |

## Public Methods

#### public static [MatrixDiagV3.Options](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3.Options)
**align**
(String align)

<br />

##### Parameters

| align | Some diagonals are shorter than \`max_diag_len\` and need to be padded. \`align\` is a string specifying how superdiagonals and subdiagonals should be aligned, respectively. There are four possible alignments: "RIGHT_LEFT" (default), "LEFT_RIGHT", "LEFT_LEFT", and "RIGHT_RIGHT". "RIGHT_LEFT" aligns superdiagonals to the right (left-pads the row) and subdiagonals to the left (right-pads the row). It is the packing format LAPACK uses. cuSPARSE uses "LEFT_RIGHT", which is the opposite alignment. |
|---|---|

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\>
**asOutput**
()

Returns the symbolic handle of a tensor.

Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is
used to obtain a symbolic handle that represents the computation of the input.

<br />

#### public static [MatrixDiagV3](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3)\<T\>
**create**
([Scope](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/Scope) scope, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> diagonal, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Integer\> k, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Integer\> numRows, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<Integer\> numCols, [Operand](https://www.tensorflow.org/api_docs/java/org/tensorflow/Operand)\<T\> paddingValue, [Options...](https://www.tensorflow.org/api_docs/java/org/tensorflow/op/core/MatrixDiagV3.Options) options)

Factory method to create a class wrapping a new MatrixDiagV3 operation.

##### Parameters

| scope | current scope |
| diagonal | Rank \`r\`, where \`r \>= 1\` |
| k | Diagonal offset(s). Positive value means superdiagonal, 0 refers to the main diagonal, and negative value means subdiagonals. \`k\` can be a single integer (for a single diagonal) or a pair of integers specifying the low and high ends of a matrix band. \`k\[0\]\` must not be larger than \`k\[1\]\`. |
| numRows | The number of rows of the output matrix. If it is not provided, the op assumes the output matrix is a square matrix and infers the matrix size from k and the innermost dimension of \`diagonal\`. |
| numCols | The number of columns of the output matrix. If it is not provided, the op assumes the output matrix is a square matrix and infers the matrix size from k and the innermost dimension of \`diagonal\`. |
| paddingValue | The number to fill the area outside the specified diagonal band with. Default is 0. |
| options | carries optional attributes values |
|---|---|

##### Returns

- a new instance of MatrixDiagV3

#### public [Output](https://www.tensorflow.org/api_docs/java/org/tensorflow/Output)\<T\>
**output**
()

Has rank \`r+1\` when \`k\` is an integer or \`k\[0\] == k\[1\]\`, rank \`r\` otherwise.