टेंसरफ़्लो:: ऑप्स:: मैट्रिक्सडायगV3

#include <array_ops.h>

दिए गए बैच विकर्ण मानों के साथ एक बैच विकर्ण टेंसर लौटाता है।

सारांश

मैट्रिक्स के k[0] -वें से k[1] -वें विकर्णों के रूप में diagonal में सामग्री के साथ एक टेंसर लौटाता है, बाकी सब कुछ padding के साथ गद्देदार होता है। num_rows और num_cols आउटपुट के सबसे अंदरूनी मैट्रिक्स का आयाम निर्दिष्ट करते हैं। यदि दोनों निर्दिष्ट नहीं हैं, तो ऑप मानता है कि अंतरतम मैट्रिक्स वर्गाकार है और इसका आकार k और diagonal के अंतरतम आयाम से अनुमान लगाता है। यदि उनमें से केवल एक निर्दिष्ट है, तो ऑप मानता है कि अनिर्दिष्ट मान अन्य मानदंडों के आधार पर सबसे छोटा संभव है।

माना diagonal r आयाम हैं [I, J, ..., L, M, N] आउटपुट टेंसर की रैंक r+1 होती है जिसका आकार [I, J, ..., L, M, num_rows, num_cols] जब केवल एक विकर्ण दिया जाता है ( k एक पूर्णांक है या k[0] == k[1] . अन्यथा, इसका आकार [I, J, ..., L, num_rows, num_cols] के साथ रैंक r है।

diagonal का दूसरा अंतरतम आयाम दोहरा अर्थ रखता है। जब k अदिश या k[0] == k[1] है, M बैच आकार [I, J, ..., M] का हिस्सा है, और आउटपुट टेंसर है:

output[i, j, ..., l, m, n]
  = diagonal[i, j, ..., l, n-max(d_upper, 0)] ; if n - m == d_upper
    padding_value                             ; otherwise

अन्यथा, M उसी बैच में मैट्रिक्स के विकर्णों की संख्या के रूप में माना जाता है ( M = k[1]-k[0]+1 ), और आउटपुट टेंसर है:

output[i, j, ..., l, m, n]
  = diagonal[i, j, ..., l, diag_index, index_in_diag] ; if k[0] <= d <= k[1]
    padding_value                                     ; otherwise
जहां d = n - m , diag_index = [k] - d , और index_in_diag = n - max(d, 0) + offset

offset शून्य है, सिवाय इसके कि जब विकर्ण का संरेखण दाईं ओर हो।

offset = max_diag_len - diag_len(d) ; if (`align` in {RIGHT_LEFT, RIGHT_RIGHT}
                                           and `d >= 0`) or
                                         (`align` in {LEFT_RIGHT, RIGHT_RIGHT}
                                           and `d <= 0`)
         0                          ; otherwise
जहां diag_len(d) = min(cols - max(d, 0), rows + min(d, 0)) .

उदाहरण के लिए:

# The main diagonal.
diagonal = np.array([[1, 2, 3, 4],            # Input shape: (2, 4)
                     [5, 6, 7, 8]])
tf.matrix_diag(diagonal) ==> [[[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)
  ==> [[[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))
  ==> [[[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")
  ==> [[[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)
  ==> [[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)
  ==> [[9, 9],  # Output shape: (3, 2)
       [1, 9],
       [9, 2]]

  

Arguments:

  • scope: A Scope object
  • 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].
  • num_rows: 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.
  • num_cols: 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.
  • padding_value: The number to fill the area outside the specified diagonal band with. Default is 0.

Optional attributes (see Attrs):

  • 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.

Returns:

  • Output: Has rank r+1 when k is an integer or k[0] == k[1], rank r otherwise.

Constructors and Destructors

MatrixDiagV3(const ::tensorflow::Scope & scope, ::tensorflow::Input diagonal, ::tensorflow::Input k, ::tensorflow::Input num_rows, ::tensorflow::Input num_cols, ::tensorflow::Input padding_value)
MatrixDiagV3(const ::tensorflow::Scope & scope, ::tensorflow::Input diagonal, ::tensorflow::Input k, ::tensorflow::Input num_rows, ::tensorflow::Input num_cols, ::tensorflow::Input padding_value, const MatrixDiagV3::Attrs & attrs)

Public attributes

operation
output

Public functions

node() const
::tensorflow::Node *
operator::tensorflow::Input() const
operator::tensorflow::Output() const

Public static functions

Align(StringPiece x)

Structs

tensorflow::ops::MatrixDiagV3::Attrs

Optional attribute setters for MatrixDiagV3.

Public attributes

operation

Operation operation

आउटपुट

::tensorflow::Output output

सार्वजनिक समारोह

मैट्रिक्सडायगV3

 MatrixDiagV3(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input diagonal,
  ::tensorflow::Input k,
  ::tensorflow::Input num_rows,
  ::tensorflow::Input num_cols,
  ::tensorflow::Input padding_value
)

मैट्रिक्सडायगV3

 MatrixDiagV3(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input diagonal,
  ::tensorflow::Input k,
  ::tensorflow::Input num_rows,
  ::tensorflow::Input num_cols,
  ::tensorflow::Input padding_value,
  const MatrixDiagV3::Attrs & attrs
)

नोड

::tensorflow::Node * node() const 

ऑपरेटर::टेन्सरफ़्लो::इनपुट

 operator::tensorflow::Input() const 

ऑपरेटर::टेन्सरफ़्लो::आउटपुट

 operator::tensorflow::Output() const 

सार्वजनिक स्थैतिक कार्य

संरेखित

Attrs Align(
  StringPiece x
)