Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.MatrixSetDiagV3

View Source On Gitee
class mindspore.ops.MatrixSetDiagV3(align='RIGHT_LEFT')[source]

Updates the diagonal part of a batched tensor. It takes an Tensor x and diagonal as input and returns a Tensor in which the specified diagonal values in the innermost matrices will be replaced by the values in the diagonal.

Diagonals shorter than max_diag_len need to be padded, where max_diag_len is the longest diagonal value. The dimension of diagonal is shape[2] must be equal to num_diags calculated by num_diags=k[1]k[0]+1. The dimension of diagonal is shape[1] must be equal to the longest diagonal value max_diag_len calculated by max_diag_len=min(x.shape[2]+min(k[1],0),x.shape[1]+min(k[0],0)).

Assume x is an n-D Tensor with shape (d1,d2,...,dn2,dn1,dn). If k is an integer or k[0]==k[1], diagonal is an (n-1)-D Tensor with shape (d1,d2,...,dn2,max_diag_len) Otherwise, it has the same rank as x with shape (d1,d2,...,dn2,num_diags,max_diag_len).

Warning

This is an experimental API that is subject to change or deletion.

Parameters

align (str, optional) –

specifies how superdiagonals and subdiagonals should be aligned. Supported values: "RIGHT_LEFT" , "LEFT_RIGHT", "LEFT_LEFT" , "RIGHT_RIGHT" . Default: "RIGHT_LEFT" .

  • When set to "RIGHT_LEFT" , the alignment of superdiagonals will be towards the right side (padding the row on the left), while subdiagonals will be towards the left side (padding the row on the right)

  • When set to "LEFT_RIGHT" , the alignment of superdiagonals will be towards the left side (padding the row on the right), while subdiagonals will be towards the right side (padding the row on the left)

  • When set to "LEFT_LEFT" , the alignment of both superdiagonals and subdiagonals will be towards the left side(padding the row on the right).

  • When set to "RIGHT_RIGHT" , the alignment of both superdiagonals and subdiagonals will be towards the right side(padding the row on the left).

Inputs:
  • x (Tensor) - A n-D Tensor, where n>=2.

  • diagonal (Tensor) - A Tensor with the same dtype as x. Its rank depends on k. If k is an integer or k[0]==k[1], its dimension is n1. Otherwise, it has dimension n.

  • k (Tensor) - Diagonal offset(s), Tensor of type int32. k can either be a single integer, which represents a single diagonal, or a pair of integers that specify the low and high ends of a matrix band. In this case, k[0] should not be greater than k[1]. The value of k has restructions, which means that value of k must be in range (x.shape[2],x.shape[1]). Input k must be const Tensor when taking Graph mode.

    • k > 0 refers to a superdiagonal.

    • k = 0 refers to the main diagonal.

    • k < 0 refers to subdiagonals.

Outputs:

Tensor. The same type and shape as x.

Raises
  • TypeError – If any input is not Tensor.

  • TypeError – If input x and diagonal are not the same dtype.

  • TypeError – If k is not int32 dtype.

  • ValueError – If align is not a string or not in the valid range.

  • ValueError – If rank of k is not equal to 0 or 1.

  • ValueError – If rank of x is not greater equal to 2.

  • ValueError – If size of k is not equal to 1 or 2.

  • ValueError – If k[1] is not greater equal to k[0] in case the size of k is 2.

  • ValueError – If the diagonal rank size don’t match with input x rank size.

  • ValueError – If the diagonal shape value don’t match with input x shape value.

  • ValueError – If the diagonal shape[2] is not equal to num_diags calculated by num_diags=k[1]k[0]+1 .

  • ValueError – If the value of k is not in (x.shape[2],x.shape[1]).

  • ValueError – If the diagonal shape[1] is not equal to the max_diag_len calculated by max_diag_len=min(x.shape[2]+min(k[1],0),x.shape[1]+min(k[0],0)) .

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([[7, 7, 7, 7],
...                      [7, 7, 7, 7],
...                      [7, 7, 7, 7]]), mindspore.float32)
>>> diagonal = Tensor(np.array([[0, 9, 1],
...                             [6, 5, 8],
...                             [1, 2, 3],
...                             [4, 5, 0]]), mindspore.float32)
>>> k =Tensor(np.array([-1, 2]), mindspore.int32)
>>> matrix_set_diag_v3 = ops.MatrixSetDiagV3(align='RIGHT_LEFT')
>>> output = matrix_set_diag_v3(x, diagonal, k)
>>> print(output)
[[1. 6. 9. 7.]
 [4. 2. 5. 1.]
 [7. 5. 3. 8.]]
>>> print(output.shape)
(3, 4)