mindspore.mint.linalg.qr
- mindspore.mint.linalg.qr(A, mode='reduced')
Orthogonal decomposition of the input \(A = QR\).
Where A is an input tensor, a dimension is at least 2, and A may be represented as a product form of an orthogonal matrix Q and an upper triangular matrix R.
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
A (Tensor) – The calculated matrix, A is at least two-dimensional.
mode (str, optional) –
Matrix decomposition mode. The options are
reduced
,complete
, andr
. The default value isreduced
."reduced"
: For input \(A(*, m, n)\) output simplified size \(Q(*, m, k)\), \(R(*, k, n)\), where k is the minimum value of m and n."complete"
: For input \(A(*, m, n)\) output full-size \(Q(*, m, m)\), \(R(*, m, n)\)."r"
: Only \(R(*, k, n)\) in the reduced scenario is calculated, where k is the minimum value of m and n, and Q is returned as an empty tensor.
- Returns
Q (Tensor) - The shape is \(Q(*, m, k)\) or \((*, m, n)\), has the same dtype as A.
R (Tensor) - The shape is \(Q(*, k, n)\) or \((*, m, n)\), has the same dtype as A.
- Raises
TypeError – If A is not a Tensor.
TypeError – If the dtype of A is not the float32.
ValueError – If A is not empty and its dimension is less than 2 dimensions.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, mint >>> x = Tensor(np.array([[1.0, 1.0, 2.0, 4.0], [1.0, 1.0, 2.0, 4.0]]), mindspore.float32) >>> output = mint.linalg.qr(x) >>> print(output) (Tensor(shape=[2, 2], dtype=Float32, value= [[-7.07106829e-01, -7.07106769e-01], [-7.07106769e-01, 7.07106829e-01]]), Tensor(shape=[2, 4], dtype=Float32, value= [[-1.41421354e+00, -1.41421354e+00, -2.82842731e+00, -5.65685463e+00], [ 0.00000000e+00, 3.42285418e-08, 0.00000000e+00, 0.00000000e+00]]))